From d87c4a7c29acbc346667efd56c17e426e51aefb9 Mon Sep 17 00:00:00 2001 From: rex-zsd <rexkaneki@gmail.com> Date: Thu, 5 Dec 2019 11:34:39 +0800 Subject: [PATCH] build: compile 1.0.0-beta.6 --- dist/dropdown-item/index.js | 94 +++++++++++++++++--------- dist/dropdown-menu/index.js | 107 +++++++++++------------------ dist/dropdown-menu/index.wxml | 4 +- dist/dropdown-menu/index.wxs | 16 +++++ dist/image/index.wxml | 1 - dist/overlay/index.wxml | 4 +- dist/rate/index.js | 13 +++- dist/rate/index.wxml | 4 +- dist/sidebar/index.js | 2 +- dist/stepper/index.js | 8 ++- dist/stepper/index.wxml | 4 +- dist/tree-select/index.wxml | 2 +- lib/dropdown-item/index.js | 98 ++++++++++++++++++--------- lib/dropdown-menu/index.js | 123 +++++++++++----------------------- lib/dropdown-menu/index.wxml | 4 +- lib/dropdown-menu/index.wxs | 16 +++++ lib/image/index.wxml | 1 - lib/overlay/index.wxml | 4 +- lib/rate/index.js | 13 +++- lib/rate/index.wxml | 4 +- lib/sidebar/index.js | 2 +- lib/stepper/index.js | 8 ++- lib/stepper/index.wxml | 4 +- lib/tree-select/index.wxml | 2 +- 24 files changed, 298 insertions(+), 240 deletions(-) create mode 100644 dist/dropdown-menu/index.wxs create mode 100644 lib/dropdown-menu/index.wxs diff --git a/dist/dropdown-item/index.js b/dist/dropdown-item/index.js index 529de0f5..f2b6c481 100644 --- a/dist/dropdown-item/index.js +++ b/dist/dropdown-item/index.js @@ -6,19 +6,30 @@ VantComponent({ type: 'ancestor', linked(target) { this.parent = target; + this.updateDataFromParent(); }, unlinked() { this.parent = null; } }, props: { - value: null, - title: String, + value: { + type: null, + observer: 'rerender' + }, + title: { + type: String, + observer: 'rerender' + }, disabled: Boolean, - titleClass: String, + titleClass: { + type: String, + observer: 'rerender' + }, options: { type: Array, - value: [] + value: [], + observer: 'rerender' } }, data: { @@ -27,44 +38,67 @@ VantComponent({ showWrapper: false, displayTitle: '' }, - created() { - this.setData({ displayTitle: this.computedDisplayTitle(this.data.value) }); - }, methods: { - computedDisplayTitle(curValue) { - const { title, options } = this.data; - if (title) { - return title; + rerender() { + wx.nextTick(() => { + this.parent && this.parent.updateItemListData(); + }); + }, + updateDataFromParent() { + if (this.parent) { + const { overlay, duration, activeColor, closeOnClickOverlay, direction } = this.parent.data; + this.setData({ + overlay, + duration, + activeColor, + closeOnClickOverlay, + direction + }); } - const match = options.filter(option => option.value === curValue); - const displayTitle = match.length ? match[0].text : ''; - return displayTitle; }, onClickOverlay() { this.toggle(); this.$emit('close'); }, onOptionTap(event) { - let { value, displayTitle } = this.data; const { option } = event.currentTarget.dataset; - const { value: optionValue } = option; - if (optionValue !== value) { - value = optionValue; - displayTitle = this.computedDisplayTitle(optionValue); - this.$emit('change', optionValue); - } - this.setData({ showPopup: false, value, displayTitle }); - const time = this.data.duration || 0; + const { value } = option; + const shouldEmitChange = this.data.value !== value; + this.setData({ showPopup: false, value }); setTimeout(() => { this.setData({ showWrapper: false }); - }, time); - // parent 中的 itemListData 是 children 上的数据的集合 - // 数据的更新由 children 各自维护,但是模板的更新需要额外触发 parent 的 setData - this.parent.setData({ itemListData: this.parent.data.itemListData }); + }, this.data.duration || 0); + this.rerender(); + if (shouldEmitChange) { + this.$emit('change', value); + } }, - toggle() { - const { childIndex } = this.data; - this.parent.toggleItem(childIndex); + toggle(show, options = {}) { + const { showPopup, duration } = this.data; + if (show == null) { + show = !showPopup; + } + if (show === showPopup) { + return; + } + if (!show) { + const time = options.immediate ? 0 : duration; + this.setData({ transition: !options.immediate, showPopup: show }); + setTimeout(() => { + this.setData({ showWrapper: false }); + }, time); + this.rerender(); + return; + } + this.parent.getChildWrapperStyle().then((wrapperStyle = '') => { + this.setData({ + transition: !options.immediate, + showPopup: show, + wrapperStyle, + showWrapper: true + }); + this.rerender(); + }); } } }); diff --git a/dist/dropdown-menu/index.js b/dist/dropdown-menu/index.js index 302659a1..889387be 100644 --- a/dist/dropdown-menu/index.js +++ b/dist/dropdown-menu/index.js @@ -7,33 +7,23 @@ VantComponent({ name: 'dropdown-item', type: 'descendant', linked(target) { - this.children = this.children || []; - // 透传 props 给 dropdown-item - const { overlay, duration, activeColor, closeOnClickOverlay, direction } = this.data; - this.updateChildData(target, { - overlay, - duration, - activeColor, - closeOnClickOverlay, - direction, - childIndex: this.children.length - }); this.children.push(target); - // 收集 dorpdown-item 的 data 挂在 data 上 - target && - this.setData({ - itemListData: this.data.itemListData.concat([target.data]) - }); + this.updateItemListData(); }, unlinked(target) { this.children = this.children.filter((child) => child !== target); + this.updateItemListData(); } }, props: { - activeColor: String, + activeColor: { + type: String, + observer: 'updateChildrenData' + }, overlay: { type: Boolean, - value: true + value: true, + observer: 'updateChildrenData' }, zIndex: { type: Number, @@ -41,15 +31,18 @@ VantComponent({ }, duration: { type: Number, - value: 200 + value: 200, + observer: 'updateChildrenData' }, direction: { type: String, - value: 'down' + value: 'down', + observer: 'updateChildrenData' }, closeOnClickOverlay: { type: Boolean, - value: true + value: true, + observer: 'updateChildrenData' }, closeOnClickOutside: { type: Boolean, @@ -59,68 +52,47 @@ VantComponent({ data: { itemListData: [] }, - created() { + beforeCreate() { + const { windowHeight } = wx.getSystemInfoSync(); + this.windowHeight = windowHeight; + this.children = []; ARRAY.push(this); }, destroyed() { ARRAY = ARRAY.filter(item => item !== this); }, methods: { - updateChildData(childItem, newData, needRefreshList = false) { - childItem.setData(newData); - if (needRefreshList) { - // dropdown-item data 更新,涉及到 title 的展示,触发模板更新 - this.setData({ itemListData: this.data.itemListData }); - } + updateItemListData() { + this.setData({ + itemListData: this.children.map((child) => child.data) + }); + }, + updateChildrenData() { + this.children.forEach((child) => { + child.updateDataFromParent(); + }); }, toggleItem(active) { this.children.forEach((item, index) => { const { showPopup } = item.data; if (index === active) { - this.toggleChildItem(item); + item.toggle(); } else if (showPopup) { - this.toggleChildItem(item, false, { immediate: true }); + item.toggle(false, { immediate: true }); } }); }, - toggleChildItem(childItem, show, options = {}) { - const { showPopup, duration } = childItem.data; - if (show === undefined) - show = !showPopup; - if (show === showPopup) { - return; - } - const newChildData = { transition: !options.immediate, showPopup: show }; - if (!show) { - const time = options.immediate ? 0 : duration; - this.updateChildData(childItem, Object.assign({}, newChildData), true); - setTimeout(() => { - this.updateChildData(childItem, { showWrapper: false }, true); - }, time); - return; - } - this.getChildWrapperStyle().then((wrapperStyle = '') => { - this.updateChildData(childItem, Object.assign(Object.assign({}, newChildData), { wrapperStyle, showWrapper: true }), true); - }); - }, close() { - this.children.forEach((item) => { - this.toggleChildItem(item, false, { immediate: true }); + this.children.forEach((child) => { + child.toggle(false, { immediate: true }); }); }, getChildWrapperStyle() { - const { windowHeight } = wx.getSystemInfoSync(); const { zIndex, direction } = this.data; - let offset = 0; - return this.getRect('.van-dropdown-menu').then(rect => { + return this.getRect('.van-dropdown-menu').then((rect) => { const { top = 0, bottom = 0 } = rect; - if (direction === 'down') { - offset = bottom; - } - else { - offset = windowHeight - top; - } + const offset = direction === 'down' ? bottom : this.windowHeight - top; let wrapperStyle = `z-index: ${zIndex};`; if (direction === 'down') { wrapperStyle += `top: ${addUnit(offset)};`; @@ -128,16 +100,17 @@ VantComponent({ else { wrapperStyle += `bottom: ${addUnit(offset)};`; } - return Promise.resolve(wrapperStyle); + return wrapperStyle; }); }, onTitleTap(event) { - // item ---> dropdown-item - const { item, index } = event.currentTarget.dataset; - if (!item.disabled) { - // menuItem ---> dropdown-menu + const { index } = event.currentTarget.dataset; + const child = this.children[index]; + if (!child.data.disabled) { ARRAY.forEach(menuItem => { - if (menuItem && menuItem.data.closeOnClickOutside && menuItem !== this) { + if (menuItem && + menuItem.data.closeOnClickOutside && + menuItem !== this) { menuItem.close(); } }); diff --git a/dist/dropdown-menu/index.wxml b/dist/dropdown-menu/index.wxml index 22933b57..037ac3b6 100644 --- a/dist/dropdown-menu/index.wxml +++ b/dist/dropdown-menu/index.wxml @@ -1,10 +1,10 @@ <wxs src="../wxs/utils.wxs" module="utils" /> +<wxs src="./index.wxs" module="computed" /> <view class="van-dropdown-menu van-dropdown-menu--top-bottom"> <view wx:for="{{ itemListData }}" wx:key="index" - data-item="{{ item }}" data-index="{{ index }}" class="{{ utils.bem('dropdown-menu__item', { disabled: item.disabled }) }}" bind:tap="onTitleTap" @@ -14,7 +14,7 @@ style="{{ item.showPopup ? 'color:' + activeColor : '' }}" > <view class="van-ellipsis"> - {{item.displayTitle}} + {{ computed.displayTitle(item) }} </view> </view> </view> diff --git a/dist/dropdown-menu/index.wxs b/dist/dropdown-menu/index.wxs new file mode 100644 index 00000000..65388549 --- /dev/null +++ b/dist/dropdown-menu/index.wxs @@ -0,0 +1,16 @@ +/* eslint-disable */ +function displayTitle(item) { + if (item.title) { + return item.title; + } + + var match = item.options.filter(function(option) { + return option.value === item.value; + }); + var displayTitle = match.length ? match[0].text : ''; + return displayTitle; +} + +module.exports = { + displayTitle: displayTitle +}; diff --git a/dist/image/index.wxml b/dist/image/index.wxml index 53e19ef8..4724ca22 100644 --- a/dist/image/index.wxml +++ b/dist/image/index.wxml @@ -8,7 +8,6 @@ <image wx:if="{{ !error }}" src="{{ src }}" - webp mode="{{ mode }}" lazy-load="{{ lazyLoad }}" class="image-class van-image__img" diff --git a/dist/overlay/index.wxml b/dist/overlay/index.wxml index d3e2b5f0..9212348b 100644 --- a/dist/overlay/index.wxml +++ b/dist/overlay/index.wxml @@ -5,4 +5,6 @@ duration="{{ duration }}" bind:tap="onClick" catch:touchmove="noop" -/> +> + <slot></slot> +</van-transition> diff --git a/dist/rate/index.js b/dist/rate/index.js index 20781e04..288ec716 100644 --- a/dist/rate/index.js +++ b/dist/rate/index.js @@ -8,7 +8,10 @@ VantComponent({ readonly: Boolean, disabled: Boolean, allowHalf: Boolean, - size: null, + size: { + type: null, + observer: 'setSizeWithUnit' + }, icon: { type: String, value: 'star' @@ -44,7 +47,8 @@ VantComponent({ }, data: { innerValue: 0, - gutterWithUnit: undefined + gutterWithUnit: undefined, + sizeWithUnit: null }, watch: { value(value) { @@ -59,6 +63,11 @@ VantComponent({ gutterWithUnit: addUnit(val) }); }, + setSizeWithUnit(size) { + this.setData({ + sizeWithUnit: addUnit(size) + }); + }, onSelect(event) { const { data } = this; const { score } = event.currentTarget.dataset; diff --git a/dist/rate/index.wxml b/dist/rate/index.wxml index 9d48ef79..72defd6b 100644 --- a/dist/rate/index.wxml +++ b/dist/rate/index.wxml @@ -12,8 +12,8 @@ > <van-icon name="{{ index + 1 <= innerValue ? icon : voidIcon }}" - size="{{ size }}" class="van-rate__icon" + style="font-size :{{ size? sizeWithUnit : ''}}" custom-class="icon-class" data-score="{{ index }}" color="{{ disabled ? disabledColor : index + 1 <= innerValue ? color : voidColor }}" @@ -22,9 +22,9 @@ <van-icon wx:if="{{ allowHalf }}" - size="{{ size }}" name="{{ index + 0.5 <= innerValue ? icon : voidIcon }}" class="{{ utils.bem('rate__icon', ['half']) }}" + style="font-size :{{ size? sizeWithUnit : ''}}" custom-class="icon-class" data-score="{{ index - 0.5 }}" color="{{ disabled ? disabledColor : index + 0.5 <= innerValue ? color : voidColor }}" diff --git a/dist/sidebar/index.js b/dist/sidebar/index.js index ff6911f2..326faf5c 100644 --- a/dist/sidebar/index.js +++ b/dist/sidebar/index.js @@ -8,7 +8,7 @@ VantComponent({ this.setActive(this.data.activeKey); }, unlinked(target) { - this.items = this.children.filter((item) => item !== target); + this.children = this.children.filter((item) => item !== target); this.setActive(this.data.activeKey); } }, diff --git a/dist/stepper/index.js b/dist/stepper/index.js index 10c2770e..c2425889 100644 --- a/dist/stepper/index.js +++ b/dist/stepper/index.js @@ -41,7 +41,9 @@ VantComponent({ showMinus: { type: Boolean, value: true - } + }, + disablePlus: Boolean, + disableMinus: Boolean }, watch: { value(value) { @@ -78,9 +80,9 @@ VantComponent({ methods: { isDisabled(type) { if (type === 'plus') { - return this.data.disabled || this.data.value >= this.data.max; + return this.data.disabled || this.data.disablePlus || this.data.value >= this.data.max; } - return this.data.disabled || this.data.value <= this.data.min; + return this.data.disabled || this.data.disableMinus || this.data.value <= this.data.min; }, onFocus(event) { this.$emit('focus', event.detail); diff --git a/dist/stepper/index.wxml b/dist/stepper/index.wxml index 06480dc0..456ccced 100644 --- a/dist/stepper/index.wxml +++ b/dist/stepper/index.wxml @@ -5,7 +5,7 @@ wx:if="{{ showMinus }}" data-type="minus" style="{{ buttonStyle }}" - class="minus-class {{ utils.bem('stepper__minus', { disabled: disabled || value <= min }) }}" + class="minus-class {{ utils.bem('stepper__minus', { disabled: disabled || disableMinus || value <= min }) }}" hover-class="van-stepper__minus--hover" hover-stay-time="70" bind:tap="onTap" @@ -27,7 +27,7 @@ wx:if="{{ showPlus }}" data-type="plus" style="{{ buttonStyle }}" - class="plus-class {{ utils.bem('stepper__plus', { disabled: disabled || value >= max }) }}" + class="plus-class {{ utils.bem('stepper__plus', { disabled: disabled || disablePlus || value >= max }) }}" hover-class="van-stepper__plus--hover" hover-stay-time="70" bind:tap="onTap" diff --git a/dist/tree-select/index.wxml b/dist/tree-select/index.wxml index 0e8df176..d6f95a8a 100644 --- a/dist/tree-select/index.wxml +++ b/dist/tree-select/index.wxml @@ -6,7 +6,7 @@ style="height: {{ innerHeight }}" > <scroll-view scroll-y class="van-tree-select__nav"> - <van-sidebar bind:change="onClickNav" custom-class="van-tree-select__nav__inner"> + <van-sidebar active-key="{{ mainActiveIndex }}" bind:change="onClickNav" custom-class="van-tree-select__nav__inner"> <van-sidebar-item wx:for="{{ items }}" wx:key="index" diff --git a/lib/dropdown-item/index.js b/lib/dropdown-item/index.js index 06efeb68..59decdd2 100644 --- a/lib/dropdown-item/index.js +++ b/lib/dropdown-item/index.js @@ -8,19 +8,30 @@ component_1.VantComponent({ type: 'ancestor', linked: function (target) { this.parent = target; + this.updateDataFromParent(); }, unlinked: function () { this.parent = null; } }, props: { - value: null, - title: String, + value: { + type: null, + observer: 'rerender' + }, + title: { + type: String, + observer: 'rerender' + }, disabled: Boolean, - titleClass: String, + titleClass: { + type: String, + observer: 'rerender' + }, options: { type: Array, - value: [] + value: [], + observer: 'rerender' } }, data: { @@ -29,18 +40,24 @@ component_1.VantComponent({ showWrapper: false, displayTitle: '' }, - created: function () { - this.setData({ displayTitle: this.computedDisplayTitle(this.data.value) }); - }, methods: { - computedDisplayTitle: function (curValue) { - var _a = this.data, title = _a.title, options = _a.options; - if (title) { - return title; + rerender: function () { + var _this = this; + wx.nextTick(function () { + _this.parent && _this.parent.updateItemListData(); + }); + }, + updateDataFromParent: function () { + if (this.parent) { + var _a = this.parent.data, overlay = _a.overlay, duration = _a.duration, activeColor = _a.activeColor, closeOnClickOverlay = _a.closeOnClickOverlay, direction = _a.direction; + this.setData({ + overlay: overlay, + duration: duration, + activeColor: activeColor, + closeOnClickOverlay: closeOnClickOverlay, + direction: direction + }); } - var match = options.filter(function (option) { return option.value === curValue; }); - var displayTitle = match.length ? match[0].text : ''; - return displayTitle; }, onClickOverlay: function () { this.toggle(); @@ -48,26 +65,47 @@ component_1.VantComponent({ }, onOptionTap: function (event) { var _this = this; - var _a = this.data, value = _a.value, displayTitle = _a.displayTitle; var option = event.currentTarget.dataset.option; - var optionValue = option.value; - if (optionValue !== value) { - value = optionValue; - displayTitle = this.computedDisplayTitle(optionValue); - this.$emit('change', optionValue); - } - this.setData({ showPopup: false, value: value, displayTitle: displayTitle }); - var time = this.data.duration || 0; + var value = option.value; + var shouldEmitChange = this.data.value !== value; + this.setData({ showPopup: false, value: value }); setTimeout(function () { _this.setData({ showWrapper: false }); - }, time); - // parent 中的 itemListData 是 children 上的数据的集合 - // 数据的更新由 children 各自维护,但是模板的更新需要额外触发 parent 的 setData - this.parent.setData({ itemListData: this.parent.data.itemListData }); + }, this.data.duration || 0); + this.rerender(); + if (shouldEmitChange) { + this.$emit('change', value); + } }, - toggle: function () { - var childIndex = this.data.childIndex; - this.parent.toggleItem(childIndex); + toggle: function (show, options) { + var _this = this; + if (options === void 0) { options = {}; } + var _a = this.data, showPopup = _a.showPopup, duration = _a.duration; + if (show == null) { + show = !showPopup; + } + if (show === showPopup) { + return; + } + if (!show) { + var time = options.immediate ? 0 : duration; + this.setData({ transition: !options.immediate, showPopup: show }); + setTimeout(function () { + _this.setData({ showWrapper: false }); + }, time); + this.rerender(); + return; + } + this.parent.getChildWrapperStyle().then(function (wrapperStyle) { + if (wrapperStyle === void 0) { wrapperStyle = ''; } + _this.setData({ + transition: !options.immediate, + showPopup: show, + wrapperStyle: wrapperStyle, + showWrapper: true + }); + _this.rerender(); + }); } } }); diff --git a/lib/dropdown-menu/index.js b/lib/dropdown-menu/index.js index 430885f2..74f5c212 100644 --- a/lib/dropdown-menu/index.js +++ b/lib/dropdown-menu/index.js @@ -1,15 +1,4 @@ "use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; Object.defineProperty(exports, "__esModule", { value: true }); var component_1 = require("../common/component"); var utils_1 = require("../common/utils"); @@ -20,33 +9,23 @@ component_1.VantComponent({ name: 'dropdown-item', type: 'descendant', linked: function (target) { - this.children = this.children || []; - // 透传 props 给 dropdown-item - var _a = this.data, overlay = _a.overlay, duration = _a.duration, activeColor = _a.activeColor, closeOnClickOverlay = _a.closeOnClickOverlay, direction = _a.direction; - this.updateChildData(target, { - overlay: overlay, - duration: duration, - activeColor: activeColor, - closeOnClickOverlay: closeOnClickOverlay, - direction: direction, - childIndex: this.children.length - }); this.children.push(target); - // 收集 dorpdown-item 的 data 挂在 data 上 - target && - this.setData({ - itemListData: this.data.itemListData.concat([target.data]) - }); + this.updateItemListData(); }, unlinked: function (target) { this.children = this.children.filter(function (child) { return child !== target; }); + this.updateItemListData(); } }, props: { - activeColor: String, + activeColor: { + type: String, + observer: 'updateChildrenData' + }, overlay: { type: Boolean, - value: true + value: true, + observer: 'updateChildrenData' }, zIndex: { type: Number, @@ -54,15 +33,18 @@ component_1.VantComponent({ }, duration: { type: Number, - value: 200 + value: 200, + observer: 'updateChildrenData' }, direction: { type: String, - value: 'down' + value: 'down', + observer: 'updateChildrenData' }, closeOnClickOverlay: { type: Boolean, - value: true + value: true, + observer: 'updateChildrenData' }, closeOnClickOutside: { type: Boolean, @@ -72,7 +54,10 @@ component_1.VantComponent({ data: { itemListData: [] }, - created: function () { + beforeCreate: function () { + var windowHeight = wx.getSystemInfoSync().windowHeight; + this.windowHeight = windowHeight; + this.children = []; ARRAY.push(this); }, destroyed: function () { @@ -80,67 +65,38 @@ component_1.VantComponent({ ARRAY = ARRAY.filter(function (item) { return item !== _this; }); }, methods: { - updateChildData: function (childItem, newData, needRefreshList) { - if (needRefreshList === void 0) { needRefreshList = false; } - childItem.setData(newData); - if (needRefreshList) { - // dropdown-item data 更新,涉及到 title 的展示,触发模板更新 - this.setData({ itemListData: this.data.itemListData }); - } + updateItemListData: function () { + this.setData({ + itemListData: this.children.map(function (child) { return child.data; }) + }); + }, + updateChildrenData: function () { + this.children.forEach(function (child) { + child.updateDataFromParent(); + }); }, toggleItem: function (active) { - var _this = this; this.children.forEach(function (item, index) { var showPopup = item.data.showPopup; if (index === active) { - _this.toggleChildItem(item); + item.toggle(); } else if (showPopup) { - _this.toggleChildItem(item, false, { immediate: true }); + item.toggle(false, { immediate: true }); } }); }, - toggleChildItem: function (childItem, show, options) { - var _this = this; - if (options === void 0) { options = {}; } - var _a = childItem.data, showPopup = _a.showPopup, duration = _a.duration; - if (show === undefined) - show = !showPopup; - if (show === showPopup) { - return; - } - var newChildData = { transition: !options.immediate, showPopup: show }; - if (!show) { - var time = options.immediate ? 0 : duration; - this.updateChildData(childItem, __assign({}, newChildData), true); - setTimeout(function () { - _this.updateChildData(childItem, { showWrapper: false }, true); - }, time); - return; - } - this.getChildWrapperStyle().then(function (wrapperStyle) { - if (wrapperStyle === void 0) { wrapperStyle = ''; } - _this.updateChildData(childItem, __assign(__assign({}, newChildData), { wrapperStyle: wrapperStyle, showWrapper: true }), true); - }); - }, close: function () { - var _this = this; - this.children.forEach(function (item) { - _this.toggleChildItem(item, false, { immediate: true }); + this.children.forEach(function (child) { + child.toggle(false, { immediate: true }); }); }, getChildWrapperStyle: function () { - var windowHeight = wx.getSystemInfoSync().windowHeight; + var _this = this; var _a = this.data, zIndex = _a.zIndex, direction = _a.direction; - var offset = 0; return this.getRect('.van-dropdown-menu').then(function (rect) { var _a = rect.top, top = _a === void 0 ? 0 : _a, _b = rect.bottom, bottom = _b === void 0 ? 0 : _b; - if (direction === 'down') { - offset = bottom; - } - else { - offset = windowHeight - top; - } + var offset = direction === 'down' ? bottom : _this.windowHeight - top; var wrapperStyle = "z-index: " + zIndex + ";"; if (direction === 'down') { wrapperStyle += "top: " + utils_1.addUnit(offset) + ";"; @@ -148,17 +104,18 @@ component_1.VantComponent({ else { wrapperStyle += "bottom: " + utils_1.addUnit(offset) + ";"; } - return Promise.resolve(wrapperStyle); + return wrapperStyle; }); }, onTitleTap: function (event) { var _this = this; - // item ---> dropdown-item - var _a = event.currentTarget.dataset, item = _a.item, index = _a.index; - if (!item.disabled) { - // menuItem ---> dropdown-menu + var index = event.currentTarget.dataset.index; + var child = this.children[index]; + if (!child.data.disabled) { ARRAY.forEach(function (menuItem) { - if (menuItem && menuItem.data.closeOnClickOutside && menuItem !== _this) { + if (menuItem && + menuItem.data.closeOnClickOutside && + menuItem !== _this) { menuItem.close(); } }); diff --git a/lib/dropdown-menu/index.wxml b/lib/dropdown-menu/index.wxml index 22933b57..037ac3b6 100644 --- a/lib/dropdown-menu/index.wxml +++ b/lib/dropdown-menu/index.wxml @@ -1,10 +1,10 @@ <wxs src="../wxs/utils.wxs" module="utils" /> +<wxs src="./index.wxs" module="computed" /> <view class="van-dropdown-menu van-dropdown-menu--top-bottom"> <view wx:for="{{ itemListData }}" wx:key="index" - data-item="{{ item }}" data-index="{{ index }}" class="{{ utils.bem('dropdown-menu__item', { disabled: item.disabled }) }}" bind:tap="onTitleTap" @@ -14,7 +14,7 @@ style="{{ item.showPopup ? 'color:' + activeColor : '' }}" > <view class="van-ellipsis"> - {{item.displayTitle}} + {{ computed.displayTitle(item) }} </view> </view> </view> diff --git a/lib/dropdown-menu/index.wxs b/lib/dropdown-menu/index.wxs new file mode 100644 index 00000000..65388549 --- /dev/null +++ b/lib/dropdown-menu/index.wxs @@ -0,0 +1,16 @@ +/* eslint-disable */ +function displayTitle(item) { + if (item.title) { + return item.title; + } + + var match = item.options.filter(function(option) { + return option.value === item.value; + }); + var displayTitle = match.length ? match[0].text : ''; + return displayTitle; +} + +module.exports = { + displayTitle: displayTitle +}; diff --git a/lib/image/index.wxml b/lib/image/index.wxml index 53e19ef8..4724ca22 100644 --- a/lib/image/index.wxml +++ b/lib/image/index.wxml @@ -8,7 +8,6 @@ <image wx:if="{{ !error }}" src="{{ src }}" - webp mode="{{ mode }}" lazy-load="{{ lazyLoad }}" class="image-class van-image__img" diff --git a/lib/overlay/index.wxml b/lib/overlay/index.wxml index d3e2b5f0..9212348b 100644 --- a/lib/overlay/index.wxml +++ b/lib/overlay/index.wxml @@ -5,4 +5,6 @@ duration="{{ duration }}" bind:tap="onClick" catch:touchmove="noop" -/> +> + <slot></slot> +</van-transition> diff --git a/lib/rate/index.js b/lib/rate/index.js index eb846fdc..1fe4c2b0 100644 --- a/lib/rate/index.js +++ b/lib/rate/index.js @@ -21,7 +21,10 @@ component_1.VantComponent({ readonly: Boolean, disabled: Boolean, allowHalf: Boolean, - size: null, + size: { + type: null, + observer: 'setSizeWithUnit' + }, icon: { type: String, value: 'star' @@ -57,7 +60,8 @@ component_1.VantComponent({ }, data: { innerValue: 0, - gutterWithUnit: undefined + gutterWithUnit: undefined, + sizeWithUnit: null }, watch: { value: function (value) { @@ -72,6 +76,11 @@ component_1.VantComponent({ gutterWithUnit: utils_1.addUnit(val) }); }, + setSizeWithUnit: function (size) { + this.setData({ + sizeWithUnit: utils_1.addUnit(size) + }); + }, onSelect: function (event) { var data = this.data; var score = event.currentTarget.dataset.score; diff --git a/lib/rate/index.wxml b/lib/rate/index.wxml index 9d48ef79..72defd6b 100644 --- a/lib/rate/index.wxml +++ b/lib/rate/index.wxml @@ -12,8 +12,8 @@ > <van-icon name="{{ index + 1 <= innerValue ? icon : voidIcon }}" - size="{{ size }}" class="van-rate__icon" + style="font-size :{{ size? sizeWithUnit : ''}}" custom-class="icon-class" data-score="{{ index }}" color="{{ disabled ? disabledColor : index + 1 <= innerValue ? color : voidColor }}" @@ -22,9 +22,9 @@ <van-icon wx:if="{{ allowHalf }}" - size="{{ size }}" name="{{ index + 0.5 <= innerValue ? icon : voidIcon }}" class="{{ utils.bem('rate__icon', ['half']) }}" + style="font-size :{{ size? sizeWithUnit : ''}}" custom-class="icon-class" data-score="{{ index - 0.5 }}" color="{{ disabled ? disabledColor : index + 0.5 <= innerValue ? color : voidColor }}" diff --git a/lib/sidebar/index.js b/lib/sidebar/index.js index af537a44..f50abbff 100644 --- a/lib/sidebar/index.js +++ b/lib/sidebar/index.js @@ -10,7 +10,7 @@ component_1.VantComponent({ this.setActive(this.data.activeKey); }, unlinked: function (target) { - this.items = this.children.filter(function (item) { return item !== target; }); + this.children = this.children.filter(function (item) { return item !== target; }); this.setActive(this.data.activeKey); } }, diff --git a/lib/stepper/index.js b/lib/stepper/index.js index c0c58bb4..f4e1344d 100644 --- a/lib/stepper/index.js +++ b/lib/stepper/index.js @@ -43,7 +43,9 @@ component_1.VantComponent({ showMinus: { type: Boolean, value: true - } + }, + disablePlus: Boolean, + disableMinus: Boolean }, watch: { value: function (value) { @@ -80,9 +82,9 @@ component_1.VantComponent({ methods: { isDisabled: function (type) { if (type === 'plus') { - return this.data.disabled || this.data.value >= this.data.max; + return this.data.disabled || this.data.disablePlus || this.data.value >= this.data.max; } - return this.data.disabled || this.data.value <= this.data.min; + return this.data.disabled || this.data.disableMinus || this.data.value <= this.data.min; }, onFocus: function (event) { this.$emit('focus', event.detail); diff --git a/lib/stepper/index.wxml b/lib/stepper/index.wxml index 06480dc0..456ccced 100644 --- a/lib/stepper/index.wxml +++ b/lib/stepper/index.wxml @@ -5,7 +5,7 @@ wx:if="{{ showMinus }}" data-type="minus" style="{{ buttonStyle }}" - class="minus-class {{ utils.bem('stepper__minus', { disabled: disabled || value <= min }) }}" + class="minus-class {{ utils.bem('stepper__minus', { disabled: disabled || disableMinus || value <= min }) }}" hover-class="van-stepper__minus--hover" hover-stay-time="70" bind:tap="onTap" @@ -27,7 +27,7 @@ wx:if="{{ showPlus }}" data-type="plus" style="{{ buttonStyle }}" - class="plus-class {{ utils.bem('stepper__plus', { disabled: disabled || value >= max }) }}" + class="plus-class {{ utils.bem('stepper__plus', { disabled: disabled || disablePlus || value >= max }) }}" hover-class="van-stepper__plus--hover" hover-stay-time="70" bind:tap="onTap" diff --git a/lib/tree-select/index.wxml b/lib/tree-select/index.wxml index 0e8df176..d6f95a8a 100644 --- a/lib/tree-select/index.wxml +++ b/lib/tree-select/index.wxml @@ -6,7 +6,7 @@ style="height: {{ innerHeight }}" > <scroll-view scroll-y class="van-tree-select__nav"> - <van-sidebar bind:change="onClickNav" custom-class="van-tree-select__nav__inner"> + <van-sidebar active-key="{{ mainActiveIndex }}" bind:change="onClickNav" custom-class="van-tree-select__nav__inner"> <van-sidebar-item wx:for="{{ items }}" wx:key="index"