From 3202c2ec6e662f599fc346c3df773d4e7a4ec588 Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 13 Sep 2018 17:38:15 +0800 Subject: [PATCH] [bugfix] Badge: active prop not work (#569) --- dist/action-sheet/index.wxml | 6 ++-- dist/action-sheet/index.wxss | 2 +- dist/badge-group/index.js | 10 +++--- dist/button/index.js | 52 ++++++++++++-------------------- dist/cell/index.js | 22 +++++++++++--- dist/cell/index.wxml | 16 +++++++--- dist/cell/index.wxss | 2 +- dist/col/index.js | 10 ++++++ dist/col/index.wxml | 2 +- dist/common/create.js | 2 ++ dist/field/index.js | 13 +++++++- dist/field/index.wxml | 7 +++-- dist/field/index.wxss | 2 +- dist/mixins/basic.js | 4 +++ dist/mixins/observer/behavior.js | 34 +++++++++++++++++++++ dist/mixins/observer/index.js | 14 +++++++++ dist/mixins/observer/props.js | 25 +++++++++++++++ example/pages/badge/index.wxml | 2 +- packages/badge-group/index.js | 10 +++--- 19 files changed, 175 insertions(+), 60 deletions(-) create mode 100644 dist/mixins/observer/behavior.js create mode 100644 dist/mixins/observer/index.js create mode 100644 dist/mixins/observer/props.js diff --git a/dist/action-sheet/index.wxml b/dist/action-sheet/index.wxml index 24b143d6..88876761 100644 --- a/dist/action-sheet/index.wxml +++ b/dist/action-sheet/index.wxml @@ -1,9 +1,9 @@ diff --git a/dist/action-sheet/index.wxss b/dist/action-sheet/index.wxss index fe294121..a4676ee6 100644 --- a/dist/action-sheet/index.wxss +++ b/dist/action-sheet/index.wxss @@ -1 +1 @@ -.van-hairline,.van-hairline--bottom,.van-hairline--left,.van-hairline--right,.van-hairline--surround,.van-hairline--top,.van-hairline--top-bottom{position:relative}.van-hairline--bottom::after,.van-hairline--left::after,.van-hairline--right::after,.van-hairline--surround::after,.van-hairline--top-bottom::after,.van-hairline--top::after,.van-hairline::after{content:'';position:absolute;top:0;left:0;width:200%;height:200%;-webkit-transform:scale(.5);transform:scale(.5);-webkit-transform-origin:0 0;transform-origin:0 0;pointer-events:none;box-sizing:border-box;border:0 solid #eee}.van-hairline--top::after{border-top-width:1px}.van-hairline--left::after{border-left-width:1px}.van-hairline--right::after{border-right-width:1px}.van-hairline--bottom::after{border-bottom-width:1px}.van-hairline--top-bottom::after{border-width:1px 0}.van-hairline--surround::after{border-width:1px}.van-action-sheet{color:#333;max-height:90%;overflow-y:auto;-webkit-overflow-scrolling:touch;background-color:#f8f8f8}.van-action-sheet--withtitle{background-color:#fff}.van-action-sheet__cancel,.van-action-sheet__item{height:50px;line-height:50px;font-size:16px;text-align:center;background-color:#fff}.van-action-sheet__cancel:active,.van-action-sheet__item:active{background-color:#e8e8e8}.van-action-sheet__item--disabled{color:#c9c9c9}.van-action-sheet__item--disabled:active{background-color:#fff}.van-action-sheet__name,.van-action-sheet__subname{display:inline-block}.van-action-sheet__subname{font-size:12px;color:#666;margin-left:5px}.van-action-sheet__loading{display:inline-block}.van-action-sheet__cancel{margin-top:10px}.van-action-sheet__header{font-size:16px;line-height:44px;text-align:center}.van-action-sheet__close{top:0;right:0;padding:0 15px;font-size:18px!important;color:#999;position:absolute!important;line-height:inherit!important} \ No newline at end of file +.van-hairline,.van-hairline--bottom,.van-hairline--left,.van-hairline--right,.van-hairline--surround,.van-hairline--top,.van-hairline--top-bottom{position:relative}.van-hairline--bottom::after,.van-hairline--left::after,.van-hairline--right::after,.van-hairline--surround::after,.van-hairline--top-bottom::after,.van-hairline--top::after,.van-hairline::after{content:'';position:absolute;top:0;left:0;width:200%;height:200%;-webkit-transform:scale(.5);transform:scale(.5);-webkit-transform-origin:0 0;transform-origin:0 0;pointer-events:none;box-sizing:border-box;border:0 solid #eee}.van-hairline--top::after{border-top-width:1px}.van-hairline--left::after{border-left-width:1px}.van-hairline--right::after{border-right-width:1px}.van-hairline--bottom::after{border-bottom-width:1px}.van-hairline--top-bottom::after{border-width:1px 0}.van-hairline--surround::after{border-width:1px}.van-action-sheet{color:#333;max-height:90%;overflow-y:auto;-webkit-overflow-scrolling:touch;background-color:#f8f8f8}.van-action-sheet__cancel,.van-action-sheet__item{height:50px;line-height:50px;font-size:16px;text-align:center;background-color:#fff}.van-action-sheet__cancel:active,.van-action-sheet__item:active{background-color:#e8e8e8}.van-action-sheet__item--disabled{color:#c9c9c9}.van-action-sheet__item--disabled:active{background-color:#fff}.van-action-sheet__name,.van-action-sheet__subname{display:inline-block}.van-action-sheet__subname{font-size:12px;color:#666;margin-left:5px}.van-action-sheet__loading{display:inline-block}.van-action-sheet__cancel{margin-top:10px}.van-action-sheet__header{font-size:16px;line-height:44px;text-align:center}.van-action-sheet__close{top:0;right:0;padding:0 15px;font-size:18px!important;color:#999;position:absolute!important;line-height:inherit!important} \ No newline at end of file diff --git a/dist/badge-group/index.js b/dist/badge-group/index.js index 70957c61..77e57af1 100644 --- a/dist/badge-group/index.js +++ b/dist/badge-group/index.js @@ -29,7 +29,7 @@ create({ badges: [] }, - attached() { + created() { this.currentActive = -1; }, @@ -46,13 +46,15 @@ create({ return; } - if (this.currentActive !== -1) { + if (this.currentActive !== -1 && badges[this.currentActive]) { this.$emit('change', active); badges[this.currentActive].setActive(false); } - badges[active].setActive(true); - this.currentActive = active; + if (badges[active]) { + badges[active].setActive(true); + this.currentActive = active; + } } } }); diff --git a/dist/button/index.js b/dist/button/index.js index 6596c4a3..a7f0a165 100644 --- a/dist/button/index.js +++ b/dist/button/index.js @@ -1,35 +1,37 @@ import { create } from '../common/create'; -import { classNames } from '../common/class-names'; import { button } from '../mixins/button'; -const booleanProp = { - type: Boolean, - observer: 'setClasses' -}; - create({ mixins: [button], props: { + plain: Boolean, + block: Boolean, + square: Boolean, + loading: Boolean, + disabled: Boolean, type: { type: String, - value: 'default', - observer: 'setClasses' + value: 'default' }, size: { type: String, - value: 'normal', - observer: 'setClasses' - }, - plain: booleanProp, - block: booleanProp, - square: booleanProp, - loading: booleanProp, - disabled: booleanProp + value: 'normal' + } }, - attached() { - this.setClasses(); + computed: { + classes() { + const { type, size, plain, disabled, loading, square, block } = this.data; + return this.classNames(`van-button--${type}`, `van-button--${size}`, { + 'van-button--block': block, + 'van-button--plain': plain, + 'van-button--square': square, + 'van-button--loading': loading, + 'van-button--disabled': disabled, + 'van-button--unclickable': disabled || loading + }); + } }, methods: { @@ -37,20 +39,6 @@ create({ if (!this.data.disabled && !this.data.loading) { this.$emit('click'); } - }, - - setClasses() { - const { type, size, plain, disabled, loading, square, block } = this.data; - this.setData({ - classes: classNames(`van-button--${type}`, `van-button--${size}`, { - 'van-button--block': block, - 'van-button--plain': plain, - 'van-button--square': square, - 'van-button--loading': loading, - 'van-button--disabled': disabled, - 'van-button--unclickable': disabled || loading - }) - }); } } }); diff --git a/dist/cell/index.js b/dist/cell/index.js index cce4c873..99afc390 100644 --- a/dist/cell/index.js +++ b/dist/cell/index.js @@ -4,9 +4,7 @@ create({ classes: [ 'title-class', 'label-class', - 'value-class', - 'left-icon-class', - 'right-icon-class' + 'value-class' ], props: { @@ -21,7 +19,6 @@ create({ clickable: Boolean, titleWidth: String, customStyle: String, - arrowDirection: String, linkType: { type: String, value: 'navigateTo' @@ -32,6 +29,23 @@ create({ } }, + computed: { + cellClass() { + const { data } = this; + return this.classNames('custom-class', 'van-cell', { + 'van-hairline': data.border, + 'van-cell--center': data.center, + 'van-cell--required': data.required, + 'van-cell--clickable': data.isLink || data.clickable + }); + }, + + titleStyle() { + const { titleWidth } = this.data; + return titleWidth ? `max-width: ${titleWidth};min-width: ${titleWidth}` : ''; + } + }, + methods: { onClick() { const { url } = this.data; diff --git a/dist/cell/index.wxml b/dist/cell/index.wxml index c8bbd485..70866015 100644 --- a/dist/cell/index.wxml +++ b/dist/cell/index.wxml @@ -1,12 +1,20 @@ - + - + {{ title }} {{ label }} @@ -20,7 +28,7 @@ diff --git a/dist/cell/index.wxss b/dist/cell/index.wxss index 316f8a3c..ac27da29 100644 --- a/dist/cell/index.wxss +++ b/dist/cell/index.wxss @@ -1 +1 @@ -.van-hairline,.van-hairline--bottom,.van-hairline--left,.van-hairline--right,.van-hairline--surround,.van-hairline--top,.van-hairline--top-bottom{position:relative}.van-hairline--bottom::after,.van-hairline--left::after,.van-hairline--right::after,.van-hairline--surround::after,.van-hairline--top-bottom::after,.van-hairline--top::after,.van-hairline::after{content:'';position:absolute;top:0;left:0;width:200%;height:200%;-webkit-transform:scale(.5);transform:scale(.5);-webkit-transform-origin:0 0;transform-origin:0 0;pointer-events:none;box-sizing:border-box;border:0 solid #eee}.van-hairline--top::after{border-top-width:1px}.van-hairline--left::after{border-left-width:1px}.van-hairline--right::after{border-right-width:1px}.van-hairline--bottom::after{border-bottom-width:1px}.van-hairline--top-bottom::after{border-width:1px 0}.van-hairline--surround::after{border-width:1px}.van-cell{width:100%;display:-webkit-box;display:-webkit-flex;display:flex;padding:10px 15px;box-sizing:border-box;line-height:24px;position:relative;background-color:#fff;color:#333;font-size:14px}.van-cell::after{left:15px;right:0;width:auto;-webkit-transform:scale(1,.5);transform:scale(1,.5);border-bottom-width:1px}.van-cell-group{background-color:#fff}.van-cell__label{font-size:12px;line-height:1.2;color:#666}.van-cell__title,.van-cell__value{-webkit-box-flex:1;-webkit-flex:1;flex:1}.van-cell__value{overflow:hidden;text-align:right;vertical-align:middle}.van-cell__left-icon{font-size:16px;line-height:24px;margin-right:5px;vertical-align:middle}.van-cell__right-icon{color:#999;font-size:12px;line-height:24px;margin-left:5px}.van-cell__right-icon--left::before{-webkit-transform:rotate(180deg);transform:rotate(180deg)}.van-cell__right-icon--up::before{-webkit-transform:rotate(-90deg);transform:rotate(-90deg)}.van-cell__right-icon--down::before{-webkit-transform:rotate(90deg);transform:rotate(90deg)}.van-cell--clickable:active{background-color:#e8e8e8}.van-cell--required{overflow:visible}.van-cell--required::before{content:'*';position:absolute;left:7px;font-size:14px;color:#f44}.van-cell--center{-webkit-box-align:center;-webkit-align-items:center;align-items:center} \ No newline at end of file +.van-hairline,.van-hairline--bottom,.van-hairline--left,.van-hairline--right,.van-hairline--surround,.van-hairline--top,.van-hairline--top-bottom{position:relative}.van-hairline--bottom::after,.van-hairline--left::after,.van-hairline--right::after,.van-hairline--surround::after,.van-hairline--top-bottom::after,.van-hairline--top::after,.van-hairline::after{content:'';position:absolute;top:0;left:0;width:200%;height:200%;-webkit-transform:scale(.5);transform:scale(.5);-webkit-transform-origin:0 0;transform-origin:0 0;pointer-events:none;box-sizing:border-box;border:0 solid #eee}.van-hairline--top::after{border-top-width:1px}.van-hairline--left::after{border-left-width:1px}.van-hairline--right::after{border-right-width:1px}.van-hairline--bottom::after{border-bottom-width:1px}.van-hairline--top-bottom::after{border-width:1px 0}.van-hairline--surround::after{border-width:1px}.van-cell{width:100%;display:-webkit-box;display:-webkit-flex;display:flex;padding:10px 15px;box-sizing:border-box;line-height:24px;position:relative;background-color:#fff;color:#333;font-size:14px}.van-cell::after{left:15px;right:0;width:auto;-webkit-transform:scale(1,.5);transform:scale(1,.5);border-bottom-width:1px}.van-cell-group{background-color:#fff}.van-cell__label{font-size:12px;line-height:1.2;color:#666}.van-cell__title,.van-cell__value{-webkit-box-flex:1;-webkit-flex:1;flex:1}.van-cell__value{overflow:hidden;text-align:right;vertical-align:middle}.van-cell__left-icon{font-size:16px;line-height:24px;margin-right:5px;vertical-align:middle}.van-cell__right-icon{color:#999;font-size:12px;line-height:24px;margin-left:5px}.van-cell--clickable:active{background-color:#e8e8e8}.van-cell--required{overflow:visible}.van-cell--required::before{content:'*';position:absolute;left:7px;font-size:14px;color:#f44}.van-cell--center{-webkit-box-align:center;-webkit-align-items:center;align-items:center} \ No newline at end of file diff --git a/dist/col/index.js b/dist/col/index.js index b87fd356..7bd39761 100644 --- a/dist/col/index.js +++ b/dist/col/index.js @@ -12,6 +12,16 @@ create({ offset: Number }, + computed: { + classes() { + const { span, offset } = this.data; + return this.classNames('custom-class', 'van-col', { + [`van-col--${span}`]: span, + [`van-col--${offset}`]: offset + }); + } + }, + methods: { setGutter(gutter) { const padding = `${gutter / 2}px`; diff --git a/dist/col/index.wxml b/dist/col/index.wxml index 30baf92a..f4cbabf7 100644 --- a/dist/col/index.wxml +++ b/dist/col/index.wxml @@ -1,5 +1,5 @@ diff --git a/dist/common/create.js b/dist/common/create.js index a6174a82..6d76447b 100644 --- a/dist/common/create.js +++ b/dist/common/create.js @@ -1,4 +1,5 @@ import { basic } from '../mixins/basic'; +import { observe } from '../mixins/observer/index'; export function create(sfc) { // map props to properties @@ -34,5 +35,6 @@ export function create(sfc) { sfc.behaviors.push('wx://form-field'); } + observe(sfc); Component(sfc); }; diff --git a/dist/field/index.js b/dist/field/index.js index 5932e75e..4fb39fa2 100644 --- a/dist/field/index.js +++ b/dist/field/index.js @@ -19,7 +19,6 @@ create({ required: Boolean, iconClass: String, clearable: Boolean, - labelAlign: String, inputAlign: String, customClass: String, confirmType: String, @@ -60,6 +59,18 @@ create({ showClear: false }, + computed: { + inputClass() { + const { data } = this; + return this.classNames('input-class', 'van-field__input', { + 'van-field--error': data.error, + 'van-field__textarea': data.type === 'textarea', + 'van-field__input--disabled': data.disabled, + [`van-field--${data.inputAlign}`]: data.inputAlign + }); + } + }, + methods: { onInput(event) { const { value = '' } = event.detail || {}; diff --git a/dist/field/index.wxml b/dist/field/index.wxml index 16689cf1..75f98e55 100644 --- a/dist/field/index.wxml +++ b/dist/field/index.wxml @@ -7,13 +7,13 @@ required="{{ required }}" custom-style="{{ customStyle }}" title-width="{{ titleWidth }}" - custom-class="{{ customClass }} van-field {{ labelAlign ? 'van-field--label-' + labelAlign : '' }}" + custom-class="van-field" >