diff --git a/docs/examples-docs/radio.md b/docs/examples-docs/radio.md index 3d99958c0..665cfa7a0 100644 --- a/docs/examples-docs/radio.md +++ b/docs/examples-docs/radio.md @@ -12,13 +12,65 @@ export default { ### 基础用法 -:::demo ```html - -``` -::: +单选框1 +单选框2 -### API + +``` + +### 禁用状态 + +```html +未选中禁用 +选中且禁用 + + +``` + +### radio组 + +```html + + 单选框1 + 单选框2 + + + +``` + +### Radio API + +| 参数 | 说明 | 类型 | 默认值 | 可选值 | +|-----------|-----------|-----------|-------------|-------------| +| disabled | 是否禁用单选框 | Boolean | false | | +| name | 根据这个来判断radio是否选中 | Boolean | false | | + +### RadioGroup API | 参数 | 说明 | 类型 | 默认值 | 可选值 | |-----------|-----------|-----------|-------------|-------------| diff --git a/docs/examples/dialog.vue b/docs/examples/dialog.vue index dd6a8b30d..c17c07476 100644 --- a/docs/examples/dialog.vue +++ b/docs/examples/dialog.vue @@ -14,7 +14,8 @@ + + diff --git a/docs/index.js b/docs/index.js index 8ee82377f..dee3b3d5b 100644 --- a/docs/index.js +++ b/docs/index.js @@ -5,11 +5,7 @@ import navConfig from './nav.config.json'; import routes from './router.config'; import SideNav from './components/side-nav'; import Mobile from './components/mobile'; -import ZanUI from '../src/index'; -import '../packages/zanui-css/src/index.css'; - -Vue.use(ZanUI); Vue.use(VueRouter); Vue.component('side-nav', SideNav); Vue.component('mobile', Mobile); diff --git a/packages/radio/src/radio-group.vue b/packages/radio/src/radio-group.vue index 157922b3b..6e6b774c6 100644 --- a/packages/radio/src/radio-group.vue +++ b/packages/radio/src/radio-group.vue @@ -9,7 +9,14 @@ export default { name: 'z-radio-group', props: { - value: [String, Number] + value: {}, + disabled: Boolean + }, + + watch: { + value(value) { + this.$emit('change', value); + } } }; diff --git a/packages/radio/src/radio.vue b/packages/radio/src/radio.vue index e51e1db7c..35bb49049 100644 --- a/packages/radio/src/radio.vue +++ b/packages/radio/src/radio.vue @@ -2,11 +2,20 @@
- - + + + @@ -21,35 +30,50 @@ export default { props: { disabled: Boolean, value: {}, - parentGroup: null + name: [String, Number] }, computed: { isGroup() { - let parent = this.$parent; - while (parent) { - if (parent.$options.name === 'z-radio-group') { - this.parentGroup = parent; - return true; - } else { - parent = parent.$parent; - } - } - return false; + return !!this.findRadioGroup() }, - model: { + currentValue: { get() { return this.isGroup ? this.parentGroup.value : this.value; }, set(val) { if (this.isGroup) { - + this.parentGroup.$emit('input', val); } else { this.$emit('input', val); } } + }, + + isDisabled() { + return this.isGroup + ? this.parentGroup.disabled || this.disabled + : this.disabled; + } + }, + + methods: { + findRadioGroup() { + if (this.parentGroup) return; + + let parent = this.$parent; + while (parent) { + if (parent.$options.name === 'z-radio-group') { + this.parentGroup = parent; + break; + } else { + parent = parent.$parent; + } + } + + return this.parentGroup; } } }; diff --git a/packages/zanui-css/src/radio.css b/packages/zanui-css/src/radio.css index c8ec135cd..c01344a52 100644 --- a/packages/zanui-css/src/radio.css +++ b/packages/zanui-css/src/radio.css @@ -1,5 +1,46 @@ +@import "./common/var.css"; + @component-namespace z { @b radio { + margin: 10px 0; + @when disabled { + .zui-icon { + color: #d1dbe5; + } + } + + @e input { + position: relative; + height: 22px; + margin-right: 15px; + } + + @e control { + position: absolute; + top: 0; + left: 0; + width: 22px; + height: 22px; + opacity: 0; + margin: 0; + } + + @e label { + line-height: 22px; + } + + .zui-icon { + font-size: 22px; + line-height: 1; + } + + .zui-icon-checked { + color: $c-green; + } + + .zui-icon-check { + color: $c-gray-dark; + } } } diff --git a/src/mixins/popup/index.js b/src/mixins/popup/index.js index 91d86fed0..7e929d251 100644 --- a/src/mixins/popup/index.js +++ b/src/mixins/popup/index.js @@ -85,7 +85,6 @@ export default { const dom = getDOM(this.$el); const props = merge({}, this, options); - const overlay = props.overlay; const zIndex = props.zIndex; // 如果属性中传入了`zIndex`,则覆盖`PopupManager`中对应的`zIndex` @@ -94,7 +93,7 @@ export default { } // 如果显示遮罩层 - if (overlay) { + if (this.overlay) { if (this.closing) { PopupManager.closeModal(this._popupId); this.closing = false; @@ -102,7 +101,7 @@ export default { PopupManager.openModal(this._popupId, PopupManager.nextZIndex(), dom); // 如果滚动时需要锁定 - if (props.lockOnScroll) { + if (this.lockOnScroll) { // 将原来的`bodyOverflow`存起来 if (!this.bodyOverflow) { this.bodyOverflow = document.body.style.overflow;