From 95d0395d34d8809c75d942fe45f47a3a67b05452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Thu, 12 Jul 2018 17:04:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=A1=A8=E5=8D=95=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E7=9A=84checked=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/css/var.scss | 2 +- src/js/form/index.js | 25 +++++++++++++++++++++---- src/js/form/style.scss | 2 +- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/css/var.scss b/src/css/var.scss index 152ac9d..6b194fe 100644 --- a/src/css/var.scss +++ b/src/css/var.scss @@ -2,7 +2,7 @@ $ct: #19b491 #3fc2a7 #16967a; $cg: #2ecc71 #58d68d #27ae60; $cpp: #9b59b6 #ac61ce #8e44ad; $cb: #2d8dd6 #52a3de #2776b1; -$cr: #e34235 #e96458 #be382d; +$cr: #eb3b48 #ff5061 #ce3742; $co: #f39c12 #ffb618 #e67e22; $cp: #e7e8eb #f3f5fb #bdc3c7; $cgr: #8a9b9c #98acae #748182; diff --git a/src/js/form/index.js b/src/js/form/index.js index e6dbdd8..e5d2f3b 100644 --- a/src/js/form/index.js +++ b/src/js/form/index.js @@ -66,11 +66,18 @@ Anot.component('button', { // 单选按钮 Anot.component('radio', { __init__(props, state, next) { - state.text = this.textContent - state.checked = state.value === props.label if (props.hasOwnProperty('disabled')) { state.disabled = true } + if (props.hasOwnProperty('checked')) { + if (state.value === null) { + state.value = props.label + } + } + + state.text = this.textContent + state.checked = state.value === props.label + this.classList.add('do-radio') this.classList.add('do-fn-noselect') this.classList.add(props.color || 'grey') @@ -94,6 +101,9 @@ Anot.component('radio', { checked: false, disabled: false }, + props: { + label: '' + }, watch: { value(val) { this.checked = this.props.label === val @@ -155,11 +165,15 @@ Anot.component('checkbox', { this.parentNode.removeChild(this) Anot.error('多选框的传入值必须一个数组', TypeError) } - state.text = this.textContent - state.checked = state.value.indexOf(props.label) > -1 if (props.hasOwnProperty('disabled')) { state.disabled = true } + if (props.hasOwnProperty('checked')) { + Anot.Array.ensure(state.value, props.label) + } + + state.text = this.textContent + state.checked = state.value.indexOf(props.label) > -1 this.classList.add('do-checkbox') this.classList.add('do-fn-noselect') @@ -185,6 +199,9 @@ Anot.component('checkbox', { checked: false, disabled: false }, + props: { + label: '' + }, methods: { onClick() { if (this.disabled) { diff --git a/src/js/form/style.scss b/src/js/form/style.scss index 46aa2c2..c304b6f 100644 --- a/src/js/form/style.scss +++ b/src/js/form/style.scss @@ -167,7 +167,7 @@ .do-checkbox {position:relative;display:inline-block;width:auto;height:30px;padding-right:10px;line-height:30px;text-align:center;cursor:default;font-size:14px; - &__box {float:left;width:20px;height:20px;margin:5px;margin-right:0;line-height:18px;border:1px solid nth($cgr, 1);border-radius:3px;font-size:18px;text-align:center; + &__box {float:left;width:20px;height:20px;margin:5px;margin-left:0;line-height:18px;border:1px solid nth($cgr, 1);border-radius:3px;font-size:18px;text-align:center; } &.checked &__box {color:#fff;font-weight:bold;}