diff --git a/dist/cascader/index.d.ts b/dist/cascader/index.d.ts
new file mode 100644
index 00000000..cb0ff5c3
--- /dev/null
+++ b/dist/cascader/index.d.ts
@@ -0,0 +1 @@
+export {};
diff --git a/dist/cascader/index.js b/dist/cascader/index.js
new file mode 100644
index 00000000..a7eeec17
--- /dev/null
+++ b/dist/cascader/index.js
@@ -0,0 +1,205 @@
+import { VantComponent } from '../common/component';
+var FieldName;
+(function (FieldName) {
+ FieldName["TEXT"] = "text";
+ FieldName["VALUE"] = "value";
+ FieldName["CHILDREN"] = "children";
+})(FieldName || (FieldName = {}));
+const defaultFieldNames = {
+ text: FieldName.TEXT,
+ value: FieldName.VALUE,
+ children: FieldName.CHILDREN,
+};
+VantComponent({
+ props: {
+ title: String,
+ value: {
+ type: String,
+ observer: 'updateValue',
+ },
+ placeholder: {
+ type: String,
+ value: '请选择',
+ },
+ activeColor: {
+ type: String,
+ value: '#1989fa',
+ },
+ options: {
+ type: Array,
+ value: [],
+ observer: 'updateOptions',
+ },
+ swipeable: {
+ type: Boolean,
+ value: false,
+ },
+ closeable: {
+ type: Boolean,
+ value: true,
+ },
+ showHeader: {
+ type: Boolean,
+ value: true,
+ },
+ closeIcon: {
+ type: String,
+ value: 'cross',
+ },
+ fieldNames: {
+ type: Object,
+ value: defaultFieldNames,
+ observer: 'updateFieldNames',
+ },
+ },
+ data: {
+ tabs: [],
+ activeTab: 0,
+ textKey: FieldName.TEXT,
+ valueKey: FieldName.VALUE,
+ childrenKey: FieldName.CHILDREN,
+ },
+ created() {
+ this.updateTabs();
+ },
+ methods: {
+ updateOptions(val, oldVal) {
+ const isAsync = !!(val.length && oldVal.length);
+ this.updateTabs(isAsync);
+ },
+ updateValue(val) {
+ if (val !== undefined) {
+ const values = this.data.tabs.map((tab) => tab.selected && tab.selected[this.data.valueKey]);
+ if (values.indexOf(val) > -1) {
+ return;
+ }
+ }
+ this.updateTabs();
+ },
+ updateFieldNames() {
+ const { text = 'text', value = 'value', children = 'children', } = this.data.fieldNames || defaultFieldNames;
+ this.setData({
+ textKey: text,
+ valueKey: value,
+ childrenKey: children,
+ });
+ },
+ getSelectedOptionsByValue(options, value) {
+ for (let i = 0; i < options.length; i++) {
+ const option = options[i];
+ if (option[this.data.valueKey] === value) {
+ return [option];
+ }
+ if (option[this.data.childrenKey]) {
+ const selectedOptions = this.getSelectedOptionsByValue(option[this.data.childrenKey], value);
+ if (selectedOptions) {
+ return [option, ...selectedOptions];
+ }
+ }
+ }
+ },
+ updateTabs(isAsync = false) {
+ const { options, value } = this.data;
+ if (value !== undefined) {
+ const selectedOptions = this.getSelectedOptionsByValue(options, value);
+ if (selectedOptions) {
+ let optionsCursor = options;
+ const tabs = selectedOptions.map((option) => {
+ const tab = {
+ options: optionsCursor,
+ selected: option,
+ };
+ const next = optionsCursor.find((item) => item[this.data.valueKey] === option[this.data.valueKey]);
+ if (next) {
+ optionsCursor = next[this.data.childrenKey];
+ }
+ return tab;
+ });
+ if (optionsCursor) {
+ tabs.push({
+ options: optionsCursor,
+ selected: null,
+ });
+ }
+ this.setData({
+ tabs,
+ });
+ wx.nextTick(() => {
+ this.setData({
+ activeTab: tabs.length - 1,
+ });
+ });
+ return;
+ }
+ }
+ // 异步更新
+ if (isAsync) {
+ const { tabs } = this.data;
+ tabs[tabs.length - 1].options =
+ options[options.length - 1][this.data.childrenKey];
+ this.setData({
+ tabs,
+ });
+ return;
+ }
+ this.setData({
+ tabs: [
+ {
+ options,
+ selected: null,
+ },
+ ],
+ });
+ },
+ onClose() {
+ this.$emit('close');
+ },
+ onClickTab(e) {
+ const { index: tabIndex, title } = e.detail;
+ this.$emit('click-tab', { title, tabIndex });
+ },
+ // 选中
+ onSelect(e) {
+ const { option, tabIndex } = e.currentTarget.dataset;
+ if (option && option.disabled) {
+ return;
+ }
+ const { valueKey, childrenKey } = this.data;
+ let { tabs } = this.data;
+ tabs[tabIndex].selected = option;
+ if (tabs.length > tabIndex + 1) {
+ tabs = tabs.slice(0, tabIndex + 1);
+ }
+ if (option[childrenKey]) {
+ const nextTab = {
+ options: option[childrenKey],
+ selected: null,
+ };
+ if (tabs[tabIndex + 1]) {
+ tabs[tabIndex + 1] = nextTab;
+ }
+ else {
+ tabs.push(nextTab);
+ }
+ wx.nextTick(() => {
+ this.setData({
+ activeTab: tabIndex + 1,
+ });
+ });
+ }
+ this.setData({
+ tabs,
+ });
+ const selectedOptions = tabs.map((tab) => tab.selected).filter(Boolean);
+ const params = {
+ value: option[valueKey],
+ tabIndex,
+ selectedOptions,
+ };
+ this.$emit('change', params);
+ if (!option[childrenKey]) {
+ this.$emit('finish', params);
+ }
+ },
+ },
+});
diff --git a/dist/cascader/index.json b/dist/cascader/index.json
new file mode 100644
index 00000000..d0f75eb7
--- /dev/null
+++ b/dist/cascader/index.json
@@ -0,0 +1,8 @@
+{
+ "component": true,
+ "usingComponents": {
+ "van-icon": "../icon/index",
+ "van-tab": "../tab/index",
+ "van-tabs": "../tabs/index"
+ }
+}
\ No newline at end of file
diff --git a/dist/cascader/index.wxml b/dist/cascader/index.wxml
new file mode 100644
index 00000000..b1d724b9
--- /dev/null
+++ b/dist/cascader/index.wxml
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+
+
+
+
+
+ {{ option[textKey] }}
+
+
+
+
+
+
+
diff --git a/dist/cascader/index.wxs b/dist/cascader/index.wxs
new file mode 100644
index 00000000..cba6465c
--- /dev/null
+++ b/dist/cascader/index.wxs
@@ -0,0 +1,24 @@
+var utils = require('../wxs/utils.wxs');
+var style = require('../wxs/style.wxs');
+
+function isSelected(tab, textKey, option) {
+ return tab.selected && tab.selected[textKey] === option[textKey]
+}
+
+function optionClass(tab, textKey, option) {
+ return utils.bem('cascader__option', { selected: isSelected({ tab, textKey, option }), disabled: option.disabled })
+}
+
+function optionStyle(data) {
+ var color = data.option.color || (isSelected(data.tab, data.textKey, data.option) ? data.activeColor : undefined);
+ return style({
+ color
+ });
+}
+
+
+module.exports = {
+ isSelected: isSelected,
+ optionClass: optionClass,
+ optionStyle: optionStyle,
+};
\ No newline at end of file
diff --git a/dist/cascader/index.wxss b/dist/cascader/index.wxss
new file mode 100644
index 00000000..70624869
--- /dev/null
+++ b/dist/cascader/index.wxss
@@ -0,0 +1 @@
+@import '../common/index.wxss';.van-cascader__header{align-items:center;display:flex;height:48px;justify-content:space-between;padding:0 16px}.van-cascader__title{font-size:16px;font-weight:600;line-height:20px}.van-cascader__close-icon{color:#c8c9cc;font-size:22px;height:22px}.van-cascader__tabs-wrap{height:48px!important;padding:0 8px}.van-cascader__tab{color:#323233!important;flex:none!important;font-weight:600!important;padding:0 8px!important}.van-cascader__tab--unselected{color:#969799!important;font-weight:400!important}.van-cascader__option{align-items:center;cursor:pointer;display:flex;font-size:14px;justify-content:space-between;line-height:20px;padding:10px 16px}.van-cascader__option:active{background-color:#f2f3f5}.van-cascader__option--selected{color:#1989fa;font-weight:600}.van-cascader__option--disabled{color:#c8c9cc;cursor:not-allowed}.van-cascader__option--disabled:active{background-color:initial}.van-cascader__options{-webkit-overflow-scrolling:touch;box-sizing:border-box;height:384px;overflow-y:auto;padding-top:6px}
\ No newline at end of file
diff --git a/dist/common/utils.d.ts b/dist/common/utils.d.ts
index b6532f95..719f2ed7 100644
--- a/dist/common/utils.d.ts
+++ b/dist/common/utils.d.ts
@@ -8,7 +8,7 @@ export { getSystemInfoSync } from './version';
export declare function range(num: number, min: number, max: number): number;
export declare function nextTick(cb: (...args: any[]) => void): void;
export declare function addUnit(value?: string | number): string | undefined;
-export declare function requestAnimationFrame(cb: () => void): NodeJS.Timeout | WechatMiniprogram.NodesRef;
+export declare function requestAnimationFrame(cb: () => void): NodeJS.Timeout;
export declare function pickExclude(obj: unknown, keys: string[]): {};
export declare function getRect(context: WechatMiniprogram.Component.TrivialInstance, selector: string): Promise;
export declare function getAllRect(context: WechatMiniprogram.Component.TrivialInstance, selector: string): Promise;
diff --git a/dist/common/utils.js b/dist/common/utils.js
index 9918f48f..f81f5f4e 100644
--- a/dist/common/utils.js
+++ b/dist/common/utils.js
@@ -1,5 +1,5 @@
import { isDef, isNumber, isPlainObject, isPromise } from './validator';
-import { canIUseGroupSetData, canIUseNextTick, getSystemInfoSync } from './version';
+import { canIUseGroupSetData, canIUseNextTick } from './version';
export { isDef } from './validator';
export { getSystemInfoSync } from './version';
export function range(num, min, max) {
@@ -23,19 +23,9 @@ export function addUnit(value) {
return isNumber(value) ? `${value}px` : value;
}
export function requestAnimationFrame(cb) {
- const systemInfo = getSystemInfoSync();
- if (systemInfo.platform === 'devtools') {
- return setTimeout(() => {
- cb();
- }, 1000 / 30);
- }
- return wx
- .createSelectorQuery()
- .selectViewport()
- .boundingClientRect()
- .exec(() => {
+ return setTimeout(() => {
cb();
- });
+ }, 1000 / 30);
}
export function pickExclude(obj, keys) {
if (!isPlainObject(obj)) {
diff --git a/dist/mixins/page-scroll.js b/dist/mixins/page-scroll.js
index c1e5614b..e08fb6e7 100644
--- a/dist/mixins/page-scroll.js
+++ b/dist/mixins/page-scroll.js
@@ -18,7 +18,7 @@ export function pageScrollMixin(scroller) {
}
const _scroller = scroller.bind(this);
const { vanPageScroller = [] } = page;
- if (!vanPageScroller.length && isFunction(page.onPageScroll)) {
+ if (isFunction(page.onPageScroll) && page.onPageScroll !== onPageScroll) {
vanPageScroller.push(page.onPageScroll.bind(page));
}
vanPageScroller.push(_scroller);
@@ -32,7 +32,7 @@ export function pageScrollMixin(scroller) {
return;
}
const { vanPageScroller } = page;
- const index = vanPageScroller.findIndex(v => v === this._scroller);
+ const index = vanPageScroller.findIndex((v) => v === this._scroller);
if (index > -1) {
page.vanPageScroller.splice(index, 1);
}
diff --git a/dist/tabs/index.js b/dist/tabs/index.js
index 2fcd5d6d..6ee2cb2d 100644
--- a/dist/tabs/index.js
+++ b/dist/tabs/index.js
@@ -5,7 +5,13 @@ import { isDef } from '../common/validator';
import { useChildren } from '../common/relation';
VantComponent({
mixins: [touch],
- classes: ['nav-class', 'tab-class', 'tab-active-class', 'line-class'],
+ classes: [
+ 'nav-class',
+ 'tab-class',
+ 'tab-active-class',
+ 'line-class',
+ 'wrap-class',
+ ],
relation: useChildren('tab', function () {
this.updateTabs();
}),
diff --git a/dist/tabs/index.wxml b/dist/tabs/index.wxml
index 6fcb57f0..f0a01bb8 100644
--- a/dist/tabs/index.wxml
+++ b/dist/tabs/index.wxml
@@ -9,7 +9,7 @@
container="{{ container }}"
bind:scroll="onTouchScroll"
>
-
+
-1) {
+ return;
+ }
+ }
+ this.updateTabs();
+ },
+ updateFieldNames: function () {
+ var _a = this.data.fieldNames || defaultFieldNames, _b = _a.text, text = _b === void 0 ? 'text' : _b, _c = _a.value, value = _c === void 0 ? 'value' : _c, _d = _a.children, children = _d === void 0 ? 'children' : _d;
+ this.setData({
+ textKey: text,
+ valueKey: value,
+ childrenKey: children,
+ });
+ },
+ getSelectedOptionsByValue: function (options, value) {
+ for (var i = 0; i < options.length; i++) {
+ var option = options[i];
+ if (option[this.data.valueKey] === value) {
+ return [option];
+ }
+ if (option[this.data.childrenKey]) {
+ var selectedOptions = this.getSelectedOptionsByValue(option[this.data.childrenKey], value);
+ if (selectedOptions) {
+ return __spreadArray([option], selectedOptions, true);
+ }
+ }
+ }
+ },
+ updateTabs: function (isAsync) {
+ var _this = this;
+ if (isAsync === void 0) { isAsync = false; }
+ var _a = this.data, options = _a.options, value = _a.value;
+ if (value !== undefined) {
+ var selectedOptions = this.getSelectedOptionsByValue(options, value);
+ if (selectedOptions) {
+ var optionsCursor_1 = options;
+ var tabs_1 = selectedOptions.map(function (option) {
+ var tab = {
+ options: optionsCursor_1,
+ selected: option,
+ };
+ var next = optionsCursor_1.find(function (item) { return item[_this.data.valueKey] === option[_this.data.valueKey]; });
+ if (next) {
+ optionsCursor_1 = next[_this.data.childrenKey];
+ }
+ return tab;
+ });
+ if (optionsCursor_1) {
+ tabs_1.push({
+ options: optionsCursor_1,
+ selected: null,
+ });
+ }
+ this.setData({
+ tabs: tabs_1,
+ });
+ wx.nextTick(function () {
+ _this.setData({
+ activeTab: tabs_1.length - 1,
+ });
+ });
+ return;
+ }
+ }
+ // 异步更新
+ if (isAsync) {
+ var tabs = this.data.tabs;
+ tabs[tabs.length - 1].options =
+ options[options.length - 1][this.data.childrenKey];
+ this.setData({
+ tabs: tabs,
+ });
+ return;
+ }
+ this.setData({
+ tabs: [
+ {
+ options: options,
+ selected: null,
+ },
+ ],
+ });
+ },
+ onClose: function () {
+ this.$emit('close');
+ },
+ onClickTab: function (e) {
+ var _a = e.detail, tabIndex = _a.index, title = _a.title;
+ this.$emit('click-tab', { title: title, tabIndex: tabIndex });
+ },
+ // 选中
+ onSelect: function (e) {
+ var _this = this;
+ var _a = e.currentTarget.dataset, option = _a.option, tabIndex = _a.tabIndex;
+ if (option && option.disabled) {
+ return;
+ }
+ var _b = this.data, valueKey = _b.valueKey, childrenKey = _b.childrenKey;
+ var tabs = this.data.tabs;
+ tabs[tabIndex].selected = option;
+ if (tabs.length > tabIndex + 1) {
+ tabs = tabs.slice(0, tabIndex + 1);
+ }
+ if (option[childrenKey]) {
+ var nextTab = {
+ options: option[childrenKey],
+ selected: null,
+ };
+ if (tabs[tabIndex + 1]) {
+ tabs[tabIndex + 1] = nextTab;
+ }
+ else {
+ tabs.push(nextTab);
+ }
+ wx.nextTick(function () {
+ _this.setData({
+ activeTab: tabIndex + 1,
+ });
+ });
+ }
+ this.setData({
+ tabs: tabs,
+ });
+ var selectedOptions = tabs.map(function (tab) { return tab.selected; }).filter(Boolean);
+ var params = {
+ value: option[valueKey],
+ tabIndex: tabIndex,
+ selectedOptions: selectedOptions,
+ };
+ this.$emit('change', params);
+ if (!option[childrenKey]) {
+ this.$emit('finish', params);
+ }
+ },
+ },
+});
diff --git a/lib/cascader/index.json b/lib/cascader/index.json
new file mode 100644
index 00000000..d0f75eb7
--- /dev/null
+++ b/lib/cascader/index.json
@@ -0,0 +1,8 @@
+{
+ "component": true,
+ "usingComponents": {
+ "van-icon": "../icon/index",
+ "van-tab": "../tab/index",
+ "van-tabs": "../tabs/index"
+ }
+}
\ No newline at end of file
diff --git a/lib/cascader/index.wxml b/lib/cascader/index.wxml
new file mode 100644
index 00000000..b1d724b9
--- /dev/null
+++ b/lib/cascader/index.wxml
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+
+
+
+
+
+ {{ option[textKey] }}
+
+
+
+
+
+
+
diff --git a/lib/cascader/index.wxs b/lib/cascader/index.wxs
new file mode 100644
index 00000000..cba6465c
--- /dev/null
+++ b/lib/cascader/index.wxs
@@ -0,0 +1,24 @@
+var utils = require('../wxs/utils.wxs');
+var style = require('../wxs/style.wxs');
+
+function isSelected(tab, textKey, option) {
+ return tab.selected && tab.selected[textKey] === option[textKey]
+}
+
+function optionClass(tab, textKey, option) {
+ return utils.bem('cascader__option', { selected: isSelected({ tab, textKey, option }), disabled: option.disabled })
+}
+
+function optionStyle(data) {
+ var color = data.option.color || (isSelected(data.tab, data.textKey, data.option) ? data.activeColor : undefined);
+ return style({
+ color
+ });
+}
+
+
+module.exports = {
+ isSelected: isSelected,
+ optionClass: optionClass,
+ optionStyle: optionStyle,
+};
\ No newline at end of file
diff --git a/lib/cascader/index.wxss b/lib/cascader/index.wxss
new file mode 100644
index 00000000..70624869
--- /dev/null
+++ b/lib/cascader/index.wxss
@@ -0,0 +1 @@
+@import '../common/index.wxss';.van-cascader__header{align-items:center;display:flex;height:48px;justify-content:space-between;padding:0 16px}.van-cascader__title{font-size:16px;font-weight:600;line-height:20px}.van-cascader__close-icon{color:#c8c9cc;font-size:22px;height:22px}.van-cascader__tabs-wrap{height:48px!important;padding:0 8px}.van-cascader__tab{color:#323233!important;flex:none!important;font-weight:600!important;padding:0 8px!important}.van-cascader__tab--unselected{color:#969799!important;font-weight:400!important}.van-cascader__option{align-items:center;cursor:pointer;display:flex;font-size:14px;justify-content:space-between;line-height:20px;padding:10px 16px}.van-cascader__option:active{background-color:#f2f3f5}.van-cascader__option--selected{color:#1989fa;font-weight:600}.van-cascader__option--disabled{color:#c8c9cc;cursor:not-allowed}.van-cascader__option--disabled:active{background-color:initial}.van-cascader__options{-webkit-overflow-scrolling:touch;box-sizing:border-box;height:384px;overflow-y:auto;padding-top:6px}
\ No newline at end of file
diff --git a/lib/common/utils.d.ts b/lib/common/utils.d.ts
index b6532f95..719f2ed7 100644
--- a/lib/common/utils.d.ts
+++ b/lib/common/utils.d.ts
@@ -8,7 +8,7 @@ export { getSystemInfoSync } from './version';
export declare function range(num: number, min: number, max: number): number;
export declare function nextTick(cb: (...args: any[]) => void): void;
export declare function addUnit(value?: string | number): string | undefined;
-export declare function requestAnimationFrame(cb: () => void): NodeJS.Timeout | WechatMiniprogram.NodesRef;
+export declare function requestAnimationFrame(cb: () => void): NodeJS.Timeout;
export declare function pickExclude(obj: unknown, keys: string[]): {};
export declare function getRect(context: WechatMiniprogram.Component.TrivialInstance, selector: string): Promise;
export declare function getAllRect(context: WechatMiniprogram.Component.TrivialInstance, selector: string): Promise;
diff --git a/lib/common/utils.js b/lib/common/utils.js
index bcc85c45..1e35ad27 100644
--- a/lib/common/utils.js
+++ b/lib/common/utils.js
@@ -31,19 +31,9 @@ function addUnit(value) {
}
exports.addUnit = addUnit;
function requestAnimationFrame(cb) {
- var systemInfo = (0, version_1.getSystemInfoSync)();
- if (systemInfo.platform === 'devtools') {
- return setTimeout(function () {
- cb();
- }, 1000 / 30);
- }
- return wx
- .createSelectorQuery()
- .selectViewport()
- .boundingClientRect()
- .exec(function () {
+ return setTimeout(function () {
cb();
- });
+ }, 1000 / 30);
}
exports.requestAnimationFrame = requestAnimationFrame;
function pickExclude(obj, keys) {
diff --git a/lib/mixins/page-scroll.js b/lib/mixins/page-scroll.js
index d6a3794f..fce7049c 100644
--- a/lib/mixins/page-scroll.js
+++ b/lib/mixins/page-scroll.js
@@ -21,7 +21,7 @@ function pageScrollMixin(scroller) {
}
var _scroller = scroller.bind(this);
var _a = page.vanPageScroller, vanPageScroller = _a === void 0 ? [] : _a;
- if (!vanPageScroller.length && (0, validator_1.isFunction)(page.onPageScroll)) {
+ if ((0, validator_1.isFunction)(page.onPageScroll) && page.onPageScroll !== onPageScroll) {
vanPageScroller.push(page.onPageScroll.bind(page));
}
vanPageScroller.push(_scroller);
diff --git a/lib/tabs/index.js b/lib/tabs/index.js
index b9c22bdb..b8928edb 100644
--- a/lib/tabs/index.js
+++ b/lib/tabs/index.js
@@ -7,7 +7,13 @@ var validator_1 = require("../common/validator");
var relation_1 = require("../common/relation");
(0, component_1.VantComponent)({
mixins: [touch_1.touch],
- classes: ['nav-class', 'tab-class', 'tab-active-class', 'line-class'],
+ classes: [
+ 'nav-class',
+ 'tab-class',
+ 'tab-active-class',
+ 'line-class',
+ 'wrap-class',
+ ],
relation: (0, relation_1.useChildren)('tab', function () {
this.updateTabs();
}),
diff --git a/lib/tabs/index.wxml b/lib/tabs/index.wxml
index 6fcb57f0..f0a01bb8 100644
--- a/lib/tabs/index.wxml
+++ b/lib/tabs/index.wxml
@@ -9,7 +9,7 @@
container="{{ container }}"
bind:scroll="onTouchScroll"
>
-
+