diff --git a/dist/action-sheet/index.d.ts b/dist/action-sheet/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/action-sheet/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/action-sheet/index.js b/dist/action-sheet/index.js index 7a93bff1..28bf57fa 100644 --- a/dist/action-sheet/index.js +++ b/dist/action-sheet/index.js @@ -1,42 +1,41 @@ import { VantComponent } from '../common/component'; import { iphonex } from '../mixins/iphonex'; VantComponent({ - mixins: [iphonex], - props: { - show: Boolean, - title: String, - cancelText: String, - zIndex: { - type: Number, - value: 100 + mixins: [iphonex], + props: { + show: Boolean, + title: String, + cancelText: String, + zIndex: { + type: Number, + value: 100 + }, + actions: { + type: Array, + value: [] + }, + overlay: { + type: Boolean, + value: true + }, + closeOnClickOverlay: { + type: Boolean, + value: true + } }, - actions: { - type: Array, - value: [] - }, - overlay: { - type: Boolean, - value: true - }, - closeOnClickOverlay: { - type: Boolean, - value: true + methods: { + onSelect(event) { + const { index } = event.currentTarget.dataset; + const item = this.data.actions[index]; + if (item && !item.disabled && !item.loading) { + this.$emit('select', item); + } + }, + onCancel() { + this.$emit('cancel'); + }, + onClose() { + this.$emit('close'); + } } - }, - methods: { - onSelect: function onSelect(event) { - var index = event.currentTarget.dataset.index; - var item = this.data.actions[index]; - - if (item && !item.disabled && !item.loading) { - this.$emit('select', item); - } - }, - onCancel: function onCancel() { - this.$emit('cancel'); - }, - onClose: function onClose() { - this.$emit('close'); - } - } -}); \ No newline at end of file +}); diff --git a/dist/area/index.d.ts b/dist/area/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/area/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/area/index.js b/dist/area/index.js index 9c942050..18b1bc05 100644 --- a/dist/area/index.js +++ b/dist/area/index.js @@ -1,208 +1,170 @@ import { VantComponent } from '../common/component'; VantComponent({ - classes: ['active-class', 'toolbar-class', 'column-class'], - props: { - title: String, - value: String, - loading: Boolean, - cancelButtonText: String, - confirmButtonText: String, - itemHeight: { - type: Number, - value: 44 - }, - visibleItemCount: { - type: Number, - value: 5 - }, - columnsNum: { - type: [String, Number], - value: 3 - }, - areaList: { - type: Object, - value: {} - } - }, - data: { - columns: [{ - values: [] - }, { - values: [] - }, { - values: [] - }], - displayColumns: [{ - values: [] - }, { - values: [] - }, { - values: [] - }] - }, - watch: { - value: function value(_value) { - this.code = _value; - this.setValues(); - }, - areaList: 'setValues', - columnsNum: function columnsNum(value) { - this.set({ - displayColumns: this.data.columns.slice(0, +value) - }); - } - }, - methods: { - getPicker: function getPicker() { - if (this.picker == null) { - this.picker = this.selectComponent('.van-area__picker'); - } - - return this.picker; - }, - onCancel: function onCancel(event) { - this.emit('cancel', event.detail); - }, - onConfirm: function onConfirm(event) { - this.emit('confirm', event.detail); - }, - emit: function emit(type, detail) { - detail.values = detail.value; - delete detail.value; - this.$emit(type, detail); - }, - onChange: function onChange(event) { - var _this = this; - - var _event$detail = event.detail, - index = _event$detail.index, - picker = _event$detail.picker, - value = _event$detail.value; - this.code = value[index].code; - this.setValues().then(function () { - _this.$emit('change', { - picker: picker, - values: picker.getValues(), - index: index - }); - }); - }, - getConfig: function getConfig(type) { - var areaList = this.data.areaList; - return areaList && areaList[type + "_list"] || {}; - }, - getList: function getList(type, code) { - var result = []; - - if (type !== 'province' && !code) { - return result; - } - - var list = this.getConfig(type); - result = Object.keys(list).map(function (code) { - return { - code: code, - name: list[code] - }; - }); - - if (code) { - // oversea code - if (code[0] === '9' && type === 'city') { - code = '9'; + classes: ['active-class', 'toolbar-class', 'column-class'], + props: { + title: String, + value: String, + loading: Boolean, + cancelButtonText: String, + confirmButtonText: String, + itemHeight: { + type: Number, + value: 44 + }, + visibleItemCount: { + type: Number, + value: 5 + }, + columnsNum: { + type: [String, Number], + value: 3 + }, + areaList: { + type: Object, + value: {} } - - result = result.filter(function (item) { - return item.code.indexOf(code) === 0; - }); - } - - return result; }, - getIndex: function getIndex(type, code) { - var compareNum = type === 'province' ? 2 : type === 'city' ? 4 : 6; - var list = this.getList(type, code.slice(0, compareNum - 2)); // oversea code - - if (code[0] === '9' && type === 'province') { - compareNum = 1; - } - - code = code.slice(0, compareNum); - - for (var i = 0; i < list.length; i++) { - if (list[i].code.slice(0, compareNum) === code) { - return i; + data: { + columns: [{ values: [] }, { values: [] }, { values: [] }], + displayColumns: [{ values: [] }, { values: [] }, { values: [] }] + }, + watch: { + value(value) { + this.code = value; + this.setValues(); + }, + areaList: 'setValues', + columnsNum(value) { + this.set({ + displayColumns: this.data.columns.slice(0, +value) + }); } - } - - return 0; }, - setValues: function setValues() { - var _this2 = this; - - var county = this.getConfig('county'); - var code = this.code || Object.keys(county)[0] || ''; - var province = this.getList('province'); - var city = this.getList('city', code.slice(0, 2)); - var picker = this.getPicker(); - - if (!picker) { - return; - } - - var stack = []; - stack.push(picker.setColumnValues(0, province, false)); - stack.push(picker.setColumnValues(1, city, false)); - - if (city.length && code.slice(2, 4) === '00') { - ; - code = city[0].code; - } - - stack.push(picker.setColumnValues(2, this.getList('county', code.slice(0, 4)), false)); - return Promise.all(stack).then(function () { - return picker.setIndexes([_this2.getIndex('province', code), _this2.getIndex('city', code), _this2.getIndex('county', code)]); - }).catch(function () {}); - }, - getValues: function getValues() { - var picker = this.getPicker(); - return picker ? picker.getValues().filter(function (value) { - return !!value; - }) : []; - }, - getDetail: function getDetail() { - var values = this.getValues(); - var area = { - code: '', - country: '', - province: '', - city: '', - county: '' - }; - - if (!values.length) { - return area; - } - - var names = values.map(function (item) { - return item.name; - }); - area.code = values[values.length - 1].code; - - if (area.code[0] === '9') { - area.country = names[1] || ''; - area.province = names[2] || ''; - } else { - area.province = names[0] || ''; - area.city = names[1] || ''; - area.county = names[2] || ''; - } - - return area; - }, - reset: function reset() { - this.code = ''; - return this.setValues(); + methods: { + getPicker() { + if (this.picker == null) { + this.picker = this.selectComponent('.van-area__picker'); + } + return this.picker; + }, + onCancel(event) { + this.emit('cancel', event.detail); + }, + onConfirm(event) { + this.emit('confirm', event.detail); + }, + emit(type, detail) { + detail.values = detail.value; + delete detail.value; + this.$emit(type, detail); + }, + onChange(event) { + const { index, picker, value } = event.detail; + this.code = value[index].code; + this.setValues().then(() => { + this.$emit('change', { + picker, + values: picker.getValues(), + index + }); + }); + }, + getConfig(type) { + const { areaList } = this.data; + return (areaList && areaList[`${type}_list`]) || {}; + }, + getList(type, code) { + let result = []; + if (type !== 'province' && !code) { + return result; + } + const list = this.getConfig(type); + result = Object.keys(list).map(code => ({ + code, + name: list[code] + })); + if (code) { + // oversea code + if (code[0] === '9' && type === 'city') { + code = '9'; + } + result = result.filter(item => item.code.indexOf(code) === 0); + } + return result; + }, + getIndex(type, code) { + let compareNum = type === 'province' ? 2 : type === 'city' ? 4 : 6; + const list = this.getList(type, code.slice(0, compareNum - 2)); + // oversea code + if (code[0] === '9' && type === 'province') { + compareNum = 1; + } + code = code.slice(0, compareNum); + for (let i = 0; i < list.length; i++) { + if (list[i].code.slice(0, compareNum) === code) { + return i; + } + } + return 0; + }, + setValues() { + const county = this.getConfig('county'); + let code = this.code || Object.keys(county)[0] || ''; + const province = this.getList('province'); + const city = this.getList('city', code.slice(0, 2)); + const picker = this.getPicker(); + if (!picker) { + return; + } + const stack = []; + stack.push(picker.setColumnValues(0, province, false)); + stack.push(picker.setColumnValues(1, city, false)); + if (city.length && code.slice(2, 4) === '00') { + ; + [{ code }] = city; + } + stack.push(picker.setColumnValues(2, this.getList('county', code.slice(0, 4)), false)); + return Promise.all(stack) + .catch(() => { }) + .then(() => picker.setIndexes([ + this.getIndex('province', code), + this.getIndex('city', code), + this.getIndex('county', code) + ])) + .catch(() => { }); + }, + getValues() { + const picker = this.getPicker(); + return picker ? picker.getValues().filter(value => !!value) : []; + }, + getDetail() { + const values = this.getValues(); + const area = { + code: '', + country: '', + province: '', + city: '', + county: '' + }; + if (!values.length) { + return area; + } + const names = values.map((item) => item.name); + area.code = values[values.length - 1].code; + if (area.code[0] === '9') { + area.country = names[1] || ''; + area.province = names[2] || ''; + } + else { + area.province = names[0] || ''; + area.city = names[1] || ''; + area.county = names[2] || ''; + } + return area; + }, + reset() { + this.code = ''; + return this.setValues(); + } } - } -}); \ No newline at end of file +}); diff --git a/dist/badge-group/index.d.ts b/dist/badge-group/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/badge-group/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/badge-group/index.js b/dist/badge-group/index.js index 5a0ae703..504f9645 100644 --- a/dist/badge-group/index.js +++ b/dist/badge-group/index.js @@ -1,55 +1,49 @@ import { VantComponent } from '../common/component'; import { isNumber } from '../common/utils'; VantComponent({ - relation: { - name: 'badge', - type: 'descendant', - linked: function linked(target) { - this.badges.push(target); - this.setActive(); + relation: { + name: 'badge', + type: 'descendant', + linked(target) { + this.badges.push(target); + this.setActive(); + }, + unlinked(target) { + this.badges = this.badges.filter(item => item !== target); + this.setActive(); + } }, - unlinked: function unlinked(target) { - this.badges = this.badges.filter(function (item) { - return item !== target; - }); - this.setActive(); + props: { + active: { + type: Number, + value: 0 + } + }, + watch: { + active: 'setActive' + }, + beforeCreate() { + this.badges = []; + this.currentActive = -1; + }, + methods: { + setActive(badge) { + let { active } = this.data; + const { badges } = this; + if (badge && !isNumber(badge)) { + active = badges.indexOf(badge); + } + if (active === this.currentActive) { + return; + } + if (this.currentActive !== -1 && badges[this.currentActive]) { + this.$emit('change', active); + badges[this.currentActive].setActive(false); + } + if (badges[active]) { + badges[active].setActive(true); + this.currentActive = active; + } + } } - }, - props: { - active: { - type: Number, - value: 0 - } - }, - watch: { - active: 'setActive' - }, - beforeCreate: function beforeCreate() { - this.badges = []; - this.currentActive = -1; - }, - methods: { - setActive: function setActive(badge) { - var active = this.data.active; - var badges = this.badges; - - if (badge && !isNumber(badge)) { - active = badges.indexOf(badge); - } - - if (active === this.currentActive) { - return; - } - - if (this.currentActive !== -1 && badges[this.currentActive]) { - this.$emit('change', active); - badges[this.currentActive].setActive(false); - } - - if (badges[active]) { - badges[active].setActive(true); - this.currentActive = active; - } - } - } -}); \ No newline at end of file +}); diff --git a/dist/badge/index.d.ts b/dist/badge/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/badge/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/badge/index.js b/dist/badge/index.js index f039df3c..58704dd8 100644 --- a/dist/badge/index.js +++ b/dist/badge/index.js @@ -1,25 +1,22 @@ import { VantComponent } from '../common/component'; VantComponent({ - relation: { - type: 'ancestor', - name: 'badge-group' - }, - props: { - info: null, - title: String - }, - methods: { - onClick: function onClick() { - var group = this.getRelationNodes('../badge-group/index')[0]; - - if (group) { - group.setActive(this); - } + relation: { + type: 'ancestor', + name: 'badge-group' }, - setActive: function setActive(active) { - this.set({ - active: active - }); + props: { + info: null, + title: String + }, + methods: { + onClick() { + const group = this.getRelationNodes('../badge-group/index')[0]; + if (group) { + group.setActive(this); + } + }, + setActive(active) { + this.set({ active }); + } } - } -}); \ No newline at end of file +}); diff --git a/dist/button/index.d.ts b/dist/button/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/button/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/button/index.js b/dist/button/index.js index 32cc3486..001cdf73 100644 --- a/dist/button/index.js +++ b/dist/button/index.js @@ -2,34 +2,34 @@ import { VantComponent } from '../common/component'; import { button } from '../mixins/button'; import { openType } from '../mixins/open-type'; VantComponent({ - mixins: [button, openType], - classes: ['hover-class', 'loading-class'], - props: { - plain: Boolean, - block: Boolean, - round: Boolean, - square: Boolean, - loading: Boolean, - disabled: Boolean, - loadingText: String, - type: { - type: String, - value: 'default' + mixins: [button, openType], + classes: ['hover-class', 'loading-class'], + props: { + plain: Boolean, + block: Boolean, + round: Boolean, + square: Boolean, + loading: Boolean, + disabled: Boolean, + loadingText: String, + type: { + type: String, + value: 'default' + }, + size: { + type: String, + value: 'normal' + }, + loadingSize: { + type: String, + value: '20px' + } }, - size: { - type: String, - value: 'normal' - }, - loadingSize: { - type: String, - value: '20px' + methods: { + onClick() { + if (!this.data.disabled && !this.data.loading) { + this.$emit('click'); + } + } } - }, - methods: { - onClick: function onClick() { - if (!this.data.disabled && !this.data.loading) { - this.$emit('click'); - } - } - } -}); \ No newline at end of file +}); diff --git a/dist/card/index.d.ts b/dist/card/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/card/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/card/index.js b/dist/card/index.js index 47e9761f..ae641517 100644 --- a/dist/card/index.js +++ b/dist/card/index.js @@ -1,31 +1,38 @@ import { link } from '../mixins/link'; import { VantComponent } from '../common/component'; VantComponent({ - classes: ['num-class', 'desc-class', 'thumb-class', 'title-class', 'price-class', 'origin-price-class'], - mixins: [link], - props: { - tag: String, - num: String, - desc: String, - thumb: String, - title: String, - price: String, - centered: Boolean, - lazyLoad: Boolean, - thumbLink: String, - originPrice: String, - thumbMode: { - type: String, - value: 'aspectFit' + classes: [ + 'num-class', + 'desc-class', + 'thumb-class', + 'title-class', + 'price-class', + 'origin-price-class', + ], + mixins: [link], + props: { + tag: String, + num: String, + desc: String, + thumb: String, + title: String, + price: String, + centered: Boolean, + lazyLoad: Boolean, + thumbLink: String, + originPrice: String, + thumbMode: { + type: String, + value: 'aspectFit' + }, + currency: { + type: String, + value: '¥' + } }, - currency: { - type: String, - value: '¥' + methods: { + onClickThumb() { + this.jumpLink('thumbLink'); + } } - }, - methods: { - onClickThumb: function onClickThumb() { - this.jumpLink('thumbLink'); - } - } -}); \ No newline at end of file +}); diff --git a/dist/cell-group/index.d.ts b/dist/cell-group/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/cell-group/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/cell-group/index.js b/dist/cell-group/index.js index a9e114c1..8e42c191 100644 --- a/dist/cell-group/index.js +++ b/dist/cell-group/index.js @@ -1,9 +1,9 @@ import { VantComponent } from '../common/component'; VantComponent({ - props: { - border: { - type: Boolean, - value: true + props: { + border: { + type: Boolean, + value: true + } } - } -}); \ No newline at end of file +}); diff --git a/dist/cell/index.d.ts b/dist/cell/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/cell/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/cell/index.js b/dist/cell/index.js index 5607b9e3..ab79c1d3 100644 --- a/dist/cell/index.js +++ b/dist/cell/index.js @@ -1,30 +1,36 @@ import { link } from '../mixins/link'; import { VantComponent } from '../common/component'; VantComponent({ - classes: ['title-class', 'label-class', 'value-class', 'right-icon-class', 'hover-class'], - mixins: [link], - props: { - title: null, - value: null, - icon: String, - size: String, - label: String, - center: Boolean, - isLink: Boolean, - required: Boolean, - clickable: Boolean, - titleWidth: String, - customStyle: String, - arrowDirection: String, - border: { - type: Boolean, - value: true + classes: [ + 'title-class', + 'label-class', + 'value-class', + 'right-icon-class', + 'hover-class' + ], + mixins: [link], + props: { + title: null, + value: null, + icon: String, + size: String, + label: String, + center: Boolean, + isLink: Boolean, + required: Boolean, + clickable: Boolean, + titleWidth: String, + customStyle: String, + arrowDirection: String, + border: { + type: Boolean, + value: true + } + }, + methods: { + onClick(event) { + this.$emit('click', event.detail); + this.jumpLink(); + } } - }, - methods: { - onClick: function onClick(event) { - this.$emit('click', event.detail); - this.jumpLink(); - } - } -}); \ No newline at end of file +}); diff --git a/dist/checkbox-group/index.d.ts b/dist/checkbox-group/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/checkbox-group/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/checkbox-group/index.js b/dist/checkbox-group/index.js index 354468b1..1fe63829 100644 --- a/dist/checkbox-group/index.js +++ b/dist/checkbox-group/index.js @@ -1,40 +1,34 @@ import { VantComponent } from '../common/component'; VantComponent({ - field: true, - relation: { - name: 'checkbox', - type: 'descendant', - linked: function linked(target) { - var _this$data = this.data, - value = _this$data.value, - disabled = _this$data.disabled; - target.set({ - value: value.indexOf(target.data.name) !== -1, - disabled: disabled || target.data.disabled - }); - } - }, - props: { - max: Number, - value: Array, - disabled: Boolean - }, - watch: { - value: function value(_value) { - var children = this.getRelationNodes('../checkbox/index'); - children.forEach(function (child) { - child.set({ - value: _value.indexOf(child.data.name) !== -1 - }); - }); + field: true, + relation: { + name: 'checkbox', + type: 'descendant', + linked(target) { + const { value, disabled } = this.data; + target.set({ + value: value.indexOf(target.data.name) !== -1, + disabled: disabled || target.data.disabled + }); + } }, - disabled: function disabled(_disabled) { - var children = this.getRelationNodes('../checkbox/index'); - children.forEach(function (child) { - child.set({ - disabled: _disabled || child.data.disabled - }); - }); + props: { + max: Number, + value: Array, + disabled: Boolean + }, + watch: { + value(value) { + const children = this.getRelationNodes('../checkbox/index'); + children.forEach(child => { + child.set({ value: value.indexOf(child.data.name) !== -1 }); + }); + }, + disabled(disabled) { + const children = this.getRelationNodes('../checkbox/index'); + children.forEach(child => { + child.set({ disabled: disabled || child.data.disabled }); + }); + } } - } -}); \ No newline at end of file +}); diff --git a/dist/checkbox/index.d.ts b/dist/checkbox/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/checkbox/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/checkbox/index.js b/dist/checkbox/index.js index b3d82e29..c2bd6155 100644 --- a/dist/checkbox/index.js +++ b/dist/checkbox/index.js @@ -1,70 +1,67 @@ import { VantComponent } from '../common/component'; VantComponent({ - field: true, - relation: { - name: 'checkbox-group', - type: 'ancestor' - }, - classes: ['icon-class', 'label-class'], - props: { - value: null, - disabled: Boolean, - useIconSlot: Boolean, - checkedColor: String, - labelPosition: String, - labelDisabled: Boolean, - shape: { - type: String, - value: 'round' + field: true, + relation: { + name: 'checkbox-group', + type: 'ancestor' + }, + classes: ['icon-class', 'label-class'], + props: { + value: null, + disabled: Boolean, + useIconSlot: Boolean, + checkedColor: String, + labelPosition: String, + labelDisabled: Boolean, + shape: { + type: String, + value: 'round' + } + }, + methods: { + emitChange(value) { + const parent = this.getRelationNodes('../checkbox-group/index')[0]; + if (parent) { + this.setParentValue(parent, value); + } + else { + this.$emit('input', value); + this.$emit('change', value); + } + }, + toggle() { + if (!this.data.disabled) { + this.emitChange(!this.data.value); + } + }, + onClickLabel() { + if (!this.data.disabled && !this.data.labelDisabled) { + this.emitChange(!this.data.value); + } + }, + setParentValue(parent, value) { + const parentValue = parent.data.value.slice(); + const { name } = this.data; + if (value) { + if (parent.data.max && parentValue.length >= parent.data.max) { + return; + } + /* istanbul ignore else */ + if (parentValue.indexOf(name) === -1) { + parentValue.push(name); + parent.$emit('input', parentValue); + parent.$emit('change', parentValue); + } + } + else { + const index = parentValue.indexOf(name); + /* istanbul ignore else */ + if (index !== -1) { + parentValue.splice(index, 1); + parent.$emit('input', parentValue); + parent.$emit('change', parentValue); + } + } + } } - }, - methods: { - emitChange: function emitChange(value) { - var parent = this.getRelationNodes('../checkbox-group/index')[0]; - - if (parent) { - this.setParentValue(parent, value); - } else { - this.$emit('input', value); - this.$emit('change', value); - } - }, - toggle: function toggle() { - if (!this.data.disabled) { - this.emitChange(!this.data.value); - } - }, - onClickLabel: function onClickLabel() { - if (!this.data.disabled && !this.data.labelDisabled) { - this.emitChange(!this.data.value); - } - }, - setParentValue: function setParentValue(parent, value) { - var parentValue = parent.data.value.slice(); - var name = this.data.name; - - if (value) { - if (parent.data.max && parentValue.length >= parent.data.max) { - return; - } - /* istanbul ignore else */ - - - if (parentValue.indexOf(name) === -1) { - parentValue.push(name); - parent.$emit('input', parentValue); - parent.$emit('change', parentValue); - } - } else { - var index = parentValue.indexOf(name); - /* istanbul ignore else */ - - if (index !== -1) { - parentValue.splice(index, 1); - parent.$emit('input', parentValue); - parent.$emit('change', parentValue); - } - } - } - } -}); \ No newline at end of file +}); diff --git a/dist/col/index.d.ts b/dist/col/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/col/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/col/index.js b/dist/col/index.js index 7b8b85b2..8976a5fc 100644 --- a/dist/col/index.js +++ b/dist/col/index.js @@ -1,26 +1,23 @@ import { VantComponent } from '../common/component'; VantComponent({ - relation: { - name: 'row', - type: 'ancestor' - }, - props: { - span: Number, - offset: Number - }, - data: { - style: '' - }, - methods: { - setGutter: function setGutter(gutter) { - var padding = gutter / 2 + "px"; - var style = gutter ? "padding-left: " + padding + "; padding-right: " + padding + ";" : ''; - - if (style !== this.data.style) { - this.set({ - style: style - }); - } + relation: { + name: 'row', + type: 'ancestor' + }, + props: { + span: Number, + offset: Number + }, + data: { + style: '' + }, + methods: { + setGutter(gutter) { + const padding = `${gutter / 2}px`; + const style = gutter ? `padding-left: ${padding}; padding-right: ${padding};` : ''; + if (style !== this.data.style) { + this.set({ style }); + } + } } - } -}); \ No newline at end of file +}); diff --git a/dist/collapse-item/index.d.ts b/dist/collapse-item/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/collapse-item/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/collapse-item/index.js b/dist/collapse-item/index.js index 640f1c5c..6b5d7912 100644 --- a/dist/collapse-item/index.js +++ b/dist/collapse-item/index.js @@ -1,105 +1,91 @@ import { VantComponent } from '../common/component'; VantComponent({ - classes: ['title-class', 'content-class'], - relation: { - name: 'collapse', - type: 'ancestor', - linked: function linked(parent) { - this.parent = parent; - } - }, - props: { - name: null, - title: null, - value: null, - icon: String, - label: String, - disabled: Boolean, - border: { - type: Boolean, - value: true - }, - isLink: { - type: Boolean, - value: true - } - }, - data: { - contentHeight: 0, - expanded: false - }, - beforeCreate: function beforeCreate() { - this.animation = wx.createAnimation({ - duration: 300, - timingFunction: 'ease-in-out' - }); - }, - methods: { - updateExpanded: function updateExpanded() { - if (!this.parent) { - return null; - } - - var _this$parent$data = this.parent.data, - value = _this$parent$data.value, - accordion = _this$parent$data.accordion, - items = _this$parent$data.items; - var name = this.data.name; - var index = items.indexOf(this); - var currentName = name == null ? index : name; - var expanded = accordion ? value === currentName : value.some(function (name) { - return name === currentName; - }); - - if (expanded !== this.data.expanded) { - this.updateStyle(expanded); - } - - this.set({ - expanded: expanded - }); - }, - updateStyle: function updateStyle(expanded) { - var _this = this; - - this.getRect('.van-collapse-item__content').then(function (res) { - var animationData = _this.animation.height(expanded ? res.height : 0).step().export(); - - if (expanded) { - _this.set({ - animationData: animationData - }); - } else { - _this.set({ - contentHeight: res.height + 'px' - }, function () { - setTimeout(function () { - _this.set({ - animationData: animationData - }); - }, 20); - }); + classes: ['title-class', 'content-class'], + relation: { + name: 'collapse', + type: 'ancestor', + linked(parent) { + this.parent = parent; } - }); }, - onClick: function onClick() { - if (this.data.disabled) { - return; - } - - var _this$data = this.data, - name = _this$data.name, - expanded = _this$data.expanded; - var index = this.parent.data.items.indexOf(this); - var currentName = name == null ? index : name; - this.parent.switch(currentName, !expanded); + props: { + name: null, + title: null, + value: null, + icon: String, + label: String, + disabled: Boolean, + border: { + type: Boolean, + value: true + }, + isLink: { + type: Boolean, + value: true + } }, - onTransitionEnd: function onTransitionEnd() { - if (this.data.expanded) { - this.set({ - contentHeight: 'auto' + data: { + contentHeight: 0, + expanded: false + }, + beforeCreate() { + this.animation = wx.createAnimation({ + duration: 300, + timingFunction: 'ease-in-out' }); - } + }, + methods: { + updateExpanded() { + if (!this.parent) { + return null; + } + const { value, accordion, items } = this.parent.data; + const { name } = this.data; + const index = items.indexOf(this); + const currentName = name == null ? index : name; + const expanded = accordion + ? value === currentName + : value.some(name => name === currentName); + if (expanded !== this.data.expanded) { + this.updateStyle(expanded); + } + this.set({ expanded }); + }, + updateStyle(expanded) { + this.getRect('.van-collapse-item__content').then(res => { + const animationData = this.animation + .height(expanded ? res.height : 0) + .step() + .export(); + if (expanded) { + this.set({ animationData }); + } + else { + this.set({ + contentHeight: res.height + 'px' + }, () => { + setTimeout(() => { + this.set({ animationData }); + }, 20); + }); + } + }); + }, + onClick() { + if (this.data.disabled) { + return; + } + const { name, expanded } = this.data; + const index = this.parent.data.items.indexOf(this); + const currentName = name == null ? index : name; + this.parent.switch(currentName, !expanded); + }, + onTransitionEnd() { + if (this.data.expanded) { + this.set({ + contentHeight: 'auto' + }); + } + } } - } -}); \ No newline at end of file +}); diff --git a/dist/collapse/index.d.ts b/dist/collapse/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/collapse/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/collapse/index.js b/dist/collapse/index.js index 66f2348a..0093de63 100644 --- a/dist/collapse/index.js +++ b/dist/collapse/index.js @@ -1,51 +1,48 @@ import { VantComponent } from '../common/component'; VantComponent({ - relation: { - name: 'collapse-item', - type: 'descendant', - linked: function linked(child) { - this.set({ - items: [].concat(this.data.items, [child]) - }, function () { - child.updateExpanded(); - }); - } - }, - props: { - accordion: Boolean, - value: null - }, - data: { - items: [] - }, - watch: { - value: function value() { - this.data.items.forEach(function (child) { - child.updateExpanded(); - }); + relation: { + name: 'collapse-item', + type: 'descendant', + linked(child) { + this.set({ + items: [...this.data.items, child] + }, () => { + child.updateExpanded(); + }); + } }, - accordion: function accordion() { - this.data.items.forEach(function (child) { - child.updateExpanded(); - }); + props: { + accordion: Boolean, + value: null + }, + data: { + items: [] + }, + watch: { + value() { + this.data.items.forEach(child => { + child.updateExpanded(); + }); + }, + accordion() { + this.data.items.forEach(child => { + child.updateExpanded(); + }); + } + }, + methods: { + switch(name, expanded) { + const { accordion, value } = this.data; + if (!accordion) { + name = expanded + ? value.concat(name) + : value.filter(activeName => activeName !== name); + } + else { + name = expanded ? name : ''; + } + this.$emit('change', name); + this.$emit('input', name); + } } - }, - methods: { - switch: function _switch(name, expanded) { - var _this$data = this.data, - accordion = _this$data.accordion, - value = _this$data.value; - - if (!accordion) { - name = expanded ? value.concat(name) : value.filter(function (activeName) { - return activeName !== name; - }); - } else { - name = expanded ? name : ''; - } - - this.$emit('change', name); - this.$emit('input', name); - } - } -}); \ No newline at end of file +}); diff --git a/dist/common/color.d.ts b/dist/common/color.d.ts new file mode 100644 index 00000000..5fa14477 --- /dev/null +++ b/dist/common/color.d.ts @@ -0,0 +1,3 @@ +export declare const RED = "#f44"; +export declare const BLUE = "#1989fa"; +export declare const GREEN = "#07c160"; diff --git a/dist/common/color.js b/dist/common/color.js index eff548d2..5f5e9660 100644 --- a/dist/common/color.js +++ b/dist/common/color.js @@ -1,3 +1,3 @@ -export var RED = '#f44'; -export var BLUE = '#1989fa'; -export var GREEN = '#07c160'; \ No newline at end of file +export const RED = '#f44'; +export const BLUE = '#1989fa'; +export const GREEN = '#07c160'; diff --git a/dist/common/component.d.ts b/dist/common/component.d.ts new file mode 100644 index 00000000..db706927 --- /dev/null +++ b/dist/common/component.d.ts @@ -0,0 +1,2 @@ +declare function VantComponent(vantOptions?: VantComponentOptions>): void; +export { VantComponent }; diff --git a/dist/common/component.js b/dist/common/component.js index 0bae29c7..63ef1a9d 100644 --- a/dist/common/component.js +++ b/dist/common/component.js @@ -1,59 +1,48 @@ import { basic } from '../mixins/basic'; import { observe } from '../mixins/observer/index'; - function mapKeys(source, target, map) { - Object.keys(map).forEach(function (key) { - if (source[key]) { - target[map[key]] = source[key]; - } - }); -} - -function VantComponent(vantOptions) { - if (vantOptions === void 0) { - vantOptions = {}; - } - - var options = {}; - mapKeys(vantOptions, options, { - data: 'data', - props: 'properties', - mixins: 'behaviors', - methods: 'methods', - beforeCreate: 'created', - created: 'attached', - mounted: 'ready', - relations: 'relations', - destroyed: 'detached', - classes: 'externalClasses' - }); - var _vantOptions = vantOptions, - relation = _vantOptions.relation; - - if (relation) { - options.relations = Object.assign(options.relations || {}, { - ["../" + relation.name + "/index"]: relation + Object.keys(map).forEach(key => { + if (source[key]) { + target[map[key]] = source[key]; + } }); - } // add default externalClasses - - - options.externalClasses = options.externalClasses || []; - options.externalClasses.push('custom-class'); // add default behaviors - - options.behaviors = options.behaviors || []; - options.behaviors.push(basic); // map field to form-field behavior - - if (vantOptions.field) { - options.behaviors.push('wx://form-field'); - } // add default options - - - options.options = { - multipleSlots: true, - addGlobalClass: true - }; - observe(vantOptions, options); - Component(options); } - -export { VantComponent }; \ No newline at end of file +function VantComponent(vantOptions = {}) { + const options = {}; + mapKeys(vantOptions, options, { + data: 'data', + props: 'properties', + mixins: 'behaviors', + methods: 'methods', + beforeCreate: 'created', + created: 'attached', + mounted: 'ready', + relations: 'relations', + destroyed: 'detached', + classes: 'externalClasses' + }); + const { relation } = vantOptions; + if (relation) { + options.relations = Object.assign(options.relations || {}, { + [`../${relation.name}/index`]: relation + }); + } + // add default externalClasses + options.externalClasses = options.externalClasses || []; + options.externalClasses.push('custom-class'); + // add default behaviors + options.behaviors = options.behaviors || []; + options.behaviors.push(basic); + // map field to form-field behavior + if (vantOptions.field) { + options.behaviors.push('wx://form-field'); + } + // add default options + options.options = { + multipleSlots: true, + addGlobalClass: true + }; + observe(vantOptions, options); + Component(options); +} +export { VantComponent }; diff --git a/dist/common/utils.d.ts b/dist/common/utils.d.ts new file mode 100644 index 00000000..1d4ea463 --- /dev/null +++ b/dist/common/utils.d.ts @@ -0,0 +1,5 @@ +declare function isDef(value: any): boolean; +declare function isObj(x: any): boolean; +declare function isNumber(value: any): boolean; +declare function range(num: number, min: number, max: number): number; +export { isObj, isDef, isNumber, range }; diff --git a/dist/common/utils.js b/dist/common/utils.js index a3455a38..2f0a66a9 100644 --- a/dist/common/utils.js +++ b/dist/common/utils.js @@ -1,18 +1,14 @@ function isDef(value) { - return value !== undefined && value !== null; + return value !== undefined && value !== null; } - function isObj(x) { - var type = typeof x; - return x !== null && (type === 'object' || type === 'function'); + const type = typeof x; + return x !== null && (type === 'object' || type === 'function'); } - function isNumber(value) { - return /^\d+$/.test(value); + return /^\d+$/.test(value); } - function range(num, min, max) { - return Math.min(Math.max(num, min), max); + return Math.min(Math.max(num, min), max); } - -export { isObj, isDef, isNumber, range }; \ No newline at end of file +export { isObj, isDef, isNumber, range }; diff --git a/dist/datetime-picker/index.d.ts b/dist/datetime-picker/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/datetime-picker/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/datetime-picker/index.js b/dist/datetime-picker/index.js index 13c70449..d4f27062 100644 --- a/dist/datetime-picker/index.js +++ b/dist/datetime-picker/index.js @@ -1,355 +1,295 @@ import { VantComponent } from '../common/component'; import { isDef } from '../common/utils'; -var currentYear = new Date().getFullYear(); - +const currentYear = new Date().getFullYear(); function isValidDate(date) { - return isDef(date) && !isNaN(new Date(date).getTime()); + return isDef(date) && !isNaN(new Date(date).getTime()); } - function range(num, min, max) { - return Math.min(Math.max(num, min), max); + return Math.min(Math.max(num, min), max); } - function padZero(val) { - return ("00" + val).slice(-2); + return `00${val}`.slice(-2); } - function times(n, iteratee) { - var index = -1; - var result = Array(n); - - while (++index < n) { - result[index] = iteratee(index); - } - - return result; + let index = -1; + const result = Array(n); + while (++index < n) { + result[index] = iteratee(index); + } + return result; } - function getTrueValue(formattedValue) { - if (!formattedValue) return; - - while (isNaN(parseInt(formattedValue, 10))) { - formattedValue = formattedValue.slice(1); - } - - return parseInt(formattedValue, 10); + if (!formattedValue) + return; + while (isNaN(parseInt(formattedValue, 10))) { + formattedValue = formattedValue.slice(1); + } + return parseInt(formattedValue, 10); } - function getMonthEndDay(year, month) { - return 32 - new Date(year, month - 1, 32).getDate(); + return 32 - new Date(year, month - 1, 32).getDate(); } - VantComponent({ - props: { - value: null, - title: String, - loading: Boolean, - itemHeight: { - type: Number, - value: 44 + props: { + value: null, + title: String, + loading: Boolean, + itemHeight: { + type: Number, + value: 44 + }, + visibleItemCount: { + type: Number, + value: 5 + }, + confirmButtonText: { + type: String, + value: '确认' + }, + cancelButtonText: { + type: String, + value: '取消' + }, + type: { + type: String, + value: 'datetime' + }, + showToolbar: { + type: Boolean, + value: true + }, + minDate: { + type: Number, + value: new Date(currentYear - 10, 0, 1).getTime() + }, + maxDate: { + type: Number, + value: new Date(currentYear + 10, 11, 31).getTime() + }, + minHour: { + type: Number, + value: 0 + }, + maxHour: { + type: Number, + value: 23 + }, + minMinute: { + type: Number, + value: 0 + }, + maxMinute: { + type: Number, + value: 59 + } }, - visibleItemCount: { - type: Number, - value: 5 + data: { + innerValue: Date.now(), + columns: [] }, - confirmButtonText: { - type: String, - value: '确认' - }, - cancelButtonText: { - type: String, - value: '取消' - }, - type: { - type: String, - value: 'datetime' - }, - showToolbar: { - type: Boolean, - value: true - }, - minDate: { - type: Number, - value: new Date(currentYear - 10, 0, 1).getTime() - }, - maxDate: { - type: Number, - value: new Date(currentYear + 10, 11, 31).getTime() - }, - minHour: { - type: Number, - value: 0 - }, - maxHour: { - type: Number, - value: 23 - }, - minMinute: { - type: Number, - value: 0 - }, - maxMinute: { - type: Number, - value: 59 - } - }, - data: { - innerValue: Date.now(), - columns: [] - }, - watch: { - value: function value(val) { - var _this = this; - - var data = this.data; - val = this.correctValue(val); - var isEqual = val === data.innerValue; - - if (!isEqual) { - this.updateColumnValue(val).then(function () { - _this.$emit('input', val); - }); - } - }, - type: 'updateColumns', - minHour: 'updateColumns', - maxHour: 'updateColumns', - minMinute: 'updateColumns', - maxMinute: 'updateColumns' - }, - methods: { - getPicker: function getPicker() { - if (this.picker == null) { - var picker = this.picker = this.selectComponent('.van-datetime-picker'); - var setColumnValues = picker.setColumnValues; - - picker.setColumnValues = function () { - for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - - return setColumnValues.apply(picker, [].concat(args, [false])); - }; - } - - return this.picker; - }, - updateColumns: function updateColumns() { - var results = this.getRanges().map(function (_ref, index) { - var type = _ref.type, - range = _ref.range; - var values = times(range[1] - range[0] + 1, function (index) { - var value = range[0] + index; - value = type === 'year' ? "" + value : padZero(value); - return value; - }); - return { - values: values - }; - }); - return this.set({ - columns: results - }); - }, - getRanges: function getRanges() { - var data = this.data; - - if (data.type === 'time') { - return [{ - type: 'hour', - range: [data.minHour, data.maxHour] - }, { - type: 'minute', - range: [data.minMinute, data.maxMinute] - }]; - } - - var _this$getBoundary = this.getBoundary('max', data.innerValue), - maxYear = _this$getBoundary.maxYear, - maxDate = _this$getBoundary.maxDate, - maxMonth = _this$getBoundary.maxMonth, - maxHour = _this$getBoundary.maxHour, - maxMinute = _this$getBoundary.maxMinute; - - var _this$getBoundary2 = this.getBoundary('min', data.innerValue), - minYear = _this$getBoundary2.minYear, - minDate = _this$getBoundary2.minDate, - minMonth = _this$getBoundary2.minMonth, - minHour = _this$getBoundary2.minHour, - minMinute = _this$getBoundary2.minMinute; - - var result = [{ - type: 'year', - range: [minYear, maxYear] - }, { - type: 'month', - range: [minMonth, maxMonth] - }, { - type: 'day', - range: [minDate, maxDate] - }, { - type: 'hour', - range: [minHour, maxHour] - }, { - type: 'minute', - range: [minMinute, maxMinute] - }]; - if (data.type === 'date') result.splice(3, 2); - if (data.type === 'year-month') result.splice(2, 3); - return result; - }, - correctValue: function correctValue(value) { - var data = this.data; // validate value - - var isDateType = data.type !== 'time'; - - if (isDateType && !isValidDate(value)) { - value = data.minDate; - } else if (!isDateType && !value) { - var minHour = data.minHour; - value = padZero(minHour) + ":00"; - } // time type - - - if (!isDateType) { - var _value$split = value.split(':'), - hour = _value$split[0], - minute = _value$split[1]; - - hour = padZero(range(hour, data.minHour, data.maxHour)); - minute = padZero(range(minute, data.minMinute, data.maxMinute)); - return hour + ":" + minute; - } // date type - - - value = Math.max(value, data.minDate); - value = Math.min(value, data.maxDate); - return value; - }, - getBoundary: function getBoundary(type, innerValue) { - var value = new Date(innerValue); - var boundary = new Date(this.data[type + "Date"]); - var year = boundary.getFullYear(); - var month = 1; - var date = 1; - var hour = 0; - var minute = 0; - - if (type === 'max') { - month = 12; - date = getMonthEndDay(value.getFullYear(), value.getMonth() + 1); - hour = 23; - minute = 59; - } - - if (value.getFullYear() === year) { - month = boundary.getMonth() + 1; - - if (value.getMonth() + 1 === month) { - date = boundary.getDate(); - - if (value.getDate() === date) { - hour = boundary.getHours(); - - if (value.getHours() === hour) { - minute = boundary.getMinutes(); + watch: { + value(val) { + const { data } = this; + val = this.correctValue(val); + const isEqual = val === data.innerValue; + if (!isEqual) { + this.updateColumnValue(val).then(() => { + this.$emit('input', val); + }); } - } - } - } - - return { - [type + "Year"]: year, - [type + "Month"]: month, - [type + "Date"]: date, - [type + "Hour"]: hour, - [type + "Minute"]: minute - }; + }, + type: 'updateColumns', + minHour: 'updateColumns', + maxHour: 'updateColumns', + minMinute: 'updateColumns', + maxMinute: 'updateColumns' }, - onCancel: function onCancel() { - this.$emit('cancel'); + methods: { + getPicker() { + if (this.picker == null) { + const picker = this.picker = this.selectComponent('.van-datetime-picker'); + const { setColumnValues } = picker; + picker.setColumnValues = (...args) => setColumnValues.apply(picker, [...args, false]); + } + return this.picker; + }, + updateColumns() { + const results = this.getRanges().map(({ type, range }, index) => { + const values = times(range[1] - range[0] + 1, index => { + let value = range[0] + index; + value = type === 'year' ? `${value}` : padZero(value); + return value; + }); + return { values }; + }); + return this.set({ columns: results }); + }, + getRanges() { + const { data } = this; + if (data.type === 'time') { + return [ + { + type: 'hour', + range: [data.minHour, data.maxHour] + }, + { + type: 'minute', + range: [data.minMinute, data.maxMinute] + } + ]; + } + const { maxYear, maxDate, maxMonth, maxHour, maxMinute } = this.getBoundary('max', data.innerValue); + const { minYear, minDate, minMonth, minHour, minMinute } = this.getBoundary('min', data.innerValue); + const result = [ + { + type: 'year', + range: [minYear, maxYear] + }, + { + type: 'month', + range: [minMonth, maxMonth] + }, + { + type: 'day', + range: [minDate, maxDate] + }, + { + type: 'hour', + range: [minHour, maxHour] + }, + { + type: 'minute', + range: [minMinute, maxMinute] + } + ]; + if (data.type === 'date') + result.splice(3, 2); + if (data.type === 'year-month') + result.splice(2, 3); + return result; + }, + correctValue(value) { + const { data } = this; + // validate value + const isDateType = data.type !== 'time'; + if (isDateType && !isValidDate(value)) { + value = data.minDate; + } + else if (!isDateType && !value) { + const { minHour } = data; + value = `${padZero(minHour)}:00`; + } + // time type + if (!isDateType) { + let [hour, minute] = value.split(':'); + hour = padZero(range(hour, data.minHour, data.maxHour)); + minute = padZero(range(minute, data.minMinute, data.maxMinute)); + return `${hour}:${minute}`; + } + // date type + value = Math.max(value, data.minDate); + value = Math.min(value, data.maxDate); + return value; + }, + getBoundary(type, innerValue) { + const value = new Date(innerValue); + const boundary = new Date(this.data[`${type}Date`]); + const year = boundary.getFullYear(); + let month = 1; + let date = 1; + let hour = 0; + let minute = 0; + if (type === 'max') { + month = 12; + date = getMonthEndDay(value.getFullYear(), value.getMonth() + 1); + hour = 23; + minute = 59; + } + if (value.getFullYear() === year) { + month = boundary.getMonth() + 1; + if (value.getMonth() + 1 === month) { + date = boundary.getDate(); + if (value.getDate() === date) { + hour = boundary.getHours(); + if (value.getHours() === hour) { + minute = boundary.getMinutes(); + } + } + } + } + return { + [`${type}Year`]: year, + [`${type}Month`]: month, + [`${type}Date`]: date, + [`${type}Hour`]: hour, + [`${type}Minute`]: minute + }; + }, + onCancel() { + this.$emit('cancel'); + }, + onConfirm() { + this.$emit('confirm', this.data.innerValue); + }, + onChange() { + const { data } = this; + let value; + const picker = this.getPicker(); + if (data.type === 'time') { + const indexes = picker.getIndexes(); + value = `${indexes[0] + data.minHour}:${indexes[1] + data.minMinute}`; + } + else { + const values = picker.getValues(); + const year = getTrueValue(values[0]); + const month = getTrueValue(values[1]); + const maxDate = getMonthEndDay(year, month); + let date = getTrueValue(values[2]); + if (data.type === 'year-month') { + date = 1; + } + date = date > maxDate ? maxDate : date; + let hour = 0; + let minute = 0; + if (data.type === 'datetime') { + hour = getTrueValue(values[3]); + minute = getTrueValue(values[4]); + } + value = new Date(year, month - 1, date, hour, minute); + } + value = this.correctValue(value); + this.updateColumnValue(value).then(() => { + this.$emit('input', value); + this.$emit('change', picker); + }); + }, + updateColumnValue(value) { + let values = []; + const { data } = this; + const picker = this.getPicker(); + if (data.type === 'time') { + const pair = value.split(':'); + values = [pair[0], pair[1]]; + } + else { + const date = new Date(value); + values = [`${date.getFullYear()}`, padZero(date.getMonth() + 1)]; + if (data.type === 'date') { + values.push(padZero(date.getDate())); + } + if (data.type === 'datetime') { + values.push(padZero(date.getDate()), padZero(date.getHours()), padZero(date.getMinutes())); + } + } + return this.set({ innerValue: value }) + .then(() => this.updateColumns()) + .then(() => picker.setValues(values)); + } }, - onConfirm: function onConfirm() { - this.$emit('confirm', this.data.innerValue); - }, - onChange: function onChange() { - var _this2 = this; - - var data = this.data; - var value; - var picker = this.getPicker(); - - if (data.type === 'time') { - var indexes = picker.getIndexes(); - value = indexes[0] + data.minHour + ":" + (indexes[1] + data.minMinute); - } else { - var values = picker.getValues(); - var year = getTrueValue(values[0]); - var month = getTrueValue(values[1]); - var maxDate = getMonthEndDay(year, month); - var date = getTrueValue(values[2]); - - if (data.type === 'year-month') { - date = 1; - } - - date = date > maxDate ? maxDate : date; - var hour = 0; - var minute = 0; - - if (data.type === 'datetime') { - hour = getTrueValue(values[3]); - minute = getTrueValue(values[4]); - } - - value = new Date(year, month - 1, date, hour, minute); - } - - value = this.correctValue(value); - this.updateColumnValue(value).then(function () { - _this2.$emit('input', value); - - _this2.$emit('change', picker); - }); - }, - updateColumnValue: function updateColumnValue(value) { - var _this3 = this; - - var values = []; - var data = this.data; - var picker = this.getPicker(); - - if (data.type === 'time') { - var pair = value.split(':'); - values = [pair[0], pair[1]]; - } else { - var date = new Date(value); - values = ["" + date.getFullYear(), padZero(date.getMonth() + 1)]; - - if (data.type === 'date') { - values.push(padZero(date.getDate())); - } - - if (data.type === 'datetime') { - values.push(padZero(date.getDate()), padZero(date.getHours()), padZero(date.getMinutes())); - } - } - - return this.set({ - innerValue: value - }).then(function () { - return _this3.updateColumns(); - }).then(function () { - return picker.setValues(values); - }); + created() { + const innerValue = this.correctValue(this.data.value); + this.updateColumnValue(innerValue).then(() => { + this.$emit('input', innerValue); + }); } - }, - created: function created() { - var _this4 = this; - - var innerValue = this.correctValue(this.data.value); - this.updateColumnValue(innerValue).then(function () { - _this4.$emit('input', innerValue); - }); - } -}); \ No newline at end of file +}); diff --git a/dist/dialog/dialog.d.ts b/dist/dialog/dialog.d.ts new file mode 100644 index 00000000..745dcda2 --- /dev/null +++ b/dist/dialog/dialog.d.ts @@ -0,0 +1,42 @@ +declare type DialogAction = 'confirm' | 'cancel'; +declare type DialogOptions = { + lang?: string; + show?: boolean; + title?: string; + zIndex?: number; + context?: any; + message?: string; + overlay?: boolean; + selector?: string; + ariaLabel?: string; + transition?: string; + asyncClose?: boolean; + businessId?: number; + sessionFrom?: string; + appParameter?: string; + messageAlign?: string; + sendMessageImg?: string; + showMessageCard?: boolean; + sendMessagePath?: string; + sendMessageTitle?: string; + confirmButtonText?: string; + cancelButtonText?: string; + showConfirmButton?: boolean; + showCancelButton?: boolean; + closeOnClickOverlay?: boolean; + confirmButtonOpenType?: string; +}; +interface Dialog { + (options: DialogOptions): Promise; + alert?: (options: DialogOptions) => Promise; + confirm?: (options: DialogOptions) => Promise; + close?: () => void; + stopLoading?: () => void; + install?: () => void; + setDefaultOptions?: (options: DialogOptions) => void; + resetDefaultOptions?: () => void; + defaultOptions?: DialogOptions; + currentOptions?: DialogOptions; +} +declare const Dialog: Dialog; +export default Dialog; diff --git a/dist/dialog/dialog.js b/dist/dialog/dialog.js index fedfe376..8b7f723b 100644 --- a/dist/dialog/dialog.js +++ b/dist/dialog/dialog.js @@ -1,76 +1,58 @@ -function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } - -var queue = []; - +let queue = []; function getContext() { - var pages = getCurrentPages(); - return pages[pages.length - 1]; + const pages = getCurrentPages(); + return pages[pages.length - 1]; } - -var Dialog = function Dialog(options) { - options = _extends({}, Dialog.currentOptions, options); - return new Promise(function (resolve, reject) { - var context = options.context || getContext(); - var dialog = context.selectComponent(options.selector); - delete options.selector; - - if (dialog) { - dialog.set(_extends({ - onCancel: reject, - onConfirm: resolve - }, options)); - queue.push(dialog); - } else { - console.warn('未找到 van-dialog 节点,请确认 selector 及 context 是否正确'); - } - }); +const Dialog = options => { + options = Object.assign({}, Dialog.currentOptions, options); + return new Promise((resolve, reject) => { + const context = options.context || getContext(); + const dialog = context.selectComponent(options.selector); + delete options.selector; + if (dialog) { + dialog.set(Object.assign({ onCancel: reject, onConfirm: resolve }, options)); + queue.push(dialog); + } + else { + console.warn('未找到 van-dialog 节点,请确认 selector 及 context 是否正确'); + } + }); }; - Dialog.defaultOptions = { - show: true, - title: '', - message: '', - zIndex: 100, - overlay: true, - asyncClose: false, - messageAlign: '', - transition: 'scale', - selector: '#van-dialog', - confirmButtonText: '确认', - cancelButtonText: '取消', - showConfirmButton: true, - showCancelButton: false, - closeOnClickOverlay: false, - confirmButtonOpenType: '' + show: true, + title: '', + message: '', + zIndex: 100, + overlay: true, + asyncClose: false, + messageAlign: '', + transition: 'scale', + selector: '#van-dialog', + confirmButtonText: '确认', + cancelButtonText: '取消', + showConfirmButton: true, + showCancelButton: false, + closeOnClickOverlay: false, + confirmButtonOpenType: '' }; Dialog.alert = Dialog; - -Dialog.confirm = function (options) { - return Dialog(_extends({ - showCancelButton: true - }, options)); +Dialog.confirm = options => Dialog(Object.assign({ showCancelButton: true }, options)); +Dialog.close = () => { + queue.forEach(dialog => { + dialog.close(); + }); + queue = []; }; - -Dialog.close = function () { - queue.forEach(function (dialog) { - dialog.close(); - }); - queue = []; +Dialog.stopLoading = () => { + queue.forEach(dialog => { + dialog.stopLoading(); + }); }; - -Dialog.stopLoading = function () { - queue.forEach(function (dialog) { - dialog.stopLoading(); - }); +Dialog.setDefaultOptions = options => { + Object.assign(Dialog.currentOptions, options); }; - -Dialog.setDefaultOptions = function (options) { - Object.assign(Dialog.currentOptions, options); +Dialog.resetDefaultOptions = () => { + Dialog.currentOptions = Object.assign({}, Dialog.defaultOptions); }; - -Dialog.resetDefaultOptions = function () { - Dialog.currentOptions = _extends({}, Dialog.defaultOptions); -}; - Dialog.resetDefaultOptions(); -export default Dialog; \ No newline at end of file +export default Dialog; diff --git a/dist/dialog/index.d.ts b/dist/dialog/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/dialog/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/dialog/index.js b/dist/dialog/index.js index 2e5d8fd5..1ca9f520 100644 --- a/dist/dialog/index.js +++ b/dist/dialog/index.js @@ -2,100 +2,95 @@ import { VantComponent } from '../common/component'; import { button } from '../mixins/button'; import { openType } from '../mixins/open-type'; VantComponent({ - mixins: [button, openType], - props: { - show: Boolean, - title: String, - message: String, - useSlot: Boolean, - asyncClose: Boolean, - messageAlign: String, - showCancelButton: Boolean, - closeOnClickOverlay: Boolean, - confirmButtonOpenType: String, - zIndex: { - type: Number, - value: 2000 - }, - confirmButtonText: { - type: String, - value: '确认' - }, - cancelButtonText: { - type: String, - value: '取消' - }, - showConfirmButton: { - type: Boolean, - value: true - }, - overlay: { - type: Boolean, - value: true - }, - transition: { - type: String, - value: 'scale' - } - }, - data: { - loading: { - confirm: false, - cancel: false - } - }, - watch: { - show: function show(_show) { - !_show && this.stopLoading(); - } - }, - methods: { - onConfirm: function onConfirm() { - this.handleAction('confirm'); - }, - onCancel: function onCancel() { - this.handleAction('cancel'); - }, - onClickOverlay: function onClickOverlay() { - this.onClose('overlay'); - }, - handleAction: function handleAction(action) { - if (this.data.asyncClose) { - this.set({ - ["loading." + action]: true - }); - } - - this.onClose(action); - }, - close: function close() { - this.set({ - show: false - }); - }, - stopLoading: function stopLoading() { - this.set({ - loading: { - confirm: false, - cancel: false + mixins: [button, openType], + props: { + show: Boolean, + title: String, + message: String, + useSlot: Boolean, + asyncClose: Boolean, + messageAlign: String, + showCancelButton: Boolean, + closeOnClickOverlay: Boolean, + confirmButtonOpenType: String, + zIndex: { + type: Number, + value: 2000 + }, + confirmButtonText: { + type: String, + value: '确认' + }, + cancelButtonText: { + type: String, + value: '取消' + }, + showConfirmButton: { + type: Boolean, + value: true + }, + overlay: { + type: Boolean, + value: true + }, + transition: { + type: String, + value: 'scale' } - }); }, - onClose: function onClose(action) { - if (!this.data.asyncClose) { - this.close(); - } - - this.$emit('close', action); //把 dialog 实例传递出去,可以通过 stopLoading() 在外部关闭按钮的 loading - - this.$emit(action, { - dialog: this - }); - var callback = this.data[action === 'confirm' ? 'onConfirm' : 'onCancel']; - - if (callback) { - callback(this); - } + data: { + loading: { + confirm: false, + cancel: false + } + }, + watch: { + show(show) { + !show && this.stopLoading(); + } + }, + methods: { + onConfirm() { + this.handleAction('confirm'); + }, + onCancel() { + this.handleAction('cancel'); + }, + onClickOverlay() { + this.onClose('overlay'); + }, + handleAction(action) { + if (this.data.asyncClose) { + this.set({ + [`loading.${action}`]: true + }); + } + this.onClose(action); + }, + close() { + this.set({ + show: false + }); + }, + stopLoading() { + this.set({ + loading: { + confirm: false, + cancel: false + } + }); + }, + onClose(action) { + if (!this.data.asyncClose) { + this.close(); + } + this.$emit('close', action); + //把 dialog 实例传递出去,可以通过 stopLoading() 在外部关闭按钮的 loading + this.$emit(action, { dialog: this }); + const callback = this.data[action === 'confirm' ? 'onConfirm' : 'onCancel']; + if (callback) { + callback(this); + } + } } - } -}); \ No newline at end of file +}); diff --git a/dist/field/index.d.ts b/dist/field/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/field/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/field/index.js b/dist/field/index.js index f16f4630..bedaf02c 100644 --- a/dist/field/index.js +++ b/dist/field/index.js @@ -1,155 +1,130 @@ import { VantComponent } from '../common/component'; VantComponent({ - field: true, - classes: ['input-class'], - props: { - icon: String, - label: String, - error: Boolean, - fixed: Boolean, - focus: Boolean, - center: Boolean, - isLink: Boolean, - leftIcon: String, - disabled: Boolean, - autosize: Boolean, - readonly: Boolean, - required: Boolean, - iconClass: String, - clearable: Boolean, - inputAlign: String, - customClass: String, - confirmType: String, - confirmHold: Boolean, - errorMessage: String, - placeholder: String, - customStyle: String, - useIconSlot: Boolean, - useButtonSlot: Boolean, - showConfirmBar: { - type: Boolean, - value: true + field: true, + classes: ['input-class'], + props: { + size: String, + icon: String, + label: String, + error: Boolean, + fixed: Boolean, + focus: Boolean, + center: Boolean, + isLink: Boolean, + leftIcon: String, + disabled: Boolean, + autosize: Boolean, + readonly: Boolean, + required: Boolean, + iconClass: String, + clearable: Boolean, + inputAlign: String, + customClass: String, + confirmType: String, + confirmHold: Boolean, + errorMessage: String, + placeholder: String, + customStyle: String, + useIconSlot: Boolean, + useButtonSlot: Boolean, + showConfirmBar: { + type: Boolean, + value: true + }, + placeholderStyle: String, + adjustPosition: { + type: Boolean, + value: true + }, + cursorSpacing: { + type: Number, + value: 50 + }, + maxlength: { + type: Number, + value: -1 + }, + type: { + type: String, + value: 'text' + }, + border: { + type: Boolean, + value: true + }, + titleWidth: { + type: String, + value: '90px' + } }, - placeholderStyle: String, - adjustPosition: { - type: Boolean, - value: true + data: { + showClear: false }, - cursorSpacing: { - type: Number, - value: 50 + beforeCreate() { + this.focused = false; }, - maxlength: { - type: Number, - value: -1 - }, - type: { - type: String, - value: 'text' - }, - border: { - type: Boolean, - value: true - }, - titleWidth: { - type: String, - value: '90px' + methods: { + onInput(event) { + const { value = '' } = event.detail || {}; + this.set({ + value, + showClear: this.getShowClear(value) + }, () => { + this.emitChange(value); + }); + }, + onFocus(event) { + const { value = '', height = 0 } = event.detail || {}; + this.$emit('focus', { value, height }); + this.focused = true; + this.blurFromClear = false; + this.set({ + showClear: this.getShowClear() + }); + }, + onBlur(event) { + const { value = '', cursor = 0 } = event.detail || {}; + this.$emit('blur', { value, cursor }); + this.focused = false; + const showClear = this.getShowClear(); + if (this.data.value === value) { + this.set({ + showClear + }); + } + else if (!this.blurFromClear) { + // fix: the handwritten keyboard does not trigger input change + this.set({ + value, + showClear + }, () => { + this.emitChange(value); + }); + } + }, + onClickIcon() { + this.$emit('click-icon'); + }, + getShowClear(value) { + value = value === undefined ? this.data.value : value; + return (this.data.clearable && this.focused && value && !this.data.readonly); + }, + onClear() { + this.blurFromClear = true; + this.set({ + value: '', + showClear: this.getShowClear('') + }, () => { + this.emitChange(''); + this.$emit('clear', ''); + }); + }, + onConfirm() { + this.$emit('confirm', this.data.value); + }, + emitChange(value) { + this.$emit('input', value); + this.$emit('change', value); + } } - }, - data: { - showClear: false - }, - beforeCreate: function beforeCreate() { - this.focused = false; - }, - methods: { - onInput: function onInput(event) { - var _this = this; - - var _ref = event.detail || {}, - _ref$value = _ref.value, - value = _ref$value === void 0 ? '' : _ref$value; - - this.set({ - value: value, - showClear: this.getShowClear(value) - }, function () { - _this.emitChange(value); - }); - }, - onFocus: function onFocus(event) { - var _ref2 = event.detail || {}, - _ref2$value = _ref2.value, - value = _ref2$value === void 0 ? '' : _ref2$value, - _ref2$height = _ref2.height, - height = _ref2$height === void 0 ? 0 : _ref2$height; - - this.$emit('focus', { - value: value, - height: height - }); - this.focused = true; - this.blurFromClear = false; - this.set({ - showClear: this.getShowClear() - }); - }, - onBlur: function onBlur(event) { - var _this2 = this; - - var _ref3 = event.detail || {}, - _ref3$value = _ref3.value, - value = _ref3$value === void 0 ? '' : _ref3$value, - _ref3$cursor = _ref3.cursor, - cursor = _ref3$cursor === void 0 ? 0 : _ref3$cursor; - - this.$emit('blur', { - value: value, - cursor: cursor - }); - this.focused = false; - var showClear = this.getShowClear(); - - if (this.data.value === value) { - this.set({ - showClear: showClear - }); - } else if (!this.blurFromClear) { - // fix: the handwritten keyboard does not trigger input change - this.set({ - value: value, - showClear: showClear - }, function () { - _this2.emitChange(value); - }); - } - }, - onClickIcon: function onClickIcon() { - this.$emit('click-icon'); - }, - getShowClear: function getShowClear(value) { - value = value === undefined ? this.data.value : value; - return this.data.clearable && this.focused && value && !this.data.readonly; - }, - onClear: function onClear() { - var _this3 = this; - - this.blurFromClear = true; - this.set({ - value: '', - showClear: this.getShowClear('') - }, function () { - _this3.emitChange(''); - - _this3.$emit('clear', ''); - }); - }, - onConfirm: function onConfirm() { - this.$emit('confirm', this.data.value); - }, - emitChange: function emitChange(value) { - this.$emit('input', value); - this.$emit('change', value); - } - } -}); \ No newline at end of file +}); diff --git a/dist/field/index.wxml b/dist/field/index.wxml index 68326bdf..baa5f4df 100644 --- a/dist/field/index.wxml +++ b/dist/field/index.wxml @@ -10,6 +10,7 @@ custom-style="{{ customStyle }}" title-width="{{ titleWidth }}" custom-class="van-field" + size="{{ size }}" > diff --git a/dist/goods-action-button/index.d.ts b/dist/goods-action-button/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/goods-action-button/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/goods-action-button/index.js b/dist/goods-action-button/index.js index 82ae7f8e..b96e1c82 100644 --- a/dist/goods-action-button/index.js +++ b/dist/goods-action-button/index.js @@ -3,20 +3,20 @@ import { link } from '../mixins/link'; import { button } from '../mixins/button'; import { openType } from '../mixins/open-type'; VantComponent({ - mixins: [link, button, openType], - props: { - text: String, - loading: Boolean, - disabled: Boolean, - type: { - type: String, - value: 'danger' + mixins: [link, button, openType], + props: { + text: String, + loading: Boolean, + disabled: Boolean, + type: { + type: String, + value: 'danger' + } + }, + methods: { + onClick(event) { + this.$emit('click', event.detail); + this.jumpLink(); + } } - }, - methods: { - onClick: function onClick(event) { - this.$emit('click', event.detail); - this.jumpLink(); - } - } -}); \ No newline at end of file +}); diff --git a/dist/goods-action-icon/index.d.ts b/dist/goods-action-icon/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/goods-action-icon/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/goods-action-icon/index.js b/dist/goods-action-icon/index.js index 637f9dfd..8599f765 100644 --- a/dist/goods-action-icon/index.js +++ b/dist/goods-action-icon/index.js @@ -3,17 +3,17 @@ import { link } from '../mixins/link'; import { button } from '../mixins/button'; import { openType } from '../mixins/open-type'; VantComponent({ - classes: ['icon-class', 'text-class'], - mixins: [link, button, openType], - props: { - text: String, - info: String, - icon: String - }, - methods: { - onClick: function onClick(event) { - this.$emit('click', event.detail); - this.jumpLink(); + classes: ['icon-class', 'text-class'], + mixins: [link, button, openType], + props: { + text: String, + info: String, + icon: String + }, + methods: { + onClick(event) { + this.$emit('click', event.detail); + this.jumpLink(); + } } - } -}); \ No newline at end of file +}); diff --git a/dist/goods-action/index.d.ts b/dist/goods-action/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/goods-action/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/goods-action/index.js b/dist/goods-action/index.js index 3f875b99..edb5cc2e 100644 --- a/dist/goods-action/index.js +++ b/dist/goods-action/index.js @@ -1,5 +1,5 @@ import { VantComponent } from '../common/component'; import { iphonex } from '../mixins/iphonex'; VantComponent({ - mixins: [iphonex] -}); \ No newline at end of file + mixins: [iphonex] +}); diff --git a/dist/icon/index.d.ts b/dist/icon/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/icon/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/icon/index.js b/dist/icon/index.js index b31a3003..33810700 100644 --- a/dist/icon/index.js +++ b/dist/icon/index.js @@ -1,19 +1,19 @@ import { VantComponent } from '../common/component'; VantComponent({ - props: { - info: null, - name: String, - size: String, - color: String, - customStyle: String, - classPrefix: { - type: String, - value: 'van-icon' + props: { + info: null, + name: String, + size: String, + color: String, + customStyle: String, + classPrefix: { + type: String, + value: 'van-icon' + } + }, + methods: { + onClick() { + this.$emit('click'); + } } - }, - methods: { - onClick: function onClick() { - this.$emit('click'); - } - } -}); \ No newline at end of file +}); diff --git a/dist/icon/index.wxss b/dist/icon/index.wxss index 08f071f9..0e89ac5d 100644 --- a/dist/icon/index.wxss +++ b/dist/icon/index.wxss @@ -1 +1 @@ -@import '../common/index.wxss';@font-face{font-style:normal;font-weight:400;font-family:vant-icon;src:url(https://img.yzcdn.cn/vant/vant-icon-956c55.woff2) format('woff2'),url(https://img.yzcdn.cn/vant/vant-icon-956c55.woff) format('woff'),url(https://img.yzcdn.cn/vant/vant-icon-956c55.ttf) format('truetype')}.van-icon{position:relative;display:inline-block;font:normal normal normal 14px/1 vant-icon;font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased}.van-icon::before{display:inline-block}.van-icon-add-o:before{content:"\F000"}.van-icon-add-square:before{content:"\F001"}.van-icon-add:before{content:"\F002"}.van-icon-after-sale:before{content:"\F003"}.van-icon-aim:before{content:"\F004"}.van-icon-alipay:before{content:"\F005"}.van-icon-apps-o:before{content:"\F006"}.van-icon-arrow-down:before{content:"\F007"}.van-icon-arrow-left:before{content:"\F008"}.van-icon-arrow-up:before{content:"\F009"}.van-icon-arrow:before{content:"\F00A"}.van-icon-ascending:before{content:"\F00B"}.van-icon-audio:before{content:"\F00C"}.van-icon-award-o:before{content:"\F00D"}.van-icon-award:before{content:"\F00E"}.van-icon-bag-o:before{content:"\F00F"}.van-icon-bag:before{content:"\F010"}.van-icon-balance-list-o:before{content:"\F011"}.van-icon-balance-list:before{content:"\F012"}.van-icon-balance-o:before{content:"\F013"}.van-icon-balance-pay:before{content:"\F014"}.van-icon-bar-chart-o:before{content:"\F015"}.van-icon-bars:before{content:"\F016"}.van-icon-bell:before{content:"\F017"}.van-icon-bill-o:before{content:"\F018"}.van-icon-bill:before{content:"\F019"}.van-icon-birthday-cake-o:before{content:"\F01A"}.van-icon-bookmark-o:before{content:"\F01B"}.van-icon-bookmark:before{content:"\F01C"}.van-icon-browsing-history-o:before{content:"\F01D"}.van-icon-browsing-history:before{content:"\F01E"}.van-icon-brush-o:before{content:"\F01F"}.van-icon-bulb-o:before{content:"\F020"}.van-icon-bullhorn-o:before{content:"\F021"}.van-icon-calender-o:before{content:"\F022"}.van-icon-card:before{content:"\F023"}.van-icon-cart-circle-o:before{content:"\F024"}.van-icon-cart-circle:before{content:"\F025"}.van-icon-cart-o:before{content:"\F026"}.van-icon-cart:before{content:"\F027"}.van-icon-cash-back-record:before{content:"\F028"}.van-icon-cash-on-deliver:before{content:"\F029"}.van-icon-cashier-o:before{content:"\F02A"}.van-icon-certificate:before{content:"\F02B"}.van-icon-chart-trending-o:before{content:"\F02C"}.van-icon-chat-o:before{content:"\F02D"}.van-icon-chat:before{content:"\F02E"}.van-icon-checked:before{content:"\F02F"}.van-icon-circle:before{content:"\F030"}.van-icon-clear:before{content:"\F031"}.van-icon-clock-o:before{content:"\F032"}.van-icon-clock:before{content:"\F033"}.van-icon-close:before{content:"\F034"}.van-icon-closed-eye:before{content:"\F035"}.van-icon-cluster-o:before{content:"\F036"}.van-icon-cluster:before{content:"\F037"}.van-icon-column:before{content:"\F038"}.van-icon-comment-circle-o:before{content:"\F039"}.van-icon-comment-o:before{content:"\F03A"}.van-icon-comment:before{content:"\F03B"}.van-icon-completed:before{content:"\F03C"}.van-icon-contact:before{content:"\F03D"}.van-icon-coupon-o:before{content:"\F03E"}.van-icon-coupon:before{content:"\F03F"}.van-icon-credit-pay:before{content:"\F040"}.van-icon-cross:before{content:"\F041"}.van-icon-debit-pay:before{content:"\F042"}.van-icon-delete:before{content:"\F043"}.van-icon-descending:before{content:"\F044"}.van-icon-description:before{content:"\F045"}.van-icon-desktop-o:before{content:"\F046"}.van-icon-diamond-o:before{content:"\F047"}.van-icon-diamond:before{content:"\F048"}.van-icon-discount:before{content:"\F049"}.van-icon-ecard-pay:before{content:"\F04A"}.van-icon-edit:before{content:"\F04B"}.van-icon-ellipsis:before{content:"\F04C"}.van-icon-empty:before{content:"\F04D"}.van-icon-envelop-o:before{content:"\F04E"}.van-icon-exchange:before{content:"\F04F"}.van-icon-expand-o:before{content:"\F050"}.van-icon-expand:before{content:"\F051"}.van-icon-eye-o:before{content:"\F052"}.van-icon-eye:before{content:"\F053"}.van-icon-fail:before{content:"\F054"}.van-icon-failure:before{content:"\F055"}.van-icon-filter-o:before{content:"\F056"}.van-icon-fire-o:before{content:"\F057"}.van-icon-fire:before{content:"\F058"}.van-icon-flag-o:before{content:"\F059"}.van-icon-flower-o:before{content:"\F05A"}.van-icon-free-postage:before{content:"\F05B"}.van-icon-friends-o:before{content:"\F05C"}.van-icon-friends:before{content:"\F05D"}.van-icon-gem-o:before{content:"\F05E"}.van-icon-gem:before{content:"\F05F"}.van-icon-gift-card-o:before{content:"\F060"}.van-icon-gift-card:before{content:"\F061"}.van-icon-gift-o:before{content:"\F062"}.van-icon-gift:before{content:"\F063"}.van-icon-gold-coin-o:before{content:"\F064"}.van-icon-gold-coin:before{content:"\F065"}.van-icon-goods-collect-o:before{content:"\F066"}.van-icon-goods-collect:before{content:"\F067"}.van-icon-graphic:before{content:"\F068"}.van-icon-home-o:before{content:"\F069"}.van-icon-hot-o:before{content:"\F06A"}.van-icon-hot-sale-o:before{content:"\F06B"}.van-icon-hot-sale:before{content:"\F06C"}.van-icon-hot:before{content:"\F06D"}.van-icon-hotel-o:before{content:"\F06E"}.van-icon-idcard:before{content:"\F06F"}.van-icon-info-o:before{content:"\F070"}.van-icon-info:before{content:"\F071"}.van-icon-invition:before{content:"\F072"}.van-icon-label-o:before{content:"\F073"}.van-icon-label:before{content:"\F074"}.van-icon-like-o:before{content:"\F075"}.van-icon-like:before{content:"\F076"}.van-icon-live:before{content:"\F077"}.van-icon-location-o:before{content:"\F078"}.van-icon-location:before{content:"\F079"}.van-icon-lock:before{content:"\F07A"}.van-icon-logistics:before{content:"\F07B"}.van-icon-manager-o:before{content:"\F07C"}.van-icon-manager:before{content:"\F07D"}.van-icon-map-marked:before{content:"\F07E"}.van-icon-medel-o:before{content:"\F07F"}.van-icon-medel:before{content:"\F080"}.van-icon-more-o:before{content:"\F081"}.van-icon-more:before{content:"\F082"}.van-icon-music-o:before{content:"\F083"}.van-icon-new-arrival-o:before{content:"\F084"}.van-icon-new-arrival:before{content:"\F085"}.van-icon-new-o:before{content:"\F086"}.van-icon-new:before{content:"\F087"}.van-icon-newspaper-o:before{content:"\F088"}.van-icon-notes-o:before{content:"\F089"}.van-icon-orders-o:before{content:"\F08A"}.van-icon-other-pay:before{content:"\F08B"}.van-icon-paid:before{content:"\F08C"}.van-icon-passed:before{content:"\F08D"}.van-icon-pause-circle-o:before{content:"\F08E"}.van-icon-pause-circle:before{content:"\F08F"}.van-icon-pause:before{content:"\F090"}.van-icon-peer-pay:before{content:"\F091"}.van-icon-pending-payment:before{content:"\F092"}.van-icon-phone-circle-o:before{content:"\F093"}.van-icon-phone-o:before{content:"\F094"}.van-icon-phone:before{content:"\F095"}.van-icon-photo-o:before{content:"\F096"}.van-icon-photo:before{content:"\F097"}.van-icon-photograph:before{content:"\F098"}.van-icon-play-circle-o:before{content:"\F099"}.van-icon-play-circle:before{content:"\F09A"}.van-icon-play:before{content:"\F09B"}.van-icon-plus:before{content:"\F09C"}.van-icon-point-gift-o:before{content:"\F09D"}.van-icon-point-gift:before{content:"\F09E"}.van-icon-points:before{content:"\F09F"}.van-icon-printer:before{content:"\F0A0"}.van-icon-qr-invalid:before{content:"\F0A1"}.van-icon-qr:before{content:"\F0A2"}.van-icon-question-o:before{content:"\F0A3"}.van-icon-question:before{content:"\F0A4"}.van-icon-records:before{content:"\F0A5"}.van-icon-refund-o:before{content:"\F0A6"}.van-icon-replay:before{content:"\F0A7"}.van-icon-scan:before{content:"\F0A8"}.van-icon-search:before{content:"\F0A9"}.van-icon-send-gift-o:before{content:"\F0AA"}.van-icon-send-gift:before{content:"\F0AB"}.van-icon-service-o:before{content:"\F0AC"}.van-icon-service:before{content:"\F0AD"}.van-icon-setting-o:before{content:"\F0AE"}.van-icon-setting:before{content:"\F0AF"}.van-icon-share:before{content:"\F0B0"}.van-icon-shop-collect-o:before{content:"\F0B1"}.van-icon-shop-collect:before{content:"\F0B2"}.van-icon-shop-o:before{content:"\F0B3"}.van-icon-shop:before{content:"\F0B4"}.van-icon-shopping-cart-o:before{content:"\F0B5"}.van-icon-shopping-cart:before{content:"\F0B6"}.van-icon-shrink:before{content:"\F0B7"}.van-icon-sign:before{content:"\F0B8"}.van-icon-smile-comment-o:before{content:"\F0B9"}.van-icon-smile-comment:before{content:"\F0BA"}.van-icon-smile-o:before{content:"\F0BB"}.van-icon-star-o:before{content:"\F0BC"}.van-icon-star:before{content:"\F0BD"}.van-icon-stop-circle-o:before{content:"\F0BE"}.van-icon-stop-circle:before{content:"\F0BF"}.van-icon-stop:before{content:"\F0C0"}.van-icon-success:before{content:"\F0C1"}.van-icon-thumb-circle-o:before{content:"\F0C2"}.van-icon-todo-list-o:before{content:"\F0C3"}.van-icon-todo-list:before{content:"\F0C4"}.van-icon-tosend:before{content:"\F0C5"}.van-icon-tv-o:before{content:"\F0C6"}.van-icon-umbrella-circle:before{content:"\F0C7"}.van-icon-underway-o:before{content:"\F0C8"}.van-icon-underway:before{content:"\F0C9"}.van-icon-upgrade:before{content:"\F0CA"}.van-icon-user-circle-o:before{content:"\F0CB"}.van-icon-user-o:before{content:"\F0CC"}.van-icon-video-o:before{content:"\F0CD"}.van-icon-video:before{content:"\F0CE"}.van-icon-vip-card-o:before{content:"\F0CF"}.van-icon-vip-card:before{content:"\F0D0"}.van-icon-volume-o:before{content:"\F0D1"}.van-icon-volume:before{content:"\F0D2"}.van-icon-wap-home:before{content:"\F0D3"}.van-icon-wap-nav:before{content:"\F0D4"}.van-icon-warn-o:before{content:"\F0D5"}.van-icon-warning-o:before{content:"\F0D6"}.van-icon-weapp-nav:before{content:"\F0D7"}.van-icon-wechat:before{content:"\F0D8"}.van-icon-youzan-shield:before{content:"\F0D9"}.van-icon--image{width:1em;height:1em}.van-icon--image image{top:0;left:0;right:0;bottom:0;margin:auto;max-width:100%;max-height:100%;position:absolute} \ No newline at end of file +@import '../common/index.wxss';@font-face{font-style:normal;font-weight:400;font-family:vant-icon;src:url(https://img.yzcdn.cn/vant/vant-icon-c13a1e.woff2) format('woff2'),url(https://img.yzcdn.cn/vant/vant-icon-c13a1e.woff) format('woff'),url(https://img.yzcdn.cn/vant/vant-icon-c13a1e.ttf) format('truetype')}.van-icon{position:relative;display:inline-block;font:normal normal normal 14px/1 vant-icon;font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased}.van-icon::before{display:inline-block}.van-icon-add-o:before{content:"\F000"}.van-icon-add-square:before{content:"\F001"}.van-icon-add:before{content:"\F002"}.van-icon-after-sale:before{content:"\F003"}.van-icon-aim:before{content:"\F004"}.van-icon-alipay:before{content:"\F005"}.van-icon-apps-o:before{content:"\F006"}.van-icon-arrow-down:before{content:"\F007"}.van-icon-arrow-left:before{content:"\F008"}.van-icon-arrow-up:before{content:"\F009"}.van-icon-arrow:before{content:"\F00A"}.van-icon-ascending:before{content:"\F00B"}.van-icon-audio:before{content:"\F00C"}.van-icon-award-o:before{content:"\F00D"}.van-icon-award:before{content:"\F00E"}.van-icon-bag-o:before{content:"\F00F"}.van-icon-bag:before{content:"\F010"}.van-icon-balance-list-o:before{content:"\F011"}.van-icon-balance-list:before{content:"\F012"}.van-icon-balance-o:before{content:"\F013"}.van-icon-balance-pay:before{content:"\F014"}.van-icon-bar-chart-o:before{content:"\F015"}.van-icon-bars:before{content:"\F016"}.van-icon-bell:before{content:"\F017"}.van-icon-bill-o:before{content:"\F018"}.van-icon-bill:before{content:"\F019"}.van-icon-birthday-cake-o:before{content:"\F01A"}.van-icon-bookmark-o:before{content:"\F01B"}.van-icon-bookmark:before{content:"\F01C"}.van-icon-browsing-history-o:before{content:"\F01D"}.van-icon-browsing-history:before{content:"\F01E"}.van-icon-brush-o:before{content:"\F01F"}.van-icon-bulb-o:before{content:"\F020"}.van-icon-bullhorn-o:before{content:"\F021"}.van-icon-calender-o:before{content:"\F022"}.van-icon-card:before{content:"\F023"}.van-icon-cart-circle-o:before{content:"\F024"}.van-icon-cart-circle:before{content:"\F025"}.van-icon-cart-o:before{content:"\F026"}.van-icon-cart:before{content:"\F027"}.van-icon-cash-back-record:before{content:"\F028"}.van-icon-cash-on-deliver:before{content:"\F029"}.van-icon-cashier-o:before{content:"\F02A"}.van-icon-certificate:before{content:"\F02B"}.van-icon-chart-trending-o:before{content:"\F02C"}.van-icon-chat-o:before{content:"\F02D"}.van-icon-chat:before{content:"\F02E"}.van-icon-checked:before{content:"\F02F"}.van-icon-circle:before{content:"\F030"}.van-icon-clear:before{content:"\F031"}.van-icon-clock-o:before{content:"\F032"}.van-icon-clock:before{content:"\F033"}.van-icon-close:before{content:"\F034"}.van-icon-closed-eye:before{content:"\F035"}.van-icon-cluster-o:before{content:"\F036"}.van-icon-cluster:before{content:"\F037"}.van-icon-column:before{content:"\F038"}.van-icon-comment-circle-o:before{content:"\F039"}.van-icon-comment-o:before{content:"\F03A"}.van-icon-comment:before{content:"\F03B"}.van-icon-completed:before{content:"\F03C"}.van-icon-contact:before{content:"\F03D"}.van-icon-coupon-o:before{content:"\F03E"}.van-icon-coupon:before{content:"\F03F"}.van-icon-credit-pay:before{content:"\F040"}.van-icon-cross:before{content:"\F041"}.van-icon-debit-pay:before{content:"\F042"}.van-icon-delete:before{content:"\F043"}.van-icon-descending:before{content:"\F044"}.van-icon-description:before{content:"\F045"}.van-icon-desktop-o:before{content:"\F046"}.van-icon-diamond-o:before{content:"\F047"}.van-icon-diamond:before{content:"\F048"}.van-icon-discount:before{content:"\F049"}.van-icon-ecard-pay:before{content:"\F04A"}.van-icon-edit:before{content:"\F04B"}.van-icon-ellipsis:before{content:"\F04C"}.van-icon-empty:before{content:"\F04D"}.van-icon-envelop-o:before{content:"\F04E"}.van-icon-exchange:before{content:"\F04F"}.van-icon-expand-o:before{content:"\F050"}.van-icon-expand:before{content:"\F051"}.van-icon-eye-o:before{content:"\F052"}.van-icon-eye:before{content:"\F053"}.van-icon-fail:before{content:"\F054"}.van-icon-failure:before{content:"\F055"}.van-icon-filter-o:before{content:"\F056"}.van-icon-fire-o:before{content:"\F057"}.van-icon-fire:before{content:"\F058"}.van-icon-flag-o:before{content:"\F059"}.van-icon-flower-o:before{content:"\F05A"}.van-icon-free-postage:before{content:"\F05B"}.van-icon-friends-o:before{content:"\F05C"}.van-icon-friends:before{content:"\F05D"}.van-icon-gem-o:before{content:"\F05E"}.van-icon-gem:before{content:"\F05F"}.van-icon-gift-card-o:before{content:"\F060"}.van-icon-gift-card:before{content:"\F061"}.van-icon-gift-o:before{content:"\F062"}.van-icon-gift:before{content:"\F063"}.van-icon-gold-coin-o:before{content:"\F064"}.van-icon-gold-coin:before{content:"\F065"}.van-icon-goods-collect-o:before{content:"\F066"}.van-icon-goods-collect:before{content:"\F067"}.van-icon-graphic:before{content:"\F068"}.van-icon-home-o:before{content:"\F069"}.van-icon-hot-o:before{content:"\F06A"}.van-icon-hot-sale-o:before{content:"\F06B"}.van-icon-hot-sale:before{content:"\F06C"}.van-icon-hot:before{content:"\F06D"}.van-icon-hotel-o:before{content:"\F06E"}.van-icon-idcard:before{content:"\F06F"}.van-icon-info-o:before{content:"\F070"}.van-icon-info:before{content:"\F071"}.van-icon-invition:before{content:"\F072"}.van-icon-label-o:before{content:"\F073"}.van-icon-label:before{content:"\F074"}.van-icon-like-o:before{content:"\F075"}.van-icon-like:before{content:"\F076"}.van-icon-live:before{content:"\F077"}.van-icon-location-o:before{content:"\F078"}.van-icon-location:before{content:"\F079"}.van-icon-lock:before{content:"\F07A"}.van-icon-logistics:before{content:"\F07B"}.van-icon-manager-o:before{content:"\F07C"}.van-icon-manager:before{content:"\F07D"}.van-icon-map-marked:before{content:"\F07E"}.van-icon-medel-o:before{content:"\F07F"}.van-icon-medel:before{content:"\F080"}.van-icon-more-o:before{content:"\F081"}.van-icon-more:before{content:"\F082"}.van-icon-music-o:before{content:"\F083"}.van-icon-new-arrival-o:before{content:"\F084"}.van-icon-new-arrival:before{content:"\F085"}.van-icon-new-o:before{content:"\F086"}.van-icon-new:before{content:"\F087"}.van-icon-newspaper-o:before{content:"\F088"}.van-icon-notes-o:before{content:"\F089"}.van-icon-orders-o:before{content:"\F08A"}.van-icon-other-pay:before{content:"\F08B"}.van-icon-paid:before{content:"\F08C"}.van-icon-passed:before{content:"\F08D"}.van-icon-pause-circle-o:before{content:"\F08E"}.van-icon-pause-circle:before{content:"\F08F"}.van-icon-pause:before{content:"\F090"}.van-icon-peer-pay:before{content:"\F091"}.van-icon-pending-payment:before{content:"\F092"}.van-icon-phone-circle-o:before{content:"\F093"}.van-icon-phone-o:before{content:"\F094"}.van-icon-phone:before{content:"\F095"}.van-icon-photo-o:before{content:"\F096"}.van-icon-photo:before{content:"\F097"}.van-icon-photograph:before{content:"\F098"}.van-icon-play-circle-o:before{content:"\F099"}.van-icon-play-circle:before{content:"\F09A"}.van-icon-play:before{content:"\F09B"}.van-icon-plus:before{content:"\F09C"}.van-icon-point-gift-o:before{content:"\F09D"}.van-icon-point-gift:before{content:"\F09E"}.van-icon-points:before{content:"\F09F"}.van-icon-printer:before{content:"\F0A0"}.van-icon-qr-invalid:before{content:"\F0A1"}.van-icon-qr:before{content:"\F0A2"}.van-icon-question-o:before{content:"\F0A3"}.van-icon-question:before{content:"\F0A4"}.van-icon-records:before{content:"\F0A5"}.van-icon-refund-o:before{content:"\F0A6"}.van-icon-replay:before{content:"\F0A7"}.van-icon-scan:before{content:"\F0A8"}.van-icon-search:before{content:"\F0A9"}.van-icon-send-gift-o:before{content:"\F0AA"}.van-icon-send-gift:before{content:"\F0AB"}.van-icon-service-o:before{content:"\F0AC"}.van-icon-service:before{content:"\F0AD"}.van-icon-setting-o:before{content:"\F0AE"}.van-icon-setting:before{content:"\F0AF"}.van-icon-share:before{content:"\F0B0"}.van-icon-shop-collect-o:before{content:"\F0B1"}.van-icon-shop-collect:before{content:"\F0B2"}.van-icon-shop-o:before{content:"\F0B3"}.van-icon-shop:before{content:"\F0B4"}.van-icon-shopping-cart-o:before{content:"\F0B5"}.van-icon-shopping-cart:before{content:"\F0B6"}.van-icon-shrink:before{content:"\F0B7"}.van-icon-sign:before{content:"\F0B8"}.van-icon-smile-comment-o:before{content:"\F0B9"}.van-icon-smile-comment:before{content:"\F0BA"}.van-icon-smile-o:before{content:"\F0BB"}.van-icon-star-o:before{content:"\F0BC"}.van-icon-star:before{content:"\F0BD"}.van-icon-stop-circle-o:before{content:"\F0BE"}.van-icon-stop-circle:before{content:"\F0BF"}.van-icon-stop:before{content:"\F0C0"}.van-icon-success:before{content:"\F0C1"}.van-icon-thumb-circle-o:before{content:"\F0C2"}.van-icon-todo-list-o:before{content:"\F0C3"}.van-icon-todo-list:before{content:"\F0C4"}.van-icon-tosend:before{content:"\F0C5"}.van-icon-tv-o:before{content:"\F0C6"}.van-icon-umbrella-circle:before{content:"\F0C7"}.van-icon-underway-o:before{content:"\F0C8"}.van-icon-underway:before{content:"\F0C9"}.van-icon-upgrade:before{content:"\F0CA"}.van-icon-user-circle-o:before{content:"\F0CB"}.van-icon-user-o:before{content:"\F0CC"}.van-icon-video-o:before{content:"\F0CD"}.van-icon-video:before{content:"\F0CE"}.van-icon-vip-card-o:before{content:"\F0CF"}.van-icon-vip-card:before{content:"\F0D0"}.van-icon-volume-o:before{content:"\F0D1"}.van-icon-volume:before{content:"\F0D2"}.van-icon-wap-home:before{content:"\F0D3"}.van-icon-wap-nav:before{content:"\F0D4"}.van-icon-warn-o:before{content:"\F0D5"}.van-icon-warning-o:before{content:"\F0D6"}.van-icon-weapp-nav:before{content:"\F0D7"}.van-icon-wechat:before{content:"\F0D8"}.van-icon-youzan-shield:before{content:"\F0D9"}.van-icon--image{width:1em;height:1em}.van-icon--image image{top:0;left:0;right:0;bottom:0;margin:auto;max-width:100%;max-height:100%;position:absolute} \ No newline at end of file diff --git a/dist/info/index.d.ts b/dist/info/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/info/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/info/index.js b/dist/info/index.js index 1357bbf1..b7258be9 100644 --- a/dist/info/index.js +++ b/dist/info/index.js @@ -1,7 +1,7 @@ import { VantComponent } from '../common/component'; VantComponent({ - props: { - info: null, - customStyle: String - } -}); \ No newline at end of file + props: { + info: null, + customStyle: String + } +}); diff --git a/dist/loading/index.d.ts b/dist/loading/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/loading/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/loading/index.js b/dist/loading/index.js index edb8360c..942b7a42 100644 --- a/dist/loading/index.js +++ b/dist/loading/index.js @@ -1,17 +1,17 @@ import { VantComponent } from '../common/component'; VantComponent({ - props: { - size: { - type: String, - value: '30px' - }, - type: { - type: String, - value: 'circular' - }, - color: { - type: String, - value: '#c9c9c9' + props: { + size: { + type: String, + value: '30px' + }, + type: { + type: String, + value: 'circular' + }, + color: { + type: String, + value: '#c9c9c9' + } } - } -}); \ No newline at end of file +}); diff --git a/dist/mixins/basic.d.ts b/dist/mixins/basic.d.ts new file mode 100644 index 00000000..49361d32 --- /dev/null +++ b/dist/mixins/basic.d.ts @@ -0,0 +1 @@ +export declare const basic: void; diff --git a/dist/mixins/basic.js b/dist/mixins/basic.js index db7087e5..09b0dcfa 100644 --- a/dist/mixins/basic.js +++ b/dist/mixins/basic.js @@ -1,22 +1,22 @@ -export var basic = Behavior({ - methods: { - $emit: function $emit() { - this.triggerEvent.apply(this, arguments); - }, - getRect: function getRect(selector, all) { - var _this = this; - - return new Promise(function (resolve) { - wx.createSelectorQuery().in(_this)[all ? 'selectAll' : 'select'](selector).boundingClientRect(function (rect) { - if (all && Array.isArray(rect) && rect.length) { - resolve(rect); - } - - if (!all && rect) { - resolve(rect); - } - }).exec(); - }); +export const basic = Behavior({ + methods: { + $emit() { + this.triggerEvent.apply(this, arguments); + }, + getRect(selector, all) { + return new Promise(resolve => { + wx.createSelectorQuery() + .in(this)[all ? 'selectAll' : 'select'](selector) + .boundingClientRect(rect => { + if (all && Array.isArray(rect) && rect.length) { + resolve(rect); + } + if (!all && rect) { + resolve(rect); + } + }) + .exec(); + }); + } } - } -}); \ No newline at end of file +}); diff --git a/dist/mixins/button.d.ts b/dist/mixins/button.d.ts new file mode 100644 index 00000000..6e716c59 --- /dev/null +++ b/dist/mixins/button.d.ts @@ -0,0 +1 @@ +export declare const button: void; diff --git a/dist/mixins/button.js b/dist/mixins/button.js index 592734d6..5d3b4dc4 100644 --- a/dist/mixins/button.js +++ b/dist/mixins/button.js @@ -1,18 +1,18 @@ -export var button = Behavior({ - externalClasses: ['hover-class'], - properties: { - id: String, - lang: { - type: String, - value: 'en' - }, - businessId: Number, - sessionFrom: String, - sendMessageTitle: String, - sendMessagePath: String, - sendMessageImg: String, - showMessageCard: Boolean, - appParameter: String, - ariaLabel: String - } -}); \ No newline at end of file +export const button = Behavior({ + externalClasses: ['hover-class'], + properties: { + id: String, + lang: { + type: String, + value: 'en' + }, + businessId: Number, + sessionFrom: String, + sendMessageTitle: String, + sendMessagePath: String, + sendMessageImg: String, + showMessageCard: Boolean, + appParameter: String, + ariaLabel: String + } +}); diff --git a/dist/mixins/iphonex.d.ts b/dist/mixins/iphonex.d.ts new file mode 100644 index 00000000..67081dbd --- /dev/null +++ b/dist/mixins/iphonex.d.ts @@ -0,0 +1 @@ +export declare const iphonex: void; diff --git a/dist/mixins/iphonex.js b/dist/mixins/iphonex.js index e33fb52b..f2885f4c 100644 --- a/dist/mixins/iphonex.js +++ b/dist/mixins/iphonex.js @@ -1,39 +1,32 @@ -var isIPhoneX = null; - +let isIPhoneX = null; function getIsIPhoneX() { - return new Promise(function (resolve, reject) { - if (isIPhoneX !== null) { - resolve(isIPhoneX); - } else { - wx.getSystemInfo({ - success: function success(_ref) { - var model = _ref.model, - screenHeight = _ref.screenHeight; - var iphoneX = /iphone x/i.test(model); - var iphoneNew = /iPhone11/i.test(model) && screenHeight === 812; - isIPhoneX = iphoneX || iphoneNew; - resolve(isIPhoneX); - }, - fail: reject - }); - } - }); -} - -export var iphonex = Behavior({ - properties: { - safeAreaInsetBottom: { - type: Boolean, - value: true - } - }, - created: function created() { - var _this = this; - - getIsIPhoneX().then(function (isIPhoneX) { - _this.set({ - isIPhoneX: isIPhoneX - }); + return new Promise((resolve, reject) => { + if (isIPhoneX !== null) { + resolve(isIPhoneX); + } + else { + wx.getSystemInfo({ + success: ({ model, screenHeight }) => { + const iphoneX = /iphone x/i.test(model); + const iphoneNew = /iPhone11/i.test(model) && screenHeight === 812; + isIPhoneX = iphoneX || iphoneNew; + resolve(isIPhoneX); + }, + fail: reject + }); + } }); - } -}); \ No newline at end of file +} +export const iphonex = Behavior({ + properties: { + safeAreaInsetBottom: { + type: Boolean, + value: true + } + }, + created() { + getIsIPhoneX().then(isIPhoneX => { + this.set({ isIPhoneX }); + }); + } +}); diff --git a/dist/mixins/link.d.ts b/dist/mixins/link.d.ts new file mode 100644 index 00000000..ac14a719 --- /dev/null +++ b/dist/mixins/link.d.ts @@ -0,0 +1 @@ +export declare const link: void; diff --git a/dist/mixins/link.js b/dist/mixins/link.js index 63a120ab..d7aed0c9 100644 --- a/dist/mixins/link.js +++ b/dist/mixins/link.js @@ -1,24 +1,17 @@ -export var link = Behavior({ - properties: { - url: String, - linkType: { - type: String, - value: 'navigateTo' +export const link = Behavior({ + properties: { + url: String, + linkType: { + type: String, + value: 'navigateTo' + } + }, + methods: { + jumpLink(urlKey = 'url') { + const url = this.data[urlKey]; + if (url) { + wx[this.data.linkType]({ url }); + } + } } - }, - methods: { - jumpLink: function jumpLink(urlKey) { - if (urlKey === void 0) { - urlKey = 'url'; - } - - var url = this.data[urlKey]; - - if (url) { - wx[this.data.linkType]({ - url: url - }); - } - } - } -}); \ No newline at end of file +}); diff --git a/dist/mixins/observer/behavior.d.ts b/dist/mixins/observer/behavior.d.ts new file mode 100644 index 00000000..9245688e --- /dev/null +++ b/dist/mixins/observer/behavior.d.ts @@ -0,0 +1 @@ +export declare const behavior: void; diff --git a/dist/mixins/observer/behavior.js b/dist/mixins/observer/behavior.js index c4830475..794bc53a 100644 --- a/dist/mixins/observer/behavior.js +++ b/dist/mixins/observer/behavior.js @@ -1,62 +1,47 @@ function setAsync(context, data) { - return new Promise(function (resolve) { - context.setData(data, resolve); - }); + return new Promise(resolve => { + context.setData(data, resolve); + }); } - ; -export var behavior = Behavior({ - created: function created() { - var _this = this; - - if (!this.$options) { - return; - } - - var cache = {}; - - var _this$$options = this.$options(), - computed = _this$$options.computed; - - var keys = Object.keys(computed); - - this.calcComputed = function () { - var needUpdate = {}; - keys.forEach(function (key) { - var value = computed[key].call(_this); - - if (cache[key] !== value) { - cache[key] = needUpdate[key] = value; +export const behavior = Behavior({ + created() { + if (!this.$options) { + return; } - }); - return needUpdate; - }; - }, - attached: function attached() { - this.set(); - }, - methods: { - // set data and set computed data - set: function set(data, callback) { - var _this2 = this; - - var stack = []; - - if (data) { - stack.push(setAsync(this, data)); - } - - if (this.calcComputed) { - stack.push(setAsync(this, this.calcComputed())); - } - - return Promise.all(stack).then(function (res) { - if (callback && typeof callback === 'function') { - callback.call(_this2); + const cache = {}; + const { computed } = this.$options(); + const keys = Object.keys(computed); + this.calcComputed = () => { + const needUpdate = {}; + keys.forEach(key => { + const value = computed[key].call(this); + if (cache[key] !== value) { + cache[key] = needUpdate[key] = value; + } + }); + return needUpdate; + }; + }, + attached() { + this.set(); + }, + methods: { + // set data and set computed data + set(data, callback) { + const stack = []; + if (data) { + stack.push(setAsync(this, data)); + } + if (this.calcComputed) { + stack.push(setAsync(this, this.calcComputed())); + } + return Promise.all(stack).then(res => { + if (callback && typeof callback === 'function') { + callback.call(this); + } + return res; + }); } - - return res; - }); } - } -}); \ No newline at end of file +}); diff --git a/dist/mixins/observer/index.d.ts b/dist/mixins/observer/index.d.ts new file mode 100644 index 00000000..4e54b2e5 --- /dev/null +++ b/dist/mixins/observer/index.d.ts @@ -0,0 +1 @@ +export declare function observe(vantOptions: any, options: any): void; diff --git a/dist/mixins/observer/index.js b/dist/mixins/observer/index.js index c878fd09..51427f7f 100644 --- a/dist/mixins/observer/index.js +++ b/dist/mixins/observer/index.js @@ -1,38 +1,27 @@ import { behavior } from './behavior'; import { observeProps } from './props'; export function observe(vantOptions, options) { - var watch = vantOptions.watch, - computed = vantOptions.computed; - options.behaviors.push(behavior); - - if (watch) { - var props = options.properties || {}; - Object.keys(watch).forEach(function (key) { - if (key in props) { - var prop = props[key]; - - if (prop === null || !('type' in prop)) { - prop = { - type: prop - }; - } - - prop.observer = watch[key]; - props[key] = prop; - } - }); - options.properties = props; - } - - if (computed) { - options.methods = options.methods || {}; - - options.methods.$options = function () { - return vantOptions; - }; - - if (options.properties) { - observeProps(options.properties); + const { watch, computed } = vantOptions; + options.behaviors.push(behavior); + if (watch) { + const props = options.properties || {}; + Object.keys(watch).forEach(key => { + if (key in props) { + let prop = props[key]; + if (prop === null || !('type' in prop)) { + prop = { type: prop }; + } + prop.observer = watch[key]; + props[key] = prop; + } + }); + options.properties = props; } - } -} \ No newline at end of file + if (computed) { + options.methods = options.methods || {}; + options.methods.$options = () => vantOptions; + if (options.properties) { + observeProps(options.properties); + } + } +} diff --git a/dist/mixins/observer/props.d.ts b/dist/mixins/observer/props.d.ts new file mode 100644 index 00000000..43813df4 --- /dev/null +++ b/dist/mixins/observer/props.d.ts @@ -0,0 +1 @@ +export declare function observeProps(props: any): void; diff --git a/dist/mixins/observer/props.js b/dist/mixins/observer/props.js index 57706daf..c77aa79a 100644 --- a/dist/mixins/observer/props.js +++ b/dist/mixins/observer/props.js @@ -1,32 +1,22 @@ export function observeProps(props) { - if (!props) { - return; - } - - Object.keys(props).forEach(function (key) { - var prop = props[key]; - - if (prop === null || !('type' in prop)) { - prop = { - type: prop - }; + if (!props) { + return; } - - var _prop = prop, - observer = _prop.observer; - - prop.observer = function () { - if (observer) { - if (typeof observer === 'string') { - observer = this[observer]; + Object.keys(props).forEach(key => { + let prop = props[key]; + if (prop === null || !('type' in prop)) { + prop = { type: prop }; } - - observer.apply(this, arguments); - } - - this.set(); - }; - - props[key] = prop; - }); -} \ No newline at end of file + let { observer } = prop; + prop.observer = function () { + if (observer) { + if (typeof observer === 'string') { + observer = this[observer]; + } + observer.apply(this, arguments); + } + this.set(); + }; + props[key] = prop; + }); +} diff --git a/dist/mixins/open-type.d.ts b/dist/mixins/open-type.d.ts new file mode 100644 index 00000000..1a543ff4 --- /dev/null +++ b/dist/mixins/open-type.d.ts @@ -0,0 +1 @@ +export declare const openType: void; diff --git a/dist/mixins/open-type.js b/dist/mixins/open-type.js index df6b372f..514517e0 100644 --- a/dist/mixins/open-type.js +++ b/dist/mixins/open-type.js @@ -1,25 +1,25 @@ -export var openType = Behavior({ - properties: { - openType: String - }, - methods: { - bindGetUserInfo: function bindGetUserInfo(event) { - this.$emit('getuserinfo', event.detail); +export const openType = Behavior({ + properties: { + openType: String }, - bindContact: function bindContact(event) { - this.$emit('contact', event.detail); - }, - bindGetPhoneNumber: function bindGetPhoneNumber(event) { - this.$emit('getphonenumber', event.detail); - }, - bindError: function bindError(event) { - this.$emit('error', event.detail); - }, - bindLaunchApp: function bindLaunchApp(event) { - this.$emit('launchapp', event.detail); - }, - bindOpenSetting: function bindOpenSetting(event) { - this.$emit('opensetting', event.detail); + methods: { + bindGetUserInfo(event) { + this.$emit('getuserinfo', event.detail); + }, + bindContact(event) { + this.$emit('contact', event.detail); + }, + bindGetPhoneNumber(event) { + this.$emit('getphonenumber', event.detail); + }, + bindError(event) { + this.$emit('error', event.detail); + }, + bindLaunchApp(event) { + this.$emit('launchapp', event.detail); + }, + bindOpenSetting(event) { + this.$emit('opensetting', event.detail); + }, } - } -}); \ No newline at end of file +}); diff --git a/dist/mixins/touch.d.ts b/dist/mixins/touch.d.ts new file mode 100644 index 00000000..a4417a31 --- /dev/null +++ b/dist/mixins/touch.d.ts @@ -0,0 +1 @@ +export declare const touch: void; diff --git a/dist/mixins/touch.js b/dist/mixins/touch.js index c31559bb..5efa9dda 100644 --- a/dist/mixins/touch.js +++ b/dist/mixins/touch.js @@ -1,21 +1,21 @@ -export var touch = Behavior({ - methods: { - touchStart: function touchStart(event) { - this.direction = ''; - this.deltaX = 0; - this.deltaY = 0; - this.offsetX = 0; - this.offsetY = 0; - this.startX = event.touches[0].clientX; - this.startY = event.touches[0].clientY; - }, - touchMove: function touchMove(event) { - var touch = event.touches[0]; - this.deltaX = touch.clientX - this.startX; - this.deltaY = touch.clientY - this.startY; - this.offsetX = Math.abs(this.deltaX); - this.offsetY = Math.abs(this.deltaY); - this.direction = this.offsetX > this.offsetY ? 'horizontal' : this.offsetX < this.offsetY ? 'vertical' : ''; +export const touch = Behavior({ + methods: { + touchStart(event) { + this.direction = ''; + this.deltaX = 0; + this.deltaY = 0; + this.offsetX = 0; + this.offsetY = 0; + this.startX = event.touches[0].clientX; + this.startY = event.touches[0].clientY; + }, + touchMove(event) { + const touch = event.touches[0]; + this.deltaX = touch.clientX - this.startX; + this.deltaY = touch.clientY - this.startY; + this.offsetX = Math.abs(this.deltaX); + this.offsetY = Math.abs(this.deltaY); + this.direction = this.offsetX > this.offsetY ? 'horizontal' : this.offsetX < this.offsetY ? 'vertical' : ''; + } } - } -}); \ No newline at end of file +}); diff --git a/dist/mixins/transition.d.ts b/dist/mixins/transition.d.ts new file mode 100644 index 00000000..24765ea1 --- /dev/null +++ b/dist/mixins/transition.d.ts @@ -0,0 +1 @@ +export declare const transition: (showDefaultValue: boolean) => void; diff --git a/dist/mixins/transition.js b/dist/mixins/transition.js index a3d9d180..2705752d 100644 --- a/dist/mixins/transition.js +++ b/dist/mixins/transition.js @@ -1,105 +1,89 @@ import { isObj } from '../common/utils'; - -var getClassNames = function getClassNames(name) { - return { - enter: "van-" + name + "-enter van-" + name + "-enter-active enter-class enter-active-class", - 'enter-to': "van-" + name + "-enter-to van-" + name + "-enter-active enter-to-class enter-active-class", - leave: "van-" + name + "-leave van-" + name + "-leave-active leave-class leave-active-class", - 'leave-to': "van-" + name + "-leave-to van-" + name + "-leave-active leave-to-class leave-active-class" - }; -}; - -var requestAnimationFrame = function requestAnimationFrame(cb) { - return setTimeout(cb, 1000 / 60); -}; - -export var transition = function transition(showDefaultValue) { - return Behavior({ - properties: { - customStyle: String, - show: { - type: Boolean, - value: showDefaultValue, - observer: 'observeShow' - }, - duration: { - type: [Number, Object], - value: 300, - observer: 'observeDuration' - }, - name: { - type: String, - value: 'fade', - observer: 'updateClasses' - } - }, - data: { - type: '', - inited: false, - display: false, - classNames: getClassNames('fade') - }, - attached: function attached() { - if (this.data.show) { - this.show(); - } - }, - methods: { - observeShow: function observeShow(value) { - if (value) { - this.show(); - } else { - this.leave(); +const getClassNames = (name) => ({ + enter: `van-${name}-enter van-${name}-enter-active enter-class enter-active-class`, + 'enter-to': `van-${name}-enter-to van-${name}-enter-active enter-to-class enter-active-class`, + leave: `van-${name}-leave van-${name}-leave-active leave-class leave-active-class`, + 'leave-to': `van-${name}-leave-to van-${name}-leave-active leave-to-class leave-active-class` +}); +const requestAnimationFrame = (cb) => setTimeout(cb, 1000 / 60); +export const transition = function (showDefaultValue) { + return Behavior({ + properties: { + customStyle: String, + show: { + type: Boolean, + value: showDefaultValue, + observer: 'observeShow' + }, + duration: { + type: [Number, Object], + value: 300, + observer: 'observeDuration' + }, + name: { + type: String, + value: 'fade', + observer: 'updateClasses' + } + }, + data: { + type: '', + inited: false, + display: false, + classNames: getClassNames('fade') + }, + attached() { + if (this.data.show) { + this.show(); + } + }, + methods: { + observeShow(value) { + if (value) { + this.show(); + } + else { + this.leave(); + } + }, + updateClasses(name) { + this.set({ + classNames: getClassNames(name) + }); + }, + show() { + const { classNames, duration } = this.data; + this.set({ + inited: true, + display: true, + classes: classNames.enter, + currentDuration: isObj(duration) ? duration.enter : duration + }).then(() => { + requestAnimationFrame(() => { + this.set({ + classes: classNames['enter-to'] + }); + }); + }); + }, + leave() { + const { classNames, duration } = this.data; + this.set({ + classes: classNames.leave, + currentDuration: isObj(duration) ? duration.leave : duration + }).then(() => { + requestAnimationFrame(() => { + this.set({ + classes: classNames['leave-to'] + }); + }); + }); + }, + onTransitionEnd() { + if (!this.data.show) { + this.set({ display: false }); + } + } } - }, - updateClasses: function updateClasses(name) { - this.set({ - classNames: getClassNames(name) - }); - }, - show: function show() { - var _this = this; - - var _this$data = this.data, - classNames = _this$data.classNames, - duration = _this$data.duration; - this.set({ - inited: true, - display: true, - classes: classNames.enter, - currentDuration: isObj(duration) ? duration.enter : duration - }).then(function () { - requestAnimationFrame(function () { - _this.set({ - classes: classNames['enter-to'] - }); - }); - }); - }, - leave: function leave() { - var _this2 = this; - - var _this$data2 = this.data, - classNames = _this$data2.classNames, - duration = _this$data2.duration; - this.set({ - classes: classNames.leave, - currentDuration: isObj(duration) ? duration.leave : duration - }).then(function () { - requestAnimationFrame(function () { - _this2.set({ - classes: classNames['leave-to'] - }); - }); - }); - }, - onTransitionEnd: function onTransitionEnd() { - if (!this.data.show) { - this.set({ - display: false - }); - } - } - } - }); -}; \ No newline at end of file + }); +}; diff --git a/dist/nav-bar/index.d.ts b/dist/nav-bar/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/nav-bar/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/nav-bar/index.js b/dist/nav-bar/index.js index 8f934adf..39af4886 100644 --- a/dist/nav-bar/index.js +++ b/dist/nav-bar/index.js @@ -1,27 +1,27 @@ import { VantComponent } from '../common/component'; VantComponent({ - classes: ['title-class'], - props: { - title: String, - fixed: Boolean, - leftText: String, - rightText: String, - leftArrow: Boolean, - border: { - type: Boolean, - value: true + classes: ['title-class'], + props: { + title: String, + fixed: Boolean, + leftText: String, + rightText: String, + leftArrow: Boolean, + border: { + type: Boolean, + value: true + }, + zIndex: { + type: Number, + value: 1 + } }, - zIndex: { - type: Number, - value: 1 + methods: { + onClickLeft() { + this.$emit('click-left'); + }, + onClickRight() { + this.$emit('click-right'); + } } - }, - methods: { - onClickLeft: function onClickLeft() { - this.$emit('click-left'); - }, - onClickRight: function onClickRight() { - this.$emit('click-right'); - } - } -}); \ No newline at end of file +}); diff --git a/dist/notice-bar/index.d.ts b/dist/notice-bar/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/notice-bar/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/notice-bar/index.js b/dist/notice-bar/index.js index 0cc3ae8c..a730f172 100644 --- a/dist/notice-bar/index.js +++ b/dist/notice-bar/index.js @@ -1,131 +1,128 @@ import { VantComponent } from '../common/component'; -var FONT_COLOR = '#ed6a0c'; -var BG_COLOR = '#fffbe8'; +const FONT_COLOR = '#ed6a0c'; +const BG_COLOR = '#fffbe8'; VantComponent({ - props: { - text: { - type: String, - value: '' - }, - mode: { - type: String, - value: '' - }, - url: { - type: String, - value: '' - }, - openType: { - type: String, - value: 'navigate' - }, - delay: { - type: Number, - value: 0 - }, - speed: { - type: Number, - value: 50 - }, - scrollable: { - type: Boolean, - value: true - }, - leftIcon: { - type: String, - value: '' - }, - color: { - type: String, - value: FONT_COLOR - }, - backgroundColor: { - type: String, - value: BG_COLOR - } - }, - data: { - show: true, - hasRightIcon: false - }, - watch: { - text: function text() { - this.set({}, this.init); - } - }, - created: function created() { - if (this.data.mode) { - this.set({ - hasRightIcon: true - }); - } - - this.resetAnimation = wx.createAnimation({ - duration: 0, - timingFunction: 'linear' - }); - }, - destroyed: function destroyed() { - this.timer && clearTimeout(this.timer); - }, - methods: { - init: function init() { - var _this = this; - - Promise.all([this.getRect('.van-notice-bar__content'), this.getRect('.van-notice-bar__content-wrap')]).then(function (rects) { - var contentRect = rects[0], - wrapRect = rects[1]; - - if (contentRect == null || wrapRect == null || !contentRect.width || !wrapRect.width) { - return; + props: { + text: { + type: String, + value: '' + }, + mode: { + type: String, + value: '' + }, + url: { + type: String, + value: '' + }, + openType: { + type: String, + value: 'navigate' + }, + delay: { + type: Number, + value: 0 + }, + speed: { + type: Number, + value: 50 + }, + scrollable: { + type: Boolean, + value: true + }, + leftIcon: { + type: String, + value: '' + }, + color: { + type: String, + value: FONT_COLOR + }, + backgroundColor: { + type: String, + value: BG_COLOR } - - var _this$data = _this.data, - speed = _this$data.speed, - scrollable = _this$data.scrollable, - delay = _this$data.delay; - - if (scrollable && wrapRect.width < contentRect.width) { - var duration = contentRect.width / speed * 1000; - _this.wrapWidth = wrapRect.width; - _this.contentWidth = contentRect.width; - _this.duration = duration; - _this.animation = wx.createAnimation({ - duration: duration, - timingFunction: 'linear', - delay: delay - }); - - _this.scroll(); - } - }); }, - scroll: function scroll() { - var _this2 = this; - - this.timer && clearTimeout(this.timer); - this.timer = null; - this.set({ - animationData: this.resetAnimation.translateX(this.wrapWidth).step().export() - }); - setTimeout(function () { - _this2.set({ - animationData: _this2.animation.translateX(-_this2.contentWidth).step().export() + data: { + show: true, + hasRightIcon: false + }, + watch: { + text() { + this.set({}, this.init); + } + }, + created() { + if (this.data.mode) { + this.set({ + hasRightIcon: true + }); + } + this.resetAnimation = wx.createAnimation({ + duration: 0, + timingFunction: 'linear' }); - }, 20); - this.timer = setTimeout(function () { - _this2.scroll(); - }, this.duration); }, - onClickIcon: function onClickIcon() { - this.timer && clearTimeout(this.timer); - this.timer = null; - this.set({ - show: false - }); + destroyed() { + this.timer && clearTimeout(this.timer); }, - onClick: function onClick(event) { - this.$emit('click', event); + methods: { + init() { + Promise.all([ + this.getRect('.van-notice-bar__content'), + this.getRect('.van-notice-bar__content-wrap') + ]).then((rects) => { + const [contentRect, wrapRect] = rects; + if (contentRect == null || + wrapRect == null || + !contentRect.width || + !wrapRect.width) { + return; + } + const { speed, scrollable, delay } = this.data; + if (scrollable && wrapRect.width < contentRect.width) { + const duration = (contentRect.width / speed) * 1000; + this.wrapWidth = wrapRect.width; + this.contentWidth = contentRect.width; + this.duration = duration; + this.animation = wx.createAnimation({ + duration, + timingFunction: 'linear', + delay + }); + this.scroll(); + } + }); + }, + scroll() { + this.timer && clearTimeout(this.timer); + this.timer = null; + this.set({ + animationData: this.resetAnimation + .translateX(this.wrapWidth) + .step() + .export() + }); + setTimeout(() => { + this.set({ + animationData: this.animation + .translateX(-this.contentWidth) + .step() + .export() + }); + }, 20); + this.timer = setTimeout(() => { + this.scroll(); + }, this.duration); + }, + onClickIcon() { + this.timer && clearTimeout(this.timer); + this.timer = null; + this.set({ show: false }); + }, + onClick(event) { + this.$emit('click', event); + } } - } -}); \ No newline at end of file +}); diff --git a/dist/notify/index.d.ts b/dist/notify/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/notify/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/notify/index.js b/dist/notify/index.js index f0d60a55..2e50abda 100644 --- a/dist/notify/index.js +++ b/dist/notify/index.js @@ -1,42 +1,39 @@ import { VantComponent } from '../common/component'; import { RED } from '../common/color'; VantComponent({ - props: { - text: String, - color: { - type: String, - value: '#fff' + props: { + text: String, + color: { + type: String, + value: '#fff' + }, + backgroundColor: { + type: String, + value: RED + }, + duration: { + type: Number, + value: 3000 + } }, - backgroundColor: { - type: String, - value: RED - }, - duration: { - type: Number, - value: 3000 + methods: { + show() { + const { duration } = this.data; + clearTimeout(this.timer); + this.set({ + show: true + }); + if (duration > 0 && duration !== Infinity) { + this.timer = setTimeout(() => { + this.hide(); + }, duration); + } + }, + hide() { + clearTimeout(this.timer); + this.set({ + show: false + }); + } } - }, - methods: { - show: function show() { - var _this = this; - - var duration = this.data.duration; - clearTimeout(this.timer); - this.set({ - show: true - }); - - if (duration > 0 && duration !== Infinity) { - this.timer = setTimeout(function () { - _this.hide(); - }, duration); - } - }, - hide: function hide() { - clearTimeout(this.timer); - this.set({ - show: false - }); - } - } -}); \ No newline at end of file +}); diff --git a/dist/notify/notify.d.ts b/dist/notify/notify.d.ts new file mode 100644 index 00000000..f821e9db --- /dev/null +++ b/dist/notify/notify.d.ts @@ -0,0 +1,7 @@ +declare type NotifyOptions = { + selector?: string; + duration?: number; + context?: any; +}; +export default function Notify(options?: NotifyOptions): void; +export {}; diff --git a/dist/notify/notify.js b/dist/notify/notify.js index ec1f1bda..ea5153ab 100644 --- a/dist/notify/notify.js +++ b/dist/notify/notify.js @@ -1,34 +1,25 @@ import { isObj } from '../common/utils'; -var defaultOptions = { - selector: '#van-notify', - duration: 3000 +const defaultOptions = { + selector: '#van-notify', + duration: 3000 }; - function parseOptions(text) { - return isObj(text) ? text : { - text: text - }; + return isObj(text) ? text : { text }; } - function getContext() { - var pages = getCurrentPages(); - return pages[pages.length - 1]; + const pages = getCurrentPages(); + return pages[pages.length - 1]; +} +export default function Notify(options = {}) { + options = Object.assign({}, defaultOptions, parseOptions(options)); + const context = options.context || getContext(); + const notify = context.selectComponent(options.selector); + delete options.selector; + if (notify) { + notify.set(options); + notify.show(); + } + else { + console.warn('未找到 van-notify 节点,请确认 selector 及 context 是否正确'); + } } - -export default function Notify(options) { - if (options === void 0) { - options = {}; - } - - options = Object.assign({}, defaultOptions, parseOptions(options)); - var context = options.context || getContext(); - var notify = context.selectComponent(options.selector); - delete options.selector; - - if (notify) { - notify.set(options); - notify.show(); - } else { - console.warn('未找到 van-notify 节点,请确认 selector 及 context 是否正确'); - } -} \ No newline at end of file diff --git a/dist/overlay/index.d.ts b/dist/overlay/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/overlay/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/overlay/index.js b/dist/overlay/index.js index 30176d7f..86819a4b 100644 --- a/dist/overlay/index.js +++ b/dist/overlay/index.js @@ -1,23 +1,23 @@ import { VantComponent } from '../common/component'; VantComponent({ - props: { - show: Boolean, - mask: Boolean, - customStyle: String, - duration: { - type: [Number, Object], - value: 300 + props: { + show: Boolean, + mask: Boolean, + customStyle: String, + duration: { + type: [Number, Object], + value: 300 + }, + zIndex: { + type: Number, + value: 1 + } }, - zIndex: { - type: Number, - value: 1 + methods: { + onClick() { + this.$emit('click'); + }, + // for prevent touchmove + noop() { } } - }, - methods: { - onClick: function onClick() { - this.$emit('click'); - }, - // for prevent touchmove - noop: function noop() {} - } -}); \ No newline at end of file +}); diff --git a/dist/panel/index.d.ts b/dist/panel/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/panel/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/panel/index.js b/dist/panel/index.js index 2d8b8b21..e624d5eb 100644 --- a/dist/panel/index.js +++ b/dist/panel/index.js @@ -1,10 +1,10 @@ import { VantComponent } from '../common/component'; VantComponent({ - classes: ['header-class', 'footer-class'], - props: { - desc: String, - title: String, - status: String, - useFooterSlot: Boolean - } -}); \ No newline at end of file + classes: ['header-class', 'footer-class'], + props: { + desc: String, + title: String, + status: String, + useFooterSlot: Boolean + } +}); diff --git a/dist/picker-column/index.d.ts b/dist/picker-column/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/picker-column/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/picker-column/index.js b/dist/picker-column/index.js index 8796c26b..b763c567 100644 --- a/dist/picker-column/index.js +++ b/dist/picker-column/index.js @@ -1,144 +1,136 @@ import { VantComponent } from '../common/component'; import { isObj, range } from '../common/utils'; -var DEFAULT_DURATION = 200; +const DEFAULT_DURATION = 200; VantComponent({ - classes: ['active-class'], - props: { - valueKey: String, - className: String, - itemHeight: Number, - visibleItemCount: Number, - initialOptions: { - type: Array, - value: [] - }, - defaultIndex: { - type: Number, - value: 0 - } - }, - data: { - startY: 0, - offset: 0, - duration: 0, - startOffset: 0, - options: [], - currentIndex: 0 - }, - beforeCreate: function beforeCreate() { - var _this = this; - - var _this$data = this.data, - defaultIndex = _this$data.defaultIndex, - initialOptions = _this$data.initialOptions; - this.set({ - currentIndex: defaultIndex, - options: initialOptions - }).then(function () { - _this.setIndex(defaultIndex); - }); - }, - computed: { - count: function count() { - return this.data.options.length; - }, - baseOffset: function baseOffset() { - var data = this.data; - return data.itemHeight * (data.visibleItemCount - 1) / 2; - }, - wrapperStyle: function wrapperStyle() { - var data = this.data; - return ["transition: " + data.duration + "ms", "transform: translate3d(0, " + (data.offset + data.baseOffset) + "px, 0)", "line-height: " + data.itemHeight + "px"].join('; '); - } - }, - watch: { - defaultIndex: function defaultIndex(value) { - this.setIndex(value); - } - }, - methods: { - onTouchStart: function onTouchStart(event) { - this.set({ - startY: event.touches[0].clientY, - startOffset: this.data.offset, - duration: 0 - }); - }, - onTouchMove: function onTouchMove(event) { - var data = this.data; - var deltaY = event.touches[0].clientY - data.startY; - this.set({ - offset: range(data.startOffset + deltaY, -(data.count * data.itemHeight), data.itemHeight) - }); - }, - onTouchEnd: function onTouchEnd() { - var data = this.data; - - if (data.offset !== data.startOffset) { - this.set({ - duration: DEFAULT_DURATION - }); - var index = range(Math.round(-data.offset / data.itemHeight), 0, data.count - 1); - this.setIndex(index, true); - } - }, - onClickItem: function onClickItem(event) { - var index = event.currentTarget.dataset.index; - this.setIndex(index, true); - }, - adjustIndex: function adjustIndex(index) { - var data = this.data; - index = range(index, 0, data.count); - - for (var i = index; i < data.count; i++) { - if (!this.isDisabled(data.options[i])) return i; - } - - for (var _i = index - 1; _i >= 0; _i--) { - if (!this.isDisabled(data.options[_i])) return _i; - } - }, - isDisabled: function isDisabled(option) { - return isObj(option) && option.disabled; - }, - getOptionText: function getOptionText(option) { - var data = this.data; - return isObj(option) && data.valueKey in option ? option[data.valueKey] : option; - }, - setIndex: function setIndex(index, userAction) { - var _this2 = this; - - var data = this.data; - index = this.adjustIndex(index) || 0; - var offset = -index * data.itemHeight; - - if (index !== data.currentIndex) { - return this.set({ - offset: offset, - currentIndex: index - }).then(function () { - userAction && _this2.$emit('change', index); - }); - } else { - return this.set({ - offset: offset - }); - } - }, - setValue: function setValue(value) { - var options = this.data.options; - - for (var i = 0; i < options.length; i++) { - if (this.getOptionText(options[i]) === value) { - return this.setIndex(i); + classes: ['active-class'], + props: { + valueKey: String, + className: String, + itemHeight: Number, + visibleItemCount: Number, + initialOptions: { + type: Array, + value: [] + }, + defaultIndex: { + type: Number, + value: 0 } - } - - return Promise.resolve(); }, - getValue: function getValue() { - var data = this.data; - return data.options[data.currentIndex]; + data: { + startY: 0, + offset: 0, + duration: 0, + startOffset: 0, + options: [], + currentIndex: 0 + }, + beforeCreate() { + const { defaultIndex, initialOptions } = this.data; + this.set({ + currentIndex: defaultIndex, + options: initialOptions + }).then(() => { + this.setIndex(defaultIndex); + }); + }, + computed: { + count() { + return this.data.options.length; + }, + baseOffset() { + const { data } = this; + return (data.itemHeight * (data.visibleItemCount - 1)) / 2; + }, + wrapperStyle() { + const { data } = this; + return [ + `transition: ${data.duration}ms`, + `transform: translate3d(0, ${data.offset + data.baseOffset}px, 0)`, + `line-height: ${data.itemHeight}px` + ].join('; '); + } + }, + watch: { + defaultIndex(value) { + this.setIndex(value); + } + }, + methods: { + onTouchStart(event) { + this.set({ + startY: event.touches[0].clientY, + startOffset: this.data.offset, + duration: 0 + }); + }, + onTouchMove(event) { + const { data } = this; + const deltaY = event.touches[0].clientY - data.startY; + this.set({ + offset: range(data.startOffset + deltaY, -(data.count * data.itemHeight), data.itemHeight) + }); + }, + onTouchEnd() { + const { data } = this; + if (data.offset !== data.startOffset) { + this.set({ + duration: DEFAULT_DURATION + }); + const index = range(Math.round(-data.offset / data.itemHeight), 0, data.count - 1); + this.setIndex(index, true); + } + }, + onClickItem(event) { + const { index } = event.currentTarget.dataset; + this.setIndex(index, true); + }, + adjustIndex(index) { + const { data } = this; + index = range(index, 0, data.count); + for (let i = index; i < data.count; i++) { + if (!this.isDisabled(data.options[i])) + return i; + } + for (let i = index - 1; i >= 0; i--) { + if (!this.isDisabled(data.options[i])) + return i; + } + }, + isDisabled(option) { + return isObj(option) && option.disabled; + }, + getOptionText(option) { + const { data } = this; + return isObj(option) && data.valueKey in option + ? option[data.valueKey] + : option; + }, + setIndex(index, userAction) { + const { data } = this; + index = this.adjustIndex(index) || 0; + const offset = -index * data.itemHeight; + if (index !== data.currentIndex) { + return this.set({ offset, currentIndex: index }).then(() => { + userAction && this.$emit('change', index); + }); + } + else { + return this.set({ offset }); + } + }, + setValue(value) { + const { options } = this.data; + for (let i = 0; i < options.length; i++) { + if (this.getOptionText(options[i]) === value) { + return this.setIndex(i); + } + } + return Promise.resolve(); + }, + getValue() { + const { data } = this; + return data.options[data.currentIndex]; + } } - } -}); \ No newline at end of file +}); diff --git a/dist/picker/index.d.ts b/dist/picker/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/picker/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/picker/index.js b/dist/picker/index.js index 3d19e0d3..f5ddaab5 100644 --- a/dist/picker/index.js +++ b/dist/picker/index.js @@ -1,185 +1,147 @@ import { VantComponent } from '../common/component'; - function isSimple(columns) { - return columns.length && !columns[0].values; + return columns.length && !columns[0].values; } - VantComponent({ - classes: ['active-class', 'toolbar-class', 'column-class'], - props: { - title: String, - loading: Boolean, - showToolbar: Boolean, - confirmButtonText: String, - cancelButtonText: String, - visibleItemCount: { - type: Number, - value: 5 - }, - valueKey: { - type: String, - value: 'text' - }, - itemHeight: { - type: Number, - value: 44 - }, - columns: { - type: Array, - value: [], - observer: function observer(columns) { - if (columns === void 0) { - columns = []; + classes: ['active-class', 'toolbar-class', 'column-class'], + props: { + title: String, + loading: Boolean, + showToolbar: Boolean, + confirmButtonText: String, + cancelButtonText: String, + visibleItemCount: { + type: Number, + value: 5 + }, + valueKey: { + type: String, + value: 'text' + }, + itemHeight: { + type: Number, + value: 44 + }, + columns: { + type: Array, + value: [], + observer(columns = []) { + this.simple = isSimple(columns); + this.children = this.selectAllComponents('.van-picker__column'); + if (Array.isArray(this.children) && this.children.length) { + this.setColumns().catch(() => { }); + } + } } - - this.simple = isSimple(columns); - this.children = this.selectAllComponents('.van-picker__column'); - - if (Array.isArray(this.children) && this.children.length) { - this.setColumns().catch(function () {}); + }, + beforeCreate() { + this.children = []; + }, + methods: { + noop() { }, + setColumns() { + const { data } = this; + const columns = this.simple ? [{ values: data.columns }] : data.columns; + const stack = columns.map((column, index) => this.setColumnValues(index, column.values)); + return Promise.all(stack); + }, + emit(event) { + const { type } = event.currentTarget.dataset; + if (this.simple) { + this.$emit(type, { + value: this.getColumnValue(0), + index: this.getColumnIndex(0) + }); + } + else { + this.$emit(type, { + value: this.getValues(), + index: this.getIndexes() + }); + } + }, + onChange(event) { + if (this.simple) { + this.$emit('change', { + picker: this, + value: this.getColumnValue(0), + index: this.getColumnIndex(0) + }); + } + else { + this.$emit('change', { + picker: this, + value: this.getValues(), + index: event.currentTarget.dataset.index + }); + } + }, + // get column instance by index + getColumn(index) { + return this.children[index]; + }, + // get column value by index + getColumnValue(index) { + const column = this.getColumn(index); + return column && column.getValue(); + }, + // set column value by index + setColumnValue(index, value) { + const column = this.getColumn(index); + if (column == null) { + return Promise.reject('setColumnValue: 对应列不存在'); + } + return column.setValue(value); + }, + // get column option index by column index + getColumnIndex(columnIndex) { + return (this.getColumn(columnIndex) || {}).data.currentIndex; + }, + // set column option index by column index + setColumnIndex(columnIndex, optionIndex) { + const column = this.getColumn(columnIndex); + if (column == null) { + return Promise.reject('setColumnIndex: 对应列不存在'); + } + return column.setIndex(optionIndex); + }, + // get options of column by index + getColumnValues(index) { + return (this.children[index] || {}).data.options; + }, + // set options of column by index + setColumnValues(index, options, needReset = true) { + const column = this.children[index]; + if (column == null) { + return Promise.reject('setColumnValues: 对应列不存在'); + } + const isSame = JSON.stringify(column.data.options) === JSON.stringify(options); + if (isSame) { + return Promise.resolve(); + } + return column.set({ options }).then(() => { + if (needReset) { + column.setIndex(0); + } + }); + }, + // get values of all columns + getValues() { + return this.children.map((child) => child.getValue()); + }, + // set values of all columns + setValues(values) { + const stack = values.map((value, index) => this.setColumnValue(index, value)); + return Promise.all(stack); + }, + // get indexes of all columns + getIndexes() { + return this.children.map((child) => child.data.currentIndex); + }, + // set indexes of all columns + setIndexes(indexes) { + const stack = indexes.map((optionIndex, columnIndex) => this.setColumnIndex(columnIndex, optionIndex)); + return Promise.all(stack); } - } } - }, - beforeCreate: function beforeCreate() { - this.children = []; - }, - methods: { - noop: function noop() {}, - setColumns: function setColumns() { - var _this = this; - - var data = this.data; - var columns = this.simple ? [{ - values: data.columns - }] : data.columns; - var stack = columns.map(function (column, index) { - return _this.setColumnValues(index, column.values); - }); - return Promise.all(stack); - }, - emit: function emit(event) { - var type = event.currentTarget.dataset.type; - - if (this.simple) { - this.$emit(type, { - value: this.getColumnValue(0), - index: this.getColumnIndex(0) - }); - } else { - this.$emit(type, { - value: this.getValues(), - index: this.getIndexes() - }); - } - }, - onChange: function onChange(event) { - if (this.simple) { - this.$emit('change', { - picker: this, - value: this.getColumnValue(0), - index: this.getColumnIndex(0) - }); - } else { - this.$emit('change', { - picker: this, - value: this.getValues(), - index: event.currentTarget.dataset.index - }); - } - }, - // get column instance by index - getColumn: function getColumn(index) { - return this.children[index]; - }, - // get column value by index - getColumnValue: function getColumnValue(index) { - var column = this.getColumn(index); - return column && column.getValue(); - }, - // set column value by index - setColumnValue: function setColumnValue(index, value) { - var column = this.getColumn(index); - - if (column == null) { - return Promise.reject('setColumnValue: 对应列不存在'); - } - - return column.setValue(value); - }, - // get column option index by column index - getColumnIndex: function getColumnIndex(columnIndex) { - return (this.getColumn(columnIndex) || {}).data.currentIndex; - }, - // set column option index by column index - setColumnIndex: function setColumnIndex(columnIndex, optionIndex) { - var column = this.getColumn(columnIndex); - - if (column == null) { - return Promise.reject('setColumnIndex: 对应列不存在'); - } - - return column.setIndex(optionIndex); - }, - // get options of column by index - getColumnValues: function getColumnValues(index) { - return (this.children[index] || {}).data.options; - }, - // set options of column by index - setColumnValues: function setColumnValues(index, options, needReset) { - if (needReset === void 0) { - needReset = true; - } - - var column = this.children[index]; - - if (column == null) { - return Promise.reject('setColumnValues: 对应列不存在'); - } - - var isSame = JSON.stringify(column.data.options) === JSON.stringify(options); - - if (isSame) { - return Promise.resolve(); - } - - return column.set({ - options: options - }).then(function () { - if (needReset) { - column.setIndex(0); - } - }); - }, - // get values of all columns - getValues: function getValues() { - return this.children.map(function (child) { - return child.getValue(); - }); - }, - // set values of all columns - setValues: function setValues(values) { - var _this2 = this; - - var stack = values.map(function (value, index) { - return _this2.setColumnValue(index, value); - }); - return Promise.all(stack); - }, - // get indexes of all columns - getIndexes: function getIndexes() { - return this.children.map(function (child) { - return child.data.currentIndex; - }); - }, - // set indexes of all columns - setIndexes: function setIndexes(indexes) { - var _this3 = this; - - var stack = indexes.map(function (optionIndex, columnIndex) { - return _this3.setColumnIndex(columnIndex, optionIndex); - }); - return Promise.all(stack); - } - } -}); \ No newline at end of file +}); diff --git a/dist/popup/index.d.ts b/dist/popup/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/popup/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/popup/index.js b/dist/popup/index.js index c37ffe35..67c7d6fd 100644 --- a/dist/popup/index.js +++ b/dist/popup/index.js @@ -2,49 +2,53 @@ import { VantComponent } from '../common/component'; import { transition } from '../mixins/transition'; import { iphonex } from '../mixins/iphonex'; VantComponent({ - classes: ['enter-class', 'enter-active-class', 'enter-to-class', 'leave-class', 'leave-active-class', 'leave-to-class'], - mixins: [transition(false), iphonex], - props: { - transition: { - type: String, - observer: 'observeClass' + classes: [ + 'enter-class', + 'enter-active-class', + 'enter-to-class', + 'leave-class', + 'leave-active-class', + 'leave-to-class' + ], + mixins: [transition(false), iphonex], + props: { + transition: { + type: String, + observer: 'observeClass' + }, + customStyle: String, + overlayStyle: String, + zIndex: { + type: Number, + value: 100 + }, + overlay: { + type: Boolean, + value: true + }, + closeOnClickOverlay: { + type: Boolean, + value: true + }, + position: { + type: String, + value: 'center', + observer: 'observeClass' + } }, - customStyle: String, - overlayStyle: String, - zIndex: { - type: Number, - value: 100 + created() { + this.observeClass(); }, - overlay: { - type: Boolean, - value: true - }, - closeOnClickOverlay: { - type: Boolean, - value: true - }, - position: { - type: String, - value: 'center', - observer: 'observeClass' + methods: { + onClickOverlay() { + this.$emit('click-overlay'); + if (this.data.closeOnClickOverlay) { + this.$emit('close'); + } + }, + observeClass() { + const { transition, position } = this.data; + this.updateClasses(transition || position); + } } - }, - created: function created() { - this.observeClass(); - }, - methods: { - onClickOverlay: function onClickOverlay() { - this.$emit('click-overlay'); - - if (this.data.closeOnClickOverlay) { - this.$emit('close'); - } - }, - observeClass: function observeClass() { - var _this$data = this.data, - transition = _this$data.transition, - position = _this$data.position; - this.updateClasses(transition || position); - } - } -}); \ No newline at end of file +}); diff --git a/dist/progress/index.d.ts b/dist/progress/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/progress/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/progress/index.js b/dist/progress/index.js index 2eb9e99d..e345cc23 100644 --- a/dist/progress/index.js +++ b/dist/progress/index.js @@ -1,67 +1,65 @@ import { VantComponent } from '../common/component'; import { BLUE } from '../common/color'; VantComponent({ - props: { - inactive: Boolean, - percentage: Number, - pivotText: String, - pivotColor: String, - showPivot: { - type: Boolean, - value: true + props: { + inactive: Boolean, + percentage: Number, + pivotText: String, + pivotColor: String, + showPivot: { + type: Boolean, + value: true + }, + color: { + type: String, + value: BLUE + }, + textColor: { + type: String, + value: '#fff' + } }, - color: { - type: String, - value: BLUE + data: { + pivotWidth: 0, + progressWidth: 0 }, - textColor: { - type: String, - value: '#fff' + watch: { + pivotText: 'getWidth', + showPivot: 'getWidth' + }, + computed: { + portionStyle() { + const width = (this.data.progressWidth - this.data.pivotWidth) * this.data.percentage / 100 + 'px'; + const background = this.getCurrentColor(); + return `width: ${width}; background: ${background}; `; + }, + pivotStyle() { + const color = this.data.textColor; + const background = this.data.pivotColor || this.getCurrentColor(); + return `color: ${color}; background: ${background}`; + }, + text() { + return this.data.pivotText || this.data.percentage + '%'; + } + }, + mounted() { + this.getWidth(); + }, + methods: { + getCurrentColor() { + return this.data.inactive ? '#cacaca' : this.data.color; + }, + getWidth() { + this.getRect('.van-progress').then(rect => { + this.set({ + progressWidth: rect.width + }); + }); + this.getRect('.van-progress__pivot').then(rect => { + this.set({ + pivotWidth: rect.width || 0 + }); + }); + } } - }, - data: { - pivotWidth: 0, - progressWidth: 0 - }, - watch: { - pivotText: 'getWidth', - showPivot: 'getWidth' - }, - computed: { - portionStyle: function portionStyle() { - var width = (this.data.progressWidth - this.data.pivotWidth) * this.data.percentage / 100 + 'px'; - var background = this.getCurrentColor(); - return "width: " + width + "; background: " + background + "; "; - }, - pivotStyle: function pivotStyle() { - var color = this.data.textColor; - var background = this.data.pivotColor || this.getCurrentColor(); - return "color: " + color + "; background: " + background; - }, - text: function text() { - return this.data.pivotText || this.data.percentage + '%'; - } - }, - mounted: function mounted() { - this.getWidth(); - }, - methods: { - getCurrentColor: function getCurrentColor() { - return this.data.inactive ? '#cacaca' : this.data.color; - }, - getWidth: function getWidth() { - var _this = this; - - this.getRect('.van-progress').then(function (rect) { - _this.set({ - progressWidth: rect.width - }); - }); - this.getRect('.van-progress__pivot').then(function (rect) { - _this.set({ - pivotWidth: rect.width || 0 - }); - }); - } - } -}); \ No newline at end of file +}); diff --git a/dist/radio-group/index.d.ts b/dist/radio-group/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/radio-group/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/radio-group/index.js b/dist/radio-group/index.js index e1ef1e0a..0a909888 100644 --- a/dist/radio-group/index.js +++ b/dist/radio-group/index.js @@ -1,39 +1,33 @@ import { VantComponent } from '../common/component'; VantComponent({ - field: true, - relation: { - name: 'radio', - type: 'descendant', - linked: function linked(target) { - var _this$data = this.data, - value = _this$data.value, - disabled = _this$data.disabled; - target.set({ - value: value, - disabled: disabled || target.data.disabled - }); - } - }, - props: { - value: null, - disabled: Boolean - }, - watch: { - value: function value(_value) { - var children = this.getRelationNodes('../radio/index'); - children.forEach(function (child) { - child.set({ - value: _value - }); - }); + field: true, + relation: { + name: 'radio', + type: 'descendant', + linked(target) { + const { value, disabled } = this.data; + target.set({ + value: value, + disabled: disabled || target.data.disabled + }); + } }, - disabled: function disabled(_disabled) { - var children = this.getRelationNodes('../radio/index'); - children.forEach(function (child) { - child.set({ - disabled: _disabled || child.data.disabled - }); - }); + props: { + value: null, + disabled: Boolean + }, + watch: { + value(value) { + const children = this.getRelationNodes('../radio/index'); + children.forEach(child => { + child.set({ value }); + }); + }, + disabled(disabled) { + const children = this.getRelationNodes('../radio/index'); + children.forEach(child => { + child.set({ disabled: disabled || child.data.disabled }); + }); + } } - } -}); \ No newline at end of file +}); diff --git a/dist/radio/index.d.ts b/dist/radio/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/radio/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/radio/index.js b/dist/radio/index.js index b66313a6..975cea11 100644 --- a/dist/radio/index.js +++ b/dist/radio/index.js @@ -1,32 +1,32 @@ import { VantComponent } from '../common/component'; VantComponent({ - field: true, - relation: { - name: 'radio-group', - type: 'ancestor' - }, - classes: ['icon-class', 'label-class'], - props: { - name: null, - value: null, - disabled: Boolean, - labelDisabled: Boolean, - labelPosition: String, - checkedColor: String - }, - methods: { - emitChange: function emitChange(value) { - var instance = this.getRelationNodes('../radio-group/index')[0] || this; - instance.$emit('input', value); - instance.$emit('change', value); + field: true, + relation: { + name: 'radio-group', + type: 'ancestor' }, - onChange: function onChange(event) { - this.emitChange(event.detail.value); + classes: ['icon-class', 'label-class'], + props: { + name: null, + value: null, + disabled: Boolean, + labelDisabled: Boolean, + labelPosition: String, + checkedColor: String }, - onClickLabel: function onClickLabel() { - if (!this.data.disabled && !this.data.labelDisabled) { - this.emitChange(this.data.name); - } + methods: { + emitChange(value) { + const instance = this.getRelationNodes('../radio-group/index')[0] || this; + instance.$emit('input', value); + instance.$emit('change', value); + }, + onChange(event) { + this.emitChange(event.detail.value); + }, + onClickLabel() { + if (!this.data.disabled && !this.data.labelDisabled) { + this.emitChange(this.data.name); + } + } } - } -}); \ No newline at end of file +}); diff --git a/dist/rate/index.d.ts b/dist/rate/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/rate/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/rate/index.js b/dist/rate/index.js index 873ba6b7..7ca78a1e 100644 --- a/dist/rate/index.js +++ b/dist/rate/index.js @@ -1,99 +1,80 @@ -function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } - import { VantComponent } from '../common/component'; VantComponent({ - field: true, - classes: ['icon-class'], - props: { - readonly: Boolean, - disabled: Boolean, - size: { - type: Number, - value: 20 - }, - icon: { - type: String, - value: 'star' - }, - voidIcon: { - type: String, - value: 'star-o' - }, - color: { - type: String, - value: '#ffd21e' - }, - voidColor: { - type: String, - value: '#c7c7c7' - }, - disabledColor: { - type: String, - value: '#bdbdbd' - }, - count: { - type: Number, - value: 5 - }, - value: { - type: Number, - value: 0 - } - }, - data: { - innerValue: 0 - }, - watch: { - value: function value(_value) { - if (_value !== this.data.innerValue) { - this.set({ - innerValue: _value - }); - } - } - }, - computed: { - list: function list() { - var _this$data = this.data, - count = _this$data.count, - innerValue = _this$data.innerValue; - return Array.from({ - length: count - }, function (_, index) { - return index < innerValue; - }); - } - }, - methods: { - onSelect: function onSelect(event) { - var data = this.data; - var index = event.currentTarget.dataset.index; - - if (!data.disabled && !data.readonly) { - this.set({ - innerValue: index + 1 - }); - this.$emit('input', index + 1); - this.$emit('change', index + 1); - } - }, - onTouchMove: function onTouchMove(event) { - var _this = this; - - var _event$touches$ = event.touches[0], - clientX = _event$touches$.clientX, - clientY = _event$touches$.clientY; - this.getRect('.van-rate__item', true).then(function (list) { - var target = list.find(function (item) { - return clientX >= item.left && clientX <= item.right && clientY >= item.top && clientY <= item.bottom; - }); - - if (target != null) { - _this.onSelect(_extends({}, event, { - currentTarget: target - })); + field: true, + classes: ['icon-class'], + props: { + readonly: Boolean, + disabled: Boolean, + size: { + type: Number, + value: 20 + }, + icon: { + type: String, + value: 'star' + }, + voidIcon: { + type: String, + value: 'star-o' + }, + color: { + type: String, + value: '#ffd21e' + }, + voidColor: { + type: String, + value: '#c7c7c7' + }, + disabledColor: { + type: String, + value: '#bdbdbd' + }, + count: { + type: Number, + value: 5 + }, + value: { + type: Number, + value: 0 + } + }, + data: { + innerValue: 0 + }, + watch: { + value(value) { + if (value !== this.data.innerValue) { + this.set({ innerValue: value }); + } + } + }, + computed: { + list() { + const { count, innerValue } = this.data; + return Array.from({ length: count }, (_, index) => index < innerValue); + } + }, + methods: { + onSelect(event) { + const { data } = this; + const { index } = event.currentTarget.dataset; + if (!data.disabled && !data.readonly) { + this.set({ innerValue: index + 1 }); + this.$emit('input', index + 1); + this.$emit('change', index + 1); + } + }, + onTouchMove(event) { + const { clientX, clientY } = event.touches[0]; + this.getRect('.van-rate__item', true).then(list => { + const target = list.find(item => clientX >= item.left && + clientX <= item.right && + clientY >= item.top && + clientY <= item.bottom); + if (target != null) { + this.onSelect(Object.assign({}, event, { currentTarget: target })); + } + }); } - }); } - } -}); \ No newline at end of file +}); diff --git a/dist/row/index.d.ts b/dist/row/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/row/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/row/index.js b/dist/row/index.js index 365b294d..4f92485f 100644 --- a/dist/row/index.js +++ b/dist/row/index.js @@ -1,38 +1,36 @@ import { VantComponent } from '../common/component'; VantComponent({ - relation: { - name: 'col', - type: 'descendant', - linked: function linked(target) { - if (this.data.gutter) { - target.setGutter(this.data.gutter); - } + relation: { + name: 'col', + type: 'descendant', + linked(target) { + if (this.data.gutter) { + target.setGutter(this.data.gutter); + } + } + }, + props: { + gutter: Number + }, + watch: { + gutter: 'setGutter' + }, + mounted() { + if (this.data.gutter) { + this.setGutter(); + } + }, + methods: { + setGutter() { + const { gutter } = this.data; + const margin = `-${Number(gutter) / 2}px`; + const style = gutter + ? `margin-right: ${margin}; margin-left: ${margin};` + : ''; + this.set({ style }); + this.getRelationNodes('../col/index').forEach(col => { + col.setGutter(this.data.gutter); + }); + } } - }, - props: { - gutter: Number - }, - watch: { - gutter: 'setGutter' - }, - mounted: function mounted() { - if (this.data.gutter) { - this.setGutter(); - } - }, - methods: { - setGutter: function setGutter() { - var _this = this; - - var gutter = this.data.gutter; - var margin = "-" + Number(gutter) / 2 + "px"; - var style = gutter ? "margin-right: " + margin + "; margin-left: " + margin + ";" : ''; - this.set({ - style: style - }); - this.getRelationNodes('../col/index').forEach(function (col) { - col.setGutter(_this.data.gutter); - }); - } - } -}); \ No newline at end of file +}); diff --git a/dist/search/index.d.ts b/dist/search/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/search/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/search/index.js b/dist/search/index.js index 2c8ebaa1..b02b1c19 100644 --- a/dist/search/index.js +++ b/dist/search/index.js @@ -1,51 +1,47 @@ import { VantComponent } from '../common/component'; VantComponent({ - field: true, - classes: ['field-class', 'input-class', 'cancel-class'], - props: { - focus: Boolean, - error: Boolean, - disabled: Boolean, - readonly: Boolean, - inputAlign: String, - showAction: Boolean, - useActionSlot: Boolean, - placeholder: String, - placeholderStyle: String, - background: { - type: String, - value: '#f2f2f2' + field: true, + classes: ['field-class', 'input-class', 'cancel-class'], + props: { + focus: Boolean, + error: Boolean, + disabled: Boolean, + readonly: Boolean, + inputAlign: String, + showAction: Boolean, + useActionSlot: Boolean, + placeholder: String, + placeholderStyle: String, + background: { + type: String, + value: '#f2f2f2' + }, + maxlength: { + type: Number, + value: -1 + } }, - maxlength: { - type: Number, - value: -1 + methods: { + onChange(event) { + this.set({ value: event.detail }); + this.$emit('change', event.detail); + }, + onCancel() { + this.set({ value: '' }); + this.$emit('cancel'); + this.$emit('change', ''); + }, + onSearch() { + this.$emit('search', this.data.value); + }, + onFocus() { + this.$emit('focus'); + }, + onBlur() { + this.$emit('blur'); + }, + onClear() { + this.$emit('clear'); + }, } - }, - methods: { - onChange: function onChange(event) { - this.set({ - value: event.detail - }); - this.$emit('change', event.detail); - }, - onCancel: function onCancel() { - this.set({ - value: '' - }); - this.$emit('cancel'); - this.$emit('change', ''); - }, - onSearch: function onSearch() { - this.$emit('search', this.data.value); - }, - onFocus: function onFocus() { - this.$emit('focus'); - }, - onBlur: function onBlur() { - this.$emit('blur'); - }, - onClear: function onClear() { - this.$emit('clear'); - } - } -}); \ No newline at end of file +}); diff --git a/dist/slider/index.d.ts b/dist/slider/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/slider/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/slider/index.js b/dist/slider/index.js index b779e8b0..2d8d79ed 100644 --- a/dist/slider/index.js +++ b/dist/slider/index.js @@ -1,95 +1,86 @@ import { VantComponent } from '../common/component'; import { touch } from '../mixins/touch'; VantComponent({ - mixins: [touch], - props: { - disabled: Boolean, - useButtonSlot: Boolean, - activeColor: String, - inactiveColor: String, - max: { - type: Number, - value: 100 + mixins: [touch], + props: { + disabled: Boolean, + useButtonSlot: Boolean, + activeColor: String, + inactiveColor: String, + max: { + type: Number, + value: 100 + }, + min: { + type: Number, + value: 0 + }, + step: { + type: Number, + value: 1 + }, + value: { + type: Number, + value: 0 + }, + barHeight: { + type: String, + value: '2px' + } }, - min: { - type: Number, - value: 0 + watch: { + value(value) { + this.updateValue(value, false); + } }, - step: { - type: Number, - value: 1 + created() { + this.updateValue(this.data.value); }, - value: { - type: Number, - value: 0 - }, - barHeight: { - type: String, - value: '2px' + methods: { + onTouchStart(event) { + if (this.data.disabled) + return; + this.touchStart(event); + this.startValue = this.format(this.data.value); + }, + onTouchMove(event) { + if (this.data.disabled) + return; + this.touchMove(event); + this.getRect('.van-slider').then(rect => { + const diff = this.deltaX / rect.width * 100; + this.updateValue(this.startValue + diff, false, true); + }); + }, + onTouchEnd() { + if (this.data.disabled) + return; + this.updateValue(this.data.value, true); + }, + onClick(event) { + if (this.data.disabled) + return; + this.getRect(rect => { + const value = (event.detail.x - rect.left) / rect.width * 100; + this.updateValue(value, true); + }); + }, + updateValue(value, end, drag) { + value = this.format(value); + this.set({ + value, + barStyle: `width: ${value}%; height: ${this.data.barHeight};` + }); + if (drag) { + this.$emit('drag', { value }); + } + if (end) { + this.$emit('change', value); + } + }, + format(value) { + const { max, min, step } = this.data; + return Math.round(Math.max(min, Math.min(value, max)) / step) * step; + } } - }, - watch: { - value: function value(_value) { - this.updateValue(_value, false); - } - }, - created: function created() { - this.updateValue(this.data.value); - }, - methods: { - onTouchStart: function onTouchStart(event) { - if (this.data.disabled) return; - this.touchStart(event); - this.startValue = this.format(this.data.value); - }, - onTouchMove: function onTouchMove(event) { - var _this = this; - - if (this.data.disabled) return; - this.touchMove(event); - this.getRect('.van-slider').then(function (rect) { - var diff = _this.deltaX / rect.width * 100; - - _this.updateValue(_this.startValue + diff, false, true); - }); - }, - onTouchEnd: function onTouchEnd() { - if (this.data.disabled) return; - this.updateValue(this.data.value, true); - }, - onClick: function onClick(event) { - var _this2 = this; - - if (this.data.disabled) return; - this.getRect(function (rect) { - var value = (event.detail.x - rect.left) / rect.width * 100; - - _this2.updateValue(value, true); - }); - }, - updateValue: function updateValue(value, end, drag) { - value = this.format(value); - this.set({ - value: value, - barStyle: "width: " + value + "%; height: " + this.data.barHeight + ";" - }); - - if (drag) { - this.$emit('drag', { - value: value - }); - } - - if (end) { - this.$emit('change', value); - } - }, - format: function format(value) { - var _this$data = this.data, - max = _this$data.max, - min = _this$data.min, - step = _this$data.step; - return Math.round(Math.max(min, Math.min(value, max)) / step) * step; - } - } -}); \ No newline at end of file +}); diff --git a/dist/stepper/index.d.ts b/dist/stepper/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/stepper/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/stepper/index.js b/dist/stepper/index.js index 1f17b0d8..e57669cb 100644 --- a/dist/stepper/index.js +++ b/dist/stepper/index.js @@ -1,103 +1,101 @@ -import { VantComponent } from '../common/component'; // Note that the bitwise operators and shift operators operate on 32-bit ints +import { VantComponent } from '../common/component'; +// Note that the bitwise operators and shift operators operate on 32-bit ints // so in that case, the max safe integer is 2^31-1, or 2147483647 - -var MAX = 2147483647; +const MAX = 2147483647; VantComponent({ - field: true, - classes: ['input-class', 'plus-class', 'minus-class'], - props: { - value: null, - integer: Boolean, - disabled: Boolean, - asyncChange: Boolean, - disableInput: Boolean, - min: { - type: null, - value: 1 + field: true, + classes: [ + 'input-class', + 'plus-class', + 'minus-class' + ], + props: { + value: null, + integer: Boolean, + disabled: Boolean, + asyncChange: Boolean, + disableInput: Boolean, + min: { + type: null, + value: 1 + }, + max: { + type: null, + value: MAX + }, + step: { + type: null, + value: 1 + } }, - max: { - type: null, - value: MAX + computed: { + minusDisabled() { + return this.data.disabled || this.data.value <= this.data.min; + }, + plusDisabled() { + return this.data.disabled || this.data.value >= this.data.max; + } }, - step: { - type: null, - value: 1 - } - }, - computed: { - minusDisabled: function minusDisabled() { - return this.data.disabled || this.data.value <= this.data.min; + watch: { + value(value) { + if (value !== '') { + this.set({ + value: this.range(value) + }); + } + } }, - plusDisabled: function plusDisabled() { - return this.data.disabled || this.data.value >= this.data.max; - } - }, - watch: { - value: function value(_value) { - if (_value !== '') { + data: { + focus: false + }, + created() { this.set({ - value: this.range(_value) + value: this.range(this.data.value) }); - } + }, + methods: { + onClickWrapper() { + if (!this.data.focus) { + this.setData({ focus: true }); + } + }, + onFocus(event) { + this.$emit('focus', event.detail); + }, + onBlur(event) { + const value = this.range(this.data.value); + this.triggerInput(value); + this.$emit('blur', event.detail); + }, + // limit value range + range(value) { + return Math.max(Math.min(this.data.max, value), this.data.min); + }, + onInput(event) { + const { value = '' } = event.detail || {}; + this.triggerInput(value); + }, + onChange(type) { + if (this.data[`${type}Disabled`]) { + this.$emit('overlimit', type); + return; + } + const diff = type === 'minus' ? -this.data.step : +this.data.step; + const value = Math.round((this.data.value + diff) * 100) / 100; + this.triggerInput(this.range(value)); + this.$emit(type); + }, + onMinus() { + this.onChange('minus'); + }, + onPlus() { + this.onChange('plus'); + }, + triggerInput(value) { + this.set({ + value: this.data.asyncChange ? this.data.value : value + }); + this.$emit('change', value); + } } - }, - data: { - focus: false - }, - created: function created() { - this.set({ - value: this.range(this.data.value) - }); - }, - methods: { - onClickWrapper: function onClickWrapper() { - if (!this.data.focus) { - this.setData({ - focus: true - }); - } - }, - onFocus: function onFocus(event) { - this.$emit('focus', event.detail); - }, - onBlur: function onBlur(event) { - var value = this.range(this.data.value); - this.triggerInput(value); - this.$emit('blur', event.detail); - }, - // limit value range - range: function range(value) { - return Math.max(Math.min(this.data.max, value), this.data.min); - }, - onInput: function onInput(event) { - var _ref = event.detail || {}, - _ref$value = _ref.value, - value = _ref$value === void 0 ? '' : _ref$value; - - this.triggerInput(value); - }, - onChange: function onChange(type) { - if (this.data[type + "Disabled"]) { - this.$emit('overlimit', type); - return; - } - - var diff = type === 'minus' ? -this.data.step : +this.data.step; - var value = Math.round((this.data.value + diff) * 100) / 100; - this.triggerInput(this.range(value)); - this.$emit(type); - }, - onMinus: function onMinus() { - this.onChange('minus'); - }, - onPlus: function onPlus() { - this.onChange('plus'); - }, - triggerInput: function triggerInput(value) { - this.set({ - value: this.data.asyncChange ? this.data.value : value - }); - this.$emit('change', value); - } - } -}); \ No newline at end of file +}); diff --git a/dist/steps/index.d.ts b/dist/steps/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/steps/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/steps/index.js b/dist/steps/index.js index cc712c46..6d236d19 100644 --- a/dist/steps/index.js +++ b/dist/steps/index.js @@ -1,48 +1,17 @@ import { VantComponent } from '../common/component'; import { GREEN } from '../common/color'; VantComponent({ - props: { - icon: String, - steps: Array, - active: Number, - direction: { - type: String, - value: 'horizontal' - }, - activeColor: { - type: String, - value: GREEN + props: { + icon: String, + steps: Array, + active: Number, + direction: { + type: String, + value: 'horizontal' + }, + activeColor: { + type: String, + value: GREEN + } } - }, - watch: { - steps: 'formatSteps', - active: 'formatSteps' - }, - created: function created() { - this.formatSteps(); - }, - methods: { - formatSteps: function formatSteps() { - var _this = this; - - var steps = this.data.steps; - steps.forEach(function (step, index) { - step.status = _this.getStatus(index); - }); - this.set({ - steps: steps - }); - }, - getStatus: function getStatus(index) { - var active = this.data.active; - - if (index < active) { - return 'finish'; - } else if (index === active) { - return 'process'; - } - - return ''; - } - } -}); \ No newline at end of file +}); diff --git a/dist/steps/index.wxml b/dist/steps/index.wxml index b323233e..508705d6 100644 --- a/dist/steps/index.wxml +++ b/dist/steps/index.wxml @@ -1,20 +1,35 @@ - + + + - + {{ item.text }} {{ item.desc }} - + - + + + +function get(index, active) { + if (index < active) { + return 'finish'; + } else if (index === active) { + return 'process'; + } + + return ''; +} + +module.exports = get; + diff --git a/dist/steps/index.wxss b/dist/steps/index.wxss index cc89e91a..3af61882 100644 --- a/dist/steps/index.wxss +++ b/dist/steps/index.wxss @@ -1 +1 @@ -@import '../common/index.wxss';.van-steps{overflow:hidden;background-color:#fff}.van-steps--horizontal{padding:10px}.van-steps--horizontal .van-step__wrapper{position:relative;display:-webkit-flex;display:flex;overflow:hidden}.van-steps--vertical{padding-left:10px}.van-steps--vertical .van-step__wrapper{padding:0 0 0 20px}.van-step{position:relative;-webkit-flex:1;flex:1;font-size:14px;color:#999}.van-step--finish{color:#333}.van-step__circle{width:5px;height:5px;border-radius:50%;background-color:#999}.van-step--horizontal{padding-bottom:14px}.van-step--horizontal:first-child .van-step__title{-webkit-transform:none;transform:none}.van-step--horizontal:first-child .van-step__circle-container{padding:0 8px 0 0;-webkit-transform:translate3d(0,50%,0);transform:translate3d(0,50%,0)}.van-step--horizontal:last-child{position:absolute;right:0;width:auto}.van-step--horizontal:last-child .van-step__title{-webkit-transform:none;transform:none;text-align:right}.van-step--horizontal:last-child .van-step__circle-container{right:0;padding:0 0 0 8px;-webkit-transform:translate3d(0,50%,0);transform:translate3d(0,50%,0)}.van-step--horizontal .van-step__circle-container{position:absolute;bottom:6px;z-index:1;padding:0 8px;background-color:#fff;-webkit-transform:translate3d(-50%,50%,0);transform:translate3d(-50%,50%,0)}.van-step--horizontal .van-step__title{display:inline-block;font-size:12px;-webkit-transform:translate3d(-50%,0,0);transform:translate3d(-50%,0,0)}.van-step--horizontal .van-step__line{position:absolute;left:0;right:0;bottom:6px;height:1px;background-color:#eee;-webkit-transform:translate3d(0,50%,0);transform:translate3d(0,50%,0)}.van-step--horizontal.van-step--process{color:#333}.van-step--horizontal.van-step--process .van-step__active{display:block;font-size:12px;color:#07c160;line-height:1}.van-step--vertical{font-size:14px;line-height:18px;padding:10px 10px 10px 0}.van-step--vertical::after{border-bottom-width:1px}.van-step--vertical:last-child::after{border-bottom-width:none}.van-step--vertical:first-child::before{content:'';position:absolute;width:1px;height:20px;background-color:#fff;top:0;left:-15px;z-index:1}.van-step--vertical .van-step__active,.van-step--vertical .van-step__circle,.van-step--vertical .van-step__line{position:absolute;top:19px;left:-14px;z-index:2;-webkit-transform:translate3d(-50%,-50%,0);transform:translate3d(-50%,-50%,0)}.van-step--vertical .van-step__active{font-size:12px;line-height:1}.van-step--vertical .van-step__line{z-index:1;width:1px;height:100%;background-color:#eee;-webkit-transform:translate3d(-50%,0,0);transform:translate3d(-50%,0,0)} \ No newline at end of file +@import '../common/index.wxss';.van-steps{overflow:hidden;background-color:#fff}.van-steps--horizontal{padding:10px}.van-steps--horizontal .van-step__wrapper{position:relative;display:-webkit-flex;display:flex;overflow:hidden}.van-steps--vertical{padding-left:10px}.van-steps--vertical .van-step__wrapper{padding:0 0 0 20px}.van-step{position:relative;-webkit-flex:1;flex:1;font-size:14px;color:#999}.van-step--finish{color:#333}.van-step__circle{width:5px;height:5px;background-color:#999;border-radius:50%}.van-step--horizontal{padding-bottom:14px}.van-step--horizontal:first-child .van-step__title{-webkit-transform:none;transform:none}.van-step--horizontal:first-child .van-step__circle-container{padding:0 8px 0 0;-webkit-transform:translate3d(0,50%,0);transform:translate3d(0,50%,0)}.van-step--horizontal:last-child{position:absolute;right:0;width:auto}.van-step--horizontal:last-child .van-step__title{text-align:right;-webkit-transform:none;transform:none}.van-step--horizontal:last-child .van-step__circle-container{right:0;padding:0 0 0 8px;-webkit-transform:translate3d(0,50%,0);transform:translate3d(0,50%,0)}.van-step--horizontal .van-step__circle-container{position:absolute;bottom:6px;z-index:1;padding:0 8px;background-color:#fff;-webkit-transform:translate3d(-50%,50%,0);transform:translate3d(-50%,50%,0)}.van-step--horizontal .van-step__title{display:inline-block;font-size:12px;-webkit-transform:translate3d(-50%,0,0);transform:translate3d(-50%,0,0)}.van-step--horizontal .van-step__line{position:absolute;right:0;bottom:6px;left:0;height:1px;background-color:#eee;-webkit-transform:translate3d(0,50%,0);transform:translate3d(0,50%,0)}.van-step--horizontal.van-step--process{color:#333}.van-step--horizontal.van-step--process .van-step__active{display:block;font-size:12px;line-height:1}.van-step--vertical{padding:10px 10px 10px 0;font-size:14px;line-height:18px}.van-step--vertical::after{border-bottom-width:1px}.van-step--vertical:last-child::after{border-bottom-width:none}.van-step--vertical:first-child::before{position:absolute;top:0;left:-15px;z-index:1;width:1px;height:20px;background-color:#fff;content:''}.van-step--vertical .van-step__active,.van-step--vertical .van-step__circle,.van-step--vertical .van-step__line{position:absolute;top:19px;left:-14px;z-index:2;-webkit-transform:translate3d(-50%,-50%,0);transform:translate3d(-50%,-50%,0)}.van-step--vertical .van-step__active{font-size:12px;line-height:1}.van-step--vertical .van-step__line{z-index:1;width:1px;height:100%;background-color:#eee;-webkit-transform:translate3d(-50%,0,0);transform:translate3d(-50%,0,0)} \ No newline at end of file diff --git a/dist/submit-bar/index.d.ts b/dist/submit-bar/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/submit-bar/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/submit-bar/index.js b/dist/submit-bar/index.js index 6c47d5fe..94b9cea0 100644 --- a/dist/submit-bar/index.js +++ b/dist/submit-bar/index.js @@ -1,40 +1,44 @@ import { VantComponent } from '../common/component'; import { iphonex } from '../mixins/iphonex'; VantComponent({ - mixins: [iphonex], - classes: ['bar-class', 'price-class', 'button-class'], - props: { - tip: null, - type: Number, - price: null, - label: String, - loading: Boolean, - disabled: Boolean, - buttonText: String, - currency: { - type: String, - value: '¥' + mixins: [iphonex], + classes: [ + 'bar-class', + 'price-class', + 'button-class' + ], + props: { + tip: null, + type: Number, + price: null, + label: String, + loading: Boolean, + disabled: Boolean, + buttonText: String, + currency: { + type: String, + value: '¥' + }, + buttonType: { + type: String, + value: 'danger' + } }, - buttonType: { - type: String, - value: 'danger' - } - }, - computed: { - hasPrice: function hasPrice() { - return typeof this.data.price === 'number'; + computed: { + hasPrice() { + return typeof this.data.price === 'number'; + }, + priceStr() { + return (this.data.price / 100).toFixed(2); + }, + tipStr() { + const { tip } = this.data; + return typeof tip === 'string' ? tip : ''; + } }, - priceStr: function priceStr() { - return (this.data.price / 100).toFixed(2); - }, - tipStr: function tipStr() { - var tip = this.data.tip; - return typeof tip === 'string' ? tip : ''; + methods: { + onSubmit(event) { + this.$emit('submit', event.detail); + } } - }, - methods: { - onSubmit: function onSubmit(event) { - this.$emit('submit', event.detail); - } - } -}); \ No newline at end of file +}); diff --git a/dist/swipe-cell/index.d.ts b/dist/swipe-cell/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/swipe-cell/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/swipe-cell/index.js b/dist/swipe-cell/index.js index eb6f8c90..c81a4cbe 100644 --- a/dist/swipe-cell/index.js +++ b/dist/swipe-cell/index.js @@ -1,144 +1,120 @@ import { VantComponent } from '../common/component'; import { touch } from '../mixins/touch'; -var THRESHOLD = 0.15; +const THRESHOLD = 0.15; VantComponent({ - props: { - disabled: Boolean, - leftWidth: { - type: Number, - value: 0 + props: { + disabled: Boolean, + leftWidth: { + type: Number, + value: 0 + }, + rightWidth: { + type: Number, + value: 0 + }, + asyncClose: Boolean }, - rightWidth: { - type: Number, - value: 0 - }, - asyncClose: Boolean - }, - mixins: [touch], - data: { - offset: 0, - draging: false - }, - computed: { - wrapperStyle: function wrapperStyle() { - var _this$data = this.data, - offset = _this$data.offset, - draging = _this$data.draging; - var transform = "translate3d(" + offset + "px, 0, 0)"; - var transition = draging ? 'none' : '.6s cubic-bezier(0.18, 0.89, 0.32, 1)'; - return "\n -webkit-transform: " + transform + ";\n -webkit-transition: " + transition + ";\n transform: " + transform + ";\n transition: " + transition + ";\n "; - } - }, - methods: { - onTransitionend: function onTransitionend() { - this.swipe = false; - }, - open: function open(position) { - var _this$data2 = this.data, - leftWidth = _this$data2.leftWidth, - rightWidth = _this$data2.rightWidth; - var offset = position === 'left' ? leftWidth : -rightWidth; - this.swipeMove(offset); - this.resetSwipeStatus(); - }, - close: function close() { - this.set({ - offset: 0 - }); - }, - resetSwipeStatus: function resetSwipeStatus() { - this.swiping = false; - this.opened = true; - }, - swipeMove: function swipeMove(offset) { - if (offset === void 0) { - offset = 0; - } - - this.set({ - offset: offset - }); - offset && (this.swiping = true); - !offset && (this.opened = false); - }, - swipeLeaveTransition: function swipeLeaveTransition(direction) { - var _this$data3 = this.data, - offset = _this$data3.offset, - leftWidth = _this$data3.leftWidth, - rightWidth = _this$data3.rightWidth; - var threshold = this.opened ? 1 - THRESHOLD : THRESHOLD; // right - - if (direction > 0 && -offset > rightWidth * threshold && rightWidth > 0) { - this.open('right'); // left - } else if (direction < 0 && offset > leftWidth * threshold && leftWidth > 0) { - this.open('left'); - } else { - this.swipeMove(); - } - }, - startDrag: function startDrag(event) { - if (this.data.disabled) { - return; - } - - this.set({ - draging: true - }); - this.touchStart(event); - - if (this.opened) { - this.startX -= this.data.offset; - } - }, - onDrag: function onDrag(event) { - if (this.data.disabled) { - return; - } - - this.touchMove(event); - var deltaX = this.deltaX; - var _this$data4 = this.data, - leftWidth = _this$data4.leftWidth, - rightWidth = _this$data4.rightWidth; - - if (deltaX < 0 && (-deltaX > rightWidth || !rightWidth) || deltaX > 0 && (deltaX > leftWidth || deltaX > 0 && !leftWidth)) { - return; - } - - if (this.direction === 'horizontal') { - this.swipeMove(deltaX); - } - }, - endDrag: function endDrag() { - if (this.data.disabled) { - return; - } - - this.set({ + mixins: [touch], + data: { + offset: 0, draging: false - }); - - if (this.swiping) { - this.swipeLeaveTransition(this.data.offset > 0 ? -1 : 1); - } }, - onClick: function onClick(event) { - var _event$currentTarget$ = event.currentTarget.dataset.key, - position = _event$currentTarget$ === void 0 ? 'outside' : _event$currentTarget$; - this.$emit('click', position); - - if (!this.data.offset) { - return; - } - - if (this.data.asyncClose) { - this.$emit('close', { - position: position, - instance: this - }); - } else { - this.swipeMove(0); - } + computed: { + wrapperStyle() { + const { offset, draging } = this.data; + const transform = `translate3d(${offset}px, 0, 0)`; + const transition = draging ? 'none' : '.6s cubic-bezier(0.18, 0.89, 0.32, 1)'; + return ` + -webkit-transform: ${transform}; + -webkit-transition: ${transition}; + transform: ${transform}; + transition: ${transition}; + `; + } + }, + methods: { + onTransitionend() { + this.swipe = false; + }, + open(position) { + const { leftWidth, rightWidth } = this.data; + const offset = position === 'left' ? leftWidth : -rightWidth; + this.swipeMove(offset); + this.resetSwipeStatus(); + }, + close() { + this.set({ offset: 0 }); + }, + resetSwipeStatus() { + this.swiping = false; + this.opened = true; + }, + swipeMove(offset = 0) { + this.set({ offset }); + offset && (this.swiping = true); + !offset && (this.opened = false); + }, + swipeLeaveTransition(direction) { + const { offset, leftWidth, rightWidth } = this.data; + const threshold = this.opened ? 1 - THRESHOLD : THRESHOLD; + // right + if (direction > 0 && -offset > rightWidth * threshold && rightWidth > 0) { + this.open('right'); + // left + } + else if (direction < 0 && offset > leftWidth * threshold && leftWidth > 0) { + this.open('left'); + } + else { + this.swipeMove(); + } + }, + startDrag(event) { + if (this.data.disabled) { + return; + } + this.set({ draging: true }); + this.touchStart(event); + if (this.opened) { + this.startX -= this.data.offset; + } + }, + onDrag(event) { + if (this.data.disabled) { + return; + } + this.touchMove(event); + const { deltaX } = this; + const { leftWidth, rightWidth } = this.data; + if ((deltaX < 0 && (-deltaX > rightWidth || !rightWidth)) || + (deltaX > 0 && (deltaX > leftWidth || (deltaX > 0 && !leftWidth)))) { + return; + } + if (this.direction === 'horizontal') { + this.swipeMove(deltaX); + } + }, + endDrag() { + if (this.data.disabled) { + return; + } + this.set({ draging: false }); + if (this.swiping) { + this.swipeLeaveTransition(this.data.offset > 0 ? -1 : 1); + } + }, + onClick(event) { + const { key: position = 'outside' } = event.currentTarget.dataset; + this.$emit('click', position); + if (!this.data.offset) { + return; + } + if (this.data.asyncClose) { + this.$emit('close', { position, instance: this }); + } + else { + this.swipeMove(0); + } + } } - } -}); \ No newline at end of file +}); diff --git a/dist/switch-cell/index.d.ts b/dist/switch-cell/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/switch-cell/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/switch-cell/index.js b/dist/switch-cell/index.js index 5b04139b..cd9ec5d1 100644 --- a/dist/switch-cell/index.js +++ b/dist/switch-cell/index.js @@ -1,43 +1,39 @@ import { VantComponent } from '../common/component'; VantComponent({ - field: true, - props: { - value: null, - title: String, - border: Boolean, - checked: Boolean, - loading: Boolean, - disabled: Boolean, - activeColor: String, - inactiveColor: String, - size: { - type: String, - value: '24px' + field: true, + props: { + value: null, + title: String, + border: Boolean, + checked: Boolean, + loading: Boolean, + disabled: Boolean, + activeColor: String, + inactiveColor: String, + size: { + type: String, + value: '24px' + }, + activeValue: { + type: null, + value: true + }, + inactiveValue: { + type: null, + value: false + } }, - activeValue: { - type: null, - value: true + watch: { + checked(value) { + this.set({ value }); + } }, - inactiveValue: { - type: null, - value: false + created() { + this.set({ value: this.data.checked }); + }, + methods: { + onChange(event) { + this.$emit('change', event.detail); + } } - }, - watch: { - checked: function checked(value) { - this.set({ - value: value - }); - } - }, - created: function created() { - this.set({ - value: this.data.checked - }); - }, - methods: { - onChange: function onChange(event) { - this.$emit('change', event.detail); - } - } -}); \ No newline at end of file +}); diff --git a/dist/switch/index.d.ts b/dist/switch/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/switch/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/switch/index.js b/dist/switch/index.js index 03cff2b0..77d1559b 100644 --- a/dist/switch/index.js +++ b/dist/switch/index.js @@ -1,50 +1,43 @@ import { VantComponent } from '../common/component'; VantComponent({ - field: true, - classes: ['node-class'], - props: { - checked: null, - loading: Boolean, - disabled: Boolean, - activeColor: String, - inactiveColor: String, - size: { - type: String, - value: '30px' + field: true, + classes: ['node-class'], + props: { + checked: null, + loading: Boolean, + disabled: Boolean, + activeColor: String, + inactiveColor: String, + size: { + type: String, + value: '30px' + }, + activeValue: { + type: null, + value: true + }, + inactiveValue: { + type: null, + value: false + } }, - activeValue: { - type: null, - value: true + watch: { + checked(value) { + this.set({ value }); + } }, - inactiveValue: { - type: null, - value: false + created() { + this.set({ value: this.data.checked }); + }, + methods: { + onClick() { + const { activeValue, inactiveValue } = this.data; + if (!this.data.disabled && !this.data.loading) { + const checked = this.data.checked === activeValue; + const value = checked ? inactiveValue : activeValue; + this.$emit('input', value); + this.$emit('change', value); + } + } } - }, - watch: { - checked: function checked(value) { - this.set({ - value: value - }); - } - }, - created: function created() { - this.set({ - value: this.data.checked - }); - }, - methods: { - onClick: function onClick() { - var _this$data = this.data, - activeValue = _this$data.activeValue, - inactiveValue = _this$data.inactiveValue; - - if (!this.data.disabled && !this.data.loading) { - var checked = this.data.checked === activeValue; - var value = checked ? inactiveValue : activeValue; - this.$emit('input', value); - this.$emit('change', value); - } - } - } -}); \ No newline at end of file +}); diff --git a/dist/tab/index.d.ts b/dist/tab/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/tab/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/tab/index.js b/dist/tab/index.js index a6c4eeed..c555393c 100644 --- a/dist/tab/index.js +++ b/dist/tab/index.js @@ -1,36 +1,35 @@ import { VantComponent } from '../common/component'; VantComponent({ - relation: { - name: 'tabs', - type: 'ancestor' - }, - props: { - dot: Boolean, - info: null, - title: String, - disabled: Boolean, - titleStyle: String - }, - data: { - width: null, - inited: false, - active: false, - animated: false - }, - watch: { - title: 'update', - disabled: 'update', - dot: 'update', - info: 'update', - titleStyle: 'update' - }, - methods: { - update: function update() { - var parent = this.getRelationNodes('../tabs/index')[0]; - - if (parent) { - parent.updateTabs(); - } + relation: { + name: 'tabs', + type: 'ancestor' + }, + props: { + dot: Boolean, + info: null, + title: String, + disabled: Boolean, + titleStyle: String + }, + data: { + width: null, + inited: false, + active: false, + animated: false + }, + watch: { + title: 'update', + disabled: 'update', + dot: 'update', + info: 'update', + titleStyle: 'update' + }, + methods: { + update() { + const parent = this.getRelationNodes('../tabs/index')[0]; + if (parent) { + parent.updateTabs(); + } + } } - } -}); \ No newline at end of file +}); diff --git a/dist/tab/index.wxml b/dist/tab/index.wxml index 83190318..b90f452a 100644 --- a/dist/tab/index.wxml +++ b/dist/tab/index.wxml @@ -2,7 +2,7 @@ diff --git a/dist/tabbar-item/index.d.ts b/dist/tabbar-item/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/tabbar-item/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/tabbar-item/index.js b/dist/tabbar-item/index.js index 2a833320..d23f9e74 100644 --- a/dist/tabbar-item/index.js +++ b/dist/tabbar-item/index.js @@ -1,37 +1,29 @@ import { VantComponent } from '../common/component'; VantComponent({ - props: { - info: null, - icon: String, - dot: Boolean - }, - relation: { - name: 'tabbar', - type: 'ancestor' - }, - data: { - active: false - }, - methods: { - onClick: function onClick() { - var parent = this.getRelationNodes('../tabbar/index')[0]; - - if (parent) { - parent.onChange(this); - } - - this.$emit('click'); + props: { + info: null, + icon: String, + dot: Boolean }, - setActive: function setActive(_ref) { - var active = _ref.active, - color = _ref.color; - - if (this.data.active !== active) { - this.set({ - active: active, - color: color - }); - } + relation: { + name: 'tabbar', + type: 'ancestor' + }, + data: { + active: false + }, + methods: { + onClick() { + const parent = this.getRelationNodes('../tabbar/index')[0]; + if (parent) { + parent.onChange(this); + } + this.$emit('click'); + }, + setActive({ active, color }) { + if (this.data.active !== active) { + this.set({ active, color }); + } + } } - } -}); \ No newline at end of file +}); diff --git a/dist/tabbar/index.d.ts b/dist/tabbar/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/tabbar/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/tabbar/index.js b/dist/tabbar/index.js index 441625e6..6760597f 100644 --- a/dist/tabbar/index.js +++ b/dist/tabbar/index.js @@ -1,79 +1,63 @@ import { VantComponent } from '../common/component'; import { iphonex } from '../mixins/iphonex'; VantComponent({ - mixins: [iphonex], - relation: { - name: 'tabbar-item', - type: 'descendant', - linked: function linked(target) { - var _this = this; - - this.data.items.push(target); - setTimeout(function () { - _this.setActiveItem(); - }); + mixins: [iphonex], + relation: { + name: 'tabbar-item', + type: 'descendant', + linked(target) { + this.data.items.push(target); + setTimeout(() => { + this.setActiveItem(); + }); + }, + unlinked(target) { + this.data.items = this.data.items.filter(item => item !== target); + setTimeout(() => { + this.setActiveItem(); + }); + } }, - unlinked: function unlinked(target) { - var _this2 = this; - - this.data.items = this.data.items.filter(function (item) { - return item !== target; - }); - setTimeout(function () { - _this2.setActiveItem(); - }); - } - }, - props: { - active: Number, - activeColor: String, - fixed: { - type: Boolean, - value: true + props: { + active: Number, + activeColor: String, + fixed: { + type: Boolean, + value: true + }, + zIndex: { + type: Number, + value: 1 + } }, - zIndex: { - type: Number, - value: 1 - } - }, - data: { - items: [], - currentActive: -1 - }, - watch: { - active: function active(_active) { - this.set({ - currentActive: _active - }); - this.setActiveItem(); - } - }, - created: function created() { - this.set({ - currentActive: this.data.active - }); - }, - methods: { - setActiveItem: function setActiveItem() { - var _this3 = this; - - this.data.items.forEach(function (item, index) { - item.setActive({ - active: index === _this3.data.currentActive, - color: _this3.data.activeColor - }); - }); + data: { + items: [] }, - onChange: function onChange(child) { - var active = this.data.items.indexOf(child); - - if (active !== this.data.currentActive && active !== -1) { - this.$emit('change', active); - this.set({ - currentActive: active - }); - this.setActiveItem(); - } + watch: { + active(active) { + this.currentActive = active; + this.setActiveItem(); + } + }, + created() { + this.currentActive = this.data.active; + }, + methods: { + setActiveItem() { + this.data.items.forEach((item, index) => { + item.setActive({ + active: index === this.currentActive, + color: this.data.activeColor + }); + }); + }, + onChange(child) { + const active = this.data.items.indexOf(child); + if (active !== this.currentActive && active !== -1) { + this.$emit('change', active); + this.currentActive = active; + this.setActiveItem(); + } + } } - } -}); \ No newline at end of file +}); diff --git a/dist/tabs/index.d.ts b/dist/tabs/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/tabs/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/tabs/index.js b/dist/tabs/index.js index bdb44f0c..e994c44f 100644 --- a/dist/tabs/index.js +++ b/dist/tabs/index.js @@ -1,353 +1,312 @@ import { VantComponent } from '../common/component'; import { touch } from '../mixins/touch'; VantComponent({ - mixins: [touch], - relation: { - name: 'tab', - type: 'descendant', - linked: function linked(child) { - this.child.push(child); - this.updateTabs(this.data.tabs.concat(child.data)); + mixins: [touch], + classes: ['nav-class', 'tab-class', 'tab-active-class', 'line-class'], + relation: { + name: 'tab', + type: 'descendant', + linked(child) { + this.child.push(child); + this.updateTabs(this.data.tabs.concat(child.data)); + }, + unlinked(child) { + const index = this.child.indexOf(child); + const { tabs } = this.data; + tabs.splice(index, 1); + this.child.splice(index, 1); + this.updateTabs(tabs); + } }, - unlinked: function unlinked(child) { - var index = this.child.indexOf(child); - var tabs = this.data.tabs; - tabs.splice(index, 1); - this.child.splice(index, 1); - this.updateTabs(tabs); + props: { + color: String, + sticky: Boolean, + animated: Boolean, + swipeable: Boolean, + lineWidth: { + type: Number, + value: -1 + }, + lineHeight: { + type: Number, + value: -1 + }, + active: { + type: Number, + value: 0 + }, + type: { + type: String, + value: 'line' + }, + border: { + type: Boolean, + value: true + }, + duration: { + type: Number, + value: 0.3 + }, + zIndex: { + type: Number, + value: 1 + }, + swipeThreshold: { + type: Number, + value: 4 + }, + offsetTop: { + type: Number, + value: 0 + } + }, + data: { + tabs: [], + lineStyle: '', + scrollLeft: 0, + scrollable: false, + trackStyle: '', + wrapStyle: '', + position: '' + }, + watch: { + swipeThreshold() { + this.set({ + scrollable: this.child.length > this.data.swipeThreshold + }); + }, + color: 'setLine', + lineWidth: 'setLine', + lineHeight: 'setLine', + active: 'setActiveTab', + animated: 'setTrack', + offsetTop: 'setWrapStyle' + }, + beforeCreate() { + this.child = []; + }, + mounted() { + this.setLine(true); + this.setTrack(); + this.scrollIntoView(); + this.getRect('.van-tabs__wrap').then((rect) => { + this.navHeight = rect.height; + this.observerContentScroll(); + }); + }, + destroyed() { + this.createIntersectionObserver().disconnect(); + }, + methods: { + updateTabs(tabs) { + tabs = tabs || this.data.tabs; + this.set({ + tabs, + scrollable: tabs.length > this.data.swipeThreshold + }); + this.setActiveTab(); + }, + trigger(eventName, index) { + this.$emit(eventName, { + index, + title: this.data.tabs[index].title + }); + }, + onTap(event) { + const { index } = event.currentTarget.dataset; + if (this.data.tabs[index].disabled) { + this.trigger('disabled', index); + } + else { + this.trigger('click', index); + this.setActive(index); + } + }, + setActive(active) { + if (active !== this.data.active) { + this.trigger('change', active); + this.set({ active }); + this.setActiveTab(); + } + }, + setLine(skipTransition) { + if (this.data.type !== 'line') { + return; + } + const { color, active, duration, lineWidth, lineHeight } = this.data; + this.getRect('.van-tab', true).then((rects) => { + const rect = rects[active]; + const width = lineWidth !== -1 ? lineWidth : rect.width / 2; + const height = lineHeight !== -1 ? `height: ${lineHeight}px;` : ''; + let left = rects + .slice(0, active) + .reduce((prev, curr) => prev + curr.width, 0); + left += (rect.width - width) / 2; + const transition = skipTransition + ? '' + : `transition-duration: ${duration}s; -webkit-transition-duration: ${duration}s;`; + this.set({ + lineStyle: ` + ${height} + width: ${width}px; + background-color: ${color}; + -webkit-transform: translateX(${left}px); + transform: translateX(${left}px); + ${transition} + ` + }); + }); + }, + setTrack() { + const { animated, active, duration } = this.data; + if (!animated) + return ''; + this.getRect('.van-tabs__content').then((rect) => { + const { width } = rect; + this.set({ + trackStyle: ` + width: ${width * this.child.length}px; + left: ${-1 * active * width}px; + transition: left ${duration}s; + display: -webkit-box; + display: flex; + ` + }); + const props = { width, animated }; + this.child.forEach((item) => { + item.set(props); + }); + }); + }, + setActiveTab() { + this.child.forEach((item, index) => { + const data = { + active: index === this.data.active + }; + if (data.active) { + data.inited = true; + } + if (data.active !== item.data.active) { + item.set(data); + } + }); + this.set({}, () => { + this.setLine(); + this.setTrack(); + this.scrollIntoView(); + }); + }, + // scroll active tab into view + scrollIntoView() { + const { active, scrollable } = this.data; + if (!scrollable) { + return; + } + Promise.all([ + this.getRect('.van-tab', true), + this.getRect('.van-tabs__nav') + ]).then(([tabRects, navRect]) => { + const tabRect = tabRects[active]; + const offsetLeft = tabRects + .slice(0, active) + .reduce((prev, curr) => prev + curr.width, 0); + this.set({ + scrollLeft: offsetLeft - (navRect.width - tabRect.width) / 2 + }); + }); + }, + onTouchStart(event) { + if (!this.data.swipeable) + return; + this.touchStart(event); + }, + onTouchMove(event) { + if (!this.data.swipeable) + return; + this.touchMove(event); + }, + // watch swipe touch end + onTouchEnd() { + if (!this.data.swipeable) + return; + const { active, tabs } = this.data; + const { direction, deltaX, offsetX } = this; + const minSwipeDistance = 50; + if (direction === 'horizontal' && offsetX >= minSwipeDistance) { + if (deltaX > 0 && active !== 0) { + this.setActive(active - 1); + } + else if (deltaX < 0 && active !== tabs.length - 1) { + this.setActive(active + 1); + } + } + }, + setWrapStyle() { + const { offsetTop, position } = this.data; + let wrapStyle; + switch (position) { + case 'top': + wrapStyle = ` + top: ${offsetTop}px; + position: fixed; + `; + break; + case 'bottom': + wrapStyle = ` + top: auto; + bottom: 0; + `; + break; + default: + wrapStyle = ''; + } + // cut down `set` + if (wrapStyle === this.data.wrapStyle) + return; + this.set({ wrapStyle }); + }, + observerContentScroll() { + if (!this.data.sticky) { + return; + } + const { offsetTop } = this.data; + const { windowHeight } = wx.getSystemInfoSync(); + this.createIntersectionObserver().disconnect(); + this.createIntersectionObserver() + .relativeToViewport({ top: -(this.navHeight + offsetTop) }) + .observe('.van-tabs', (res) => { + const { top } = res.boundingClientRect; + if (top > offsetTop) { + return; + } + const position = res.intersectionRatio > 0 ? 'top' : 'bottom'; + this.$emit('scroll', { + scrollTop: top + offsetTop, + isFixed: position === 'top' + }); + this.setPosition(position); + }); + this.createIntersectionObserver() + .relativeToViewport({ bottom: -(windowHeight - 1 - offsetTop) }) + .observe('.van-tabs', (res) => { + const { top, bottom } = res.boundingClientRect; + if (bottom < this.navHeight) { + return; + } + const position = res.intersectionRatio > 0 ? 'top' : ''; + this.$emit('scroll', { + scrollTop: top + offsetTop, + isFixed: position === 'top' + }); + this.setPosition(position); + }); + }, + setPosition(position) { + if (position !== this.data.position) { + this.set({ position }).then(() => { + this.setWrapStyle(); + }); + } + } } - }, - props: { - color: String, - sticky: Boolean, - animated: Boolean, - swipeable: Boolean, - lineWidth: { - type: Number, - value: -1 - }, - lineHeight: { - type: Number, - value: -1 - }, - active: { - type: Number, - value: 0 - }, - type: { - type: String, - value: 'line' - }, - border: { - type: Boolean, - value: true - }, - duration: { - type: Number, - value: 0.3 - }, - zIndex: { - type: Number, - value: 1 - }, - swipeThreshold: { - type: Number, - value: 4 - }, - offsetTop: { - type: Number, - value: 0 - } - }, - data: { - tabs: [], - lineStyle: '', - scrollLeft: 0, - scrollable: false, - trackStyle: '', - wrapStyle: '', - position: '' - }, - watch: { - swipeThreshold: function swipeThreshold() { - this.set({ - scrollable: this.child.length > this.data.swipeThreshold - }); - }, - color: 'setLine', - lineWidth: 'setLine', - lineHeight: 'setLine', - active: 'setActiveTab', - animated: 'setTrack', - offsetTop: 'setWrapStyle' - }, - beforeCreate: function beforeCreate() { - this.child = []; - }, - mounted: function mounted() { - var _this = this; - - this.setLine(true); - this.setTrack(); - this.scrollIntoView(); - this.getRect('.van-tabs__wrap').then(function (rect) { - _this.navHeight = rect.height; - - _this.observerContentScroll(); - }); - }, - destroyed: function destroyed() { - wx.createIntersectionObserver(this).disconnect(); - }, - methods: { - updateTabs: function updateTabs(tabs) { - tabs = tabs || this.data.tabs; - this.set({ - tabs: tabs, - scrollable: tabs.length > this.data.swipeThreshold - }); - this.setActiveTab(); - }, - trigger: function trigger(eventName, index) { - this.$emit(eventName, { - index: index, - title: this.data.tabs[index].title - }); - }, - onTap: function onTap(event) { - var index = event.currentTarget.dataset.index; - - if (this.data.tabs[index].disabled) { - this.trigger('disabled', index); - } else { - this.trigger('click', index); - this.setActive(index); - } - }, - setActive: function setActive(active) { - if (active !== this.data.active) { - this.trigger('change', active); - this.set({ - active: active - }); - this.setActiveTab(); - } - }, - setLine: function setLine(skipTransition) { - var _this2 = this; - - if (this.data.type !== 'line') { - return; - } - - var _this$data = this.data, - color = _this$data.color, - active = _this$data.active, - duration = _this$data.duration, - lineWidth = _this$data.lineWidth, - lineHeight = _this$data.lineHeight; - this.getRect('.van-tab', true).then(function (rects) { - var rect = rects[active]; - var width = lineWidth !== -1 ? lineWidth : rect.width / 2; - var height = lineHeight !== -1 ? "height: " + lineHeight + "px;" : ''; - var left = rects.slice(0, active).reduce(function (prev, curr) { - return prev + curr.width; - }, 0); - left += (rect.width - width) / 2; - var transition = skipTransition ? '' : "transition-duration: " + duration + "s; -webkit-transition-duration: " + duration + "s;"; - - _this2.set({ - lineStyle: "\n " + height + "\n width: " + width + "px;\n background-color: " + color + ";\n -webkit-transform: translateX(" + left + "px);\n transform: translateX(" + left + "px);\n " + transition + "\n " - }); - }); - }, - setTrack: function setTrack() { - var _this3 = this; - - var _this$data2 = this.data, - animated = _this$data2.animated, - active = _this$data2.active, - duration = _this$data2.duration; - if (!animated) return ''; - this.getRect('.van-tabs__content').then(function (rect) { - var width = rect.width; - - _this3.set({ - trackStyle: "\n width: " + width * _this3.child.length + "px;\n left: " + -1 * active * width + "px;\n transition: left " + duration + "s;\n display: -webkit-box;\n display: flex;\n " - }); - - var props = { - width: width, - animated: animated - }; - - _this3.child.forEach(function (item) { - item.set(props); - }); - }); - }, - setActiveTab: function setActiveTab() { - var _this4 = this; - - this.child.forEach(function (item, index) { - var data = { - active: index === _this4.data.active - }; - - if (data.active) { - data.inited = true; - } - - if (data.active !== item.data.active) { - item.set(data); - } - }); - this.set({}, function () { - _this4.setLine(); - - _this4.setTrack(); - - _this4.scrollIntoView(); - }); - }, - // scroll active tab into view - scrollIntoView: function scrollIntoView() { - var _this5 = this; - - var _this$data3 = this.data, - active = _this$data3.active, - scrollable = _this$data3.scrollable; - - if (!scrollable) { - return; - } - - Promise.all([this.getRect('.van-tab', true), this.getRect('.van-tabs__nav')]).then(function (_ref) { - var tabRects = _ref[0], - navRect = _ref[1]; - var tabRect = tabRects[active]; - var offsetLeft = tabRects.slice(0, active).reduce(function (prev, curr) { - return prev + curr.width; - }, 0); - - _this5.set({ - scrollLeft: offsetLeft - (navRect.width - tabRect.width) / 2 - }); - }); - }, - onTouchStart: function onTouchStart(event) { - if (!this.data.swipeable) return; - this.touchStart(event); - }, - onTouchMove: function onTouchMove(event) { - if (!this.data.swipeable) return; - this.touchMove(event); - }, - // watch swipe touch end - onTouchEnd: function onTouchEnd() { - if (!this.data.swipeable) return; - var _this$data4 = this.data, - active = _this$data4.active, - tabs = _this$data4.tabs; - var direction = this.direction, - deltaX = this.deltaX, - offsetX = this.offsetX; - var minSwipeDistance = 50; - - if (direction === 'horizontal' && offsetX >= minSwipeDistance) { - if (deltaX > 0 && active !== 0) { - this.setActive(active - 1); - } else if (deltaX < 0 && active !== tabs.length - 1) { - this.setActive(active + 1); - } - } - }, - setWrapStyle: function setWrapStyle() { - var _ref2 = this.data, - offsetTop = _ref2.offsetTop, - position = _ref2.position; - var wrapStyle; - - switch (position) { - case 'top': - wrapStyle = "\n top: " + offsetTop + "px;\n position: fixed;\n "; - break; - - case 'bottom': - wrapStyle = "\n top: auto;\n bottom: 0;\n "; - break; - - default: - wrapStyle = ''; - } // cut down `set` - - - if (wrapStyle === this.data.wrapStyle) return; - this.set({ - wrapStyle: wrapStyle - }); - }, - observerContentScroll: function observerContentScroll() { - var _this6 = this; - - if (!this.data.sticky) { - return; - } - - var offsetTop = this.data.offsetTop; - - var _wx$getSystemInfoSync = wx.getSystemInfoSync(), - windowHeight = _wx$getSystemInfoSync.windowHeight; - - wx.createIntersectionObserver(this).relativeToViewport({ - top: -this.navHeight - }).observe('.van-tabs', function (res) { - var top = res.boundingClientRect.top; - - if (top > 0) { - return; - } - - var position = res.intersectionRatio > 0 ? 'top' : 'bottom'; - - _this6.$emit('scroll', { - scrollTop: top + offsetTop, - isFixed: position === 'top' - }); - - _this6.setPosition(position); - }); - wx.createIntersectionObserver(this).relativeToViewport({ - bottom: -(windowHeight - 1) - }).observe('.van-tabs', function (res) { - var _res$boundingClientRe = res.boundingClientRect, - top = _res$boundingClientRe.top, - bottom = _res$boundingClientRe.bottom; - - if (bottom < _this6.navHeight) { - return; - } - - var position = res.intersectionRatio > 0 ? 'top' : ''; - - _this6.$emit('scroll', { - scrollTop: top + offsetTop, - isFixed: position === 'top' - }); - - _this6.setPosition(position); - }); - }, - setPosition: function setPosition(position) { - var _this7 = this; - - if (position !== this.data.position) { - this.set({ - position: position - }).then(function () { - _this7.setWrapStyle(); - }); - } - } - } -}); \ No newline at end of file +}); diff --git a/dist/tabs/index.wxml b/dist/tabs/index.wxml index ee8220d6..1618d641 100644 --- a/dist/tabs/index.wxml +++ b/dist/tabs/index.wxml @@ -11,13 +11,13 @@ class="van-tabs__scroll--{{ type }}" style="{{ color ? 'border-color: ' + color : '' }}" > - + diff --git a/dist/tabs/index.wxss b/dist/tabs/index.wxss index e0f8d5dc..03d01a27 100644 --- a/dist/tabs/index.wxss +++ b/dist/tabs/index.wxss @@ -1 +1 @@ -@import '../common/index.wxss';.van-tabs{position:relative;-webkit-tap-highlight-color:transparent}.van-tabs__wrap{position:absolute;top:0;right:0;left:0;display:-webkit-flex;display:flex;background-color:#fff}.van-tabs__wrap--page-top{position:fixed}.van-tabs__wrap--content-bottom{top:auto;bottom:0}.van-tabs__wrap--scrollable .van-tab{-webkit-flex:0 0 22%;flex:0 0 22%}.van-tabs__scroll--card{border:1px solid #f44;border-radius:2px}.van-tabs__nav{position:relative;display:-webkit-flex;display:flex;-webkit-user-select:none;user-select:none}.van-tabs__nav--line{height:100%}.van-tabs__nav--card{height:30px}.van-tabs__nav--card .van-tab{line-height:30px;color:#f44;border-right:1px solid #f44}.van-tabs__nav--card .van-tab:last-child{border-right:none}.van-tabs__nav--card .van-tab.van-tab--active{color:#fff;background-color:#f44}.van-tabs__line{position:absolute;bottom:0;left:0;z-index:1;height:3px;background-color:#f44;border-radius:3px}.van-tabs--line{padding-top:44px}.van-tabs--line .van-tabs__wrap{height:44px}.van-tabs--card{padding-top:30px;margin:0 15px}.van-tabs--card .van-tabs__wrap{height:30px}.van-tabs__content{overflow:hidden}.van-tabs__track{position:relative}.van-tab{position:relative;min-width:0;padding:0 5px;font-size:14px;line-height:44px;color:#7d7e80;text-align:center;cursor:pointer;background-color:#fff;box-sizing:border-box;-webkit-flex:1;flex:1}.van-tab--active{font-weight:500;color:#333}.van-tab--disabled{color:#c9c9c9}.van-tab__title--dot::after{display:inline-block;width:8px;height:8px;vertical-align:middle;background-color:#f44;border-radius:100%;content:''}.van-tab__title__info{position:relative!important;top:-1px!important;display:inline-block;-webkit-transform:translateX(0)!important;transform:translateX(0)!important} \ No newline at end of file +@import '../common/index.wxss';.van-tabs{position:relative;-webkit-tap-highlight-color:transparent}.van-tabs__wrap{position:absolute;top:0;right:0;left:0;display:-webkit-flex;display:flex;background-color:#fff}.van-tabs__wrap--page-top{position:fixed}.van-tabs__wrap--content-bottom{top:auto;bottom:0}.van-tabs__wrap--scrollable .van-tab{-webkit-flex:0 0 22%;flex:0 0 22%}.van-tabs__scroll--card{border:1px solid #f44;border-radius:2px}.van-tabs__nav{position:relative;display:-webkit-flex;display:flex;-webkit-user-select:none;user-select:none}.van-tabs__nav--line{height:100%}.van-tabs__nav--card{height:30px}.van-tabs__nav--card .van-tab{line-height:30px;color:#f44;border-right:1px solid #f44}.van-tabs__nav--card .van-tab:last-child{border-right:none}.van-tabs__nav--card .van-tab.van-tab--active{color:#fff;background-color:#f44}.van-tabs__line{position:absolute;bottom:0;left:0;z-index:1;height:3px;background-color:#f44;border-radius:3px}.van-tabs--line{padding-top:44px}.van-tabs--line .van-tabs__wrap{height:44px}.van-tabs--card{padding-top:30px;margin:0 15px}.van-tabs--card .van-tabs__wrap{height:30px}.van-tabs__content{overflow:hidden}.van-tabs__track{position:relative}.van-tab{position:relative;min-width:0;padding:0 5px;font-size:14px;line-height:44px;color:#7d7e80;text-align:center;cursor:pointer;box-sizing:border-box;-webkit-flex:1;flex:1}.van-tab--active{font-weight:500;color:#333}.van-tab--disabled{color:#c9c9c9}.van-tab__title--dot::after{display:inline-block;width:8px;height:8px;vertical-align:middle;background-color:#f44;border-radius:100%;content:''}.van-tab__title__info{position:relative!important;top:-1px!important;display:inline-block;-webkit-transform:translateX(0)!important;transform:translateX(0)!important} \ No newline at end of file diff --git a/dist/tag/index.d.ts b/dist/tag/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/tag/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/tag/index.js b/dist/tag/index.js index eb24754d..2042ebe2 100644 --- a/dist/tag/index.js +++ b/dist/tag/index.js @@ -1,36 +1,30 @@ import { VantComponent } from '../common/component'; import { RED, BLUE, GREEN } from '../common/color'; -var DEFAULT_COLOR = '#999'; -var COLOR_MAP = { - danger: RED, - primary: BLUE, - success: GREEN +const DEFAULT_COLOR = '#999'; +const COLOR_MAP = { + danger: RED, + primary: BLUE, + success: GREEN }; VantComponent({ - props: { - size: String, - type: String, - mark: Boolean, - color: String, - plain: Boolean, - round: Boolean, - textColor: String - }, - computed: { - style: function style() { - var color = this.data.color || COLOR_MAP[this.data.type] || DEFAULT_COLOR; - var key = this.data.plain ? 'color' : 'background-color'; - var style = { - [key]: color - }; - - if (this.data.textColor) { - style.color = this.data.textColor; - } - - return Object.keys(style).map(function (key) { - return key + ": " + style[key]; - }).join(';'); + props: { + size: String, + type: String, + mark: Boolean, + color: String, + plain: Boolean, + round: Boolean, + textColor: String + }, + computed: { + style() { + const color = this.data.color || COLOR_MAP[this.data.type] || DEFAULT_COLOR; + const key = this.data.plain ? 'color' : 'background-color'; + const style = { [key]: color }; + if (this.data.textColor) { + style.color = this.data.textColor; + } + return Object.keys(style).map(key => `${key}: ${style[key]}`).join(';'); + } } - } -}); \ No newline at end of file +}); diff --git a/dist/toast/index.d.ts b/dist/toast/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/toast/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/toast/index.js b/dist/toast/index.js index 288be8ea..39171e17 100644 --- a/dist/toast/index.js +++ b/dist/toast/index.js @@ -1,34 +1,34 @@ import { VantComponent } from '../common/component'; VantComponent({ - props: { - show: Boolean, - mask: Boolean, - message: String, - forbidClick: Boolean, - zIndex: { - type: Number, - value: 1000 + props: { + show: Boolean, + mask: Boolean, + message: String, + forbidClick: Boolean, + zIndex: { + type: Number, + value: 1000 + }, + type: { + type: String, + value: 'text' + }, + loadingType: { + type: String, + value: 'circular' + }, + position: { + type: String, + value: 'middle' + } }, - type: { - type: String, - value: 'text' - }, - loadingType: { - type: String, - value: 'circular' - }, - position: { - type: String, - value: 'middle' + methods: { + clear() { + this.set({ + show: false + }); + }, + // for prevent touchmove + noop() { } } - }, - methods: { - clear: function clear() { - this.set({ - show: false - }); - }, - // for prevent touchmove - noop: function noop() {} - } -}); \ No newline at end of file +}); diff --git a/dist/toast/toast.d.ts b/dist/toast/toast.d.ts new file mode 100644 index 00000000..b9820368 --- /dev/null +++ b/dist/toast/toast.d.ts @@ -0,0 +1,25 @@ +declare type ToastMessage = string | number; +export declare type ToastOptions = { + show?: boolean; + type?: string; + mask?: boolean; + zIndex?: number; + context?: any; + position?: string; + duration?: number; + selector?: string; + forbidClick?: boolean; + loadingType?: string; + message?: ToastMessage; +}; +export interface Toast { + (message: ToastOptions | ToastMessage, options?: ToastOptions): Weapp.Component; + loading?(options?: ToastOptions | ToastMessage): Weapp.Component; + success?(options?: ToastOptions | ToastMessage): Weapp.Component; + fail?(options?: ToastOptions | ToastMessage): Weapp.Component; + clear?(): void; + setDefaultOptions?(options: ToastOptions): void; + resetDefaultOptions?(): void; +} +declare const Toast: Toast; +export default Toast; diff --git a/dist/toast/toast.js b/dist/toast/toast.js index e42c9142..92b5d55b 100644 --- a/dist/toast/toast.js +++ b/dist/toast/toast.js @@ -1,90 +1,60 @@ -function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } - import { isObj } from '../common/utils'; -var defaultOptions = { - type: 'text', - mask: false, - message: '', - show: true, - zIndex: 1000, - duration: 3000, - position: 'middle', - forbidClick: false, - loadingType: 'circular', - selector: '#van-toast' +const defaultOptions = { + type: 'text', + mask: false, + message: '', + show: true, + zIndex: 1000, + duration: 3000, + position: 'middle', + forbidClick: false, + loadingType: 'circular', + selector: '#van-toast' }; -var queue = []; - -var currentOptions = _extends({}, defaultOptions); - +let queue = []; +let currentOptions = Object.assign({}, defaultOptions); function parseOptions(message) { - return isObj(message) ? message : { - message: message - }; + return isObj(message) ? message : { message }; } - function getContext() { - var pages = getCurrentPages(); - return pages[pages.length - 1]; + const pages = getCurrentPages(); + return pages[pages.length - 1]; } - -var Toast = function Toast(options) { - if (options === void 0) { - options = {}; - } - - options = _extends({}, currentOptions, parseOptions(options)); - var context = options.context || getContext(); - var toast = context.selectComponent(options.selector); - - if (!toast) { - console.warn('未找到 van-toast 节点,请确认 selector 及 context 是否正确'); - return; - } - - delete options.context; - delete options.selector; - queue.push(toast); - toast.set(options); - clearTimeout(toast.timer); - - if (options.duration > 0) { - toast.timer = setTimeout(function () { - toast.clear(); - queue = queue.filter(function (item) { - return item !== toast; - }); - }, options.duration); - } - - return toast; +const Toast = (options = {}) => { + options = Object.assign({}, currentOptions, parseOptions(options)); + const context = options.context || getContext(); + const toast = context.selectComponent(options.selector); + if (!toast) { + console.warn('未找到 van-toast 节点,请确认 selector 及 context 是否正确'); + return; + } + delete options.context; + delete options.selector; + queue.push(toast); + toast.set(options); + clearTimeout(toast.timer); + if (options.duration > 0) { + toast.timer = setTimeout(() => { + toast.clear(); + queue = queue.filter(item => item !== toast); + }, options.duration); + } + return toast; }; - -var createMethod = function createMethod(type) { - return function (options) { - return Toast(_extends({ - type: type - }, parseOptions(options))); - }; -}; - -['loading', 'success', 'fail'].forEach(function (method) { - Toast[method] = createMethod(method); +const createMethod = type => options => Toast(Object.assign({ type }, parseOptions(options))); +['loading', 'success', 'fail'].forEach(method => { + Toast[method] = createMethod(method); }); - -Toast.clear = function () { - queue.forEach(function (toast) { - toast.clear(); - }); - queue = []; +Toast.clear = () => { + queue.forEach(toast => { + toast.clear(); + }); + queue = []; }; - -Toast.setDefaultOptions = function (options) { - Object.assign(currentOptions, options); +Toast.setDefaultOptions = options => { + Object.assign(currentOptions, options); }; - -Toast.resetDefaultOptions = function () { - currentOptions = _extends({}, defaultOptions); +Toast.resetDefaultOptions = () => { + currentOptions = Object.assign({}, defaultOptions); }; - -export default Toast; \ No newline at end of file +export default Toast; diff --git a/dist/transition/index.d.ts b/dist/transition/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/transition/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/transition/index.js b/dist/transition/index.js index c190ee8d..a920f1f2 100644 --- a/dist/transition/index.js +++ b/dist/transition/index.js @@ -1,6 +1,13 @@ import { VantComponent } from '../common/component'; import { transition } from '../mixins/transition'; VantComponent({ - classes: ['enter-class', 'enter-active-class', 'enter-to-class', 'leave-class', 'leave-active-class', 'leave-to-class'], - mixins: [transition(true)] -}); \ No newline at end of file + classes: [ + 'enter-class', + 'enter-active-class', + 'enter-to-class', + 'leave-class', + 'leave-active-class', + 'leave-to-class' + ], + mixins: [transition(true)] +}); diff --git a/dist/tree-select/index.d.ts b/dist/tree-select/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/tree-select/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/tree-select/index.js b/dist/tree-select/index.js index 16853cd0..c9860756 100644 --- a/dist/tree-select/index.js +++ b/dist/tree-select/index.js @@ -1,93 +1,78 @@ import { VantComponent } from '../common/component'; -var ITEM_HEIGHT = 44; +const ITEM_HEIGHT = 44; VantComponent({ - classes: ['main-item-class', 'content-item-class', 'main-active-class', 'content-active-class', 'main-disabled-class', 'content-disabled-class'], - props: { - items: Array, - mainActiveIndex: { - type: Number, - value: 0 + classes: [ + 'main-item-class', + 'content-item-class', + 'main-active-class', + 'content-active-class', + 'main-disabled-class', + 'content-disabled-class' + ], + props: { + items: Array, + mainActiveIndex: { + type: Number, + value: 0 + }, + activeId: { + type: [Number, String] + }, + maxHeight: { + type: Number, + value: 300 + } }, - activeId: { - type: [Number, String] + data: { + subItems: [], + mainHeight: 0, + itemHeight: 0 }, - maxHeight: { - type: Number, - value: 300 + watch: { + items() { + this.updateSubItems().then(() => { + this.updateMainHeight(); + }); + }, + maxHeight() { + this.updateItemHeight(this.data.subItems); + this.updateMainHeight(); + }, + mainActiveIndex: 'updateSubItems' + }, + methods: { + // 当一个子项被选择时 + onSelectItem(event) { + const { item } = event.currentTarget.dataset; + if (!item.disabled) { + this.$emit('click-item', item); + } + }, + // 当一个导航被点击时 + onClickNav(event) { + const { index } = event.currentTarget.dataset; + const item = this.data.items[index]; + if (!item.disabled) { + this.$emit('click-nav', { index }); + } + }, + // 更新子项列表 + updateSubItems() { + const { items, mainActiveIndex } = this.data; + const { children = [] } = items[mainActiveIndex] || {}; + this.updateItemHeight(children); + return this.set({ subItems: children }); + }, + // 更新组件整体高度,根据最大高度和当前组件需要展示的高度来决定 + updateMainHeight() { + const { items = [], subItems = [] } = this.data; + const maxHeight = Math.max(items.length * ITEM_HEIGHT, subItems.length * ITEM_HEIGHT); + this.set({ mainHeight: Math.min(maxHeight, this.data.maxHeight) }); + }, + // 更新子项列表高度,根据可展示的最大高度和当前子项列表的高度决定 + updateItemHeight(subItems) { + const itemHeight = Math.min(subItems.length * ITEM_HEIGHT, this.data.maxHeight); + return this.set({ itemHeight }); + } } - }, - data: { - subItems: [], - mainHeight: 0, - itemHeight: 0 - }, - watch: { - items: function items() { - var _this = this; - - this.updateSubItems().then(function () { - _this.updateMainHeight(); - }); - }, - maxHeight: function maxHeight() { - this.updateItemHeight(this.data.subItems); - this.updateMainHeight(); - }, - mainActiveIndex: 'updateSubItems' - }, - methods: { - // 当一个子项被选择时 - onSelectItem: function onSelectItem(event) { - var item = event.currentTarget.dataset.item; - - if (!item.disabled) { - this.$emit('click-item', item); - } - }, - // 当一个导航被点击时 - onClickNav: function onClickNav(event) { - var index = event.currentTarget.dataset.index; - var item = this.data.items[index]; - - if (!item.disabled) { - this.$emit('click-nav', { - index: index - }); - } - }, - // 更新子项列表 - updateSubItems: function updateSubItems() { - var _this$data = this.data, - items = _this$data.items, - mainActiveIndex = _this$data.mainActiveIndex; - - var _ref = items[mainActiveIndex] || {}, - _ref$children = _ref.children, - children = _ref$children === void 0 ? [] : _ref$children; - - this.updateItemHeight(children); - return this.set({ - subItems: children - }); - }, - // 更新组件整体高度,根据最大高度和当前组件需要展示的高度来决定 - updateMainHeight: function updateMainHeight() { - var _this$data2 = this.data, - _this$data2$items = _this$data2.items, - items = _this$data2$items === void 0 ? [] : _this$data2$items, - _this$data2$subItems = _this$data2.subItems, - subItems = _this$data2$subItems === void 0 ? [] : _this$data2$subItems; - var maxHeight = Math.max(items.length * ITEM_HEIGHT, subItems.length * ITEM_HEIGHT); - this.set({ - mainHeight: Math.min(maxHeight, this.data.maxHeight) - }); - }, - // 更新子项列表高度,根据可展示的最大高度和当前子项列表的高度决定 - updateItemHeight: function updateItemHeight(subItems) { - var itemHeight = Math.min(subItems.length * ITEM_HEIGHT, this.data.maxHeight); - return this.set({ - itemHeight: itemHeight - }); - } - } -}); \ No newline at end of file +});