[build] 0.5.7

This commit is contained in:
rex-zsd 2019-03-09 12:30:26 +08:00
parent fdb170ea3e
commit 95f77bf50d
141 changed files with 3548 additions and 3913 deletions

1
dist/action-sheet/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -1,42 +1,41 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { iphonex } from '../mixins/iphonex'; import { iphonex } from '../mixins/iphonex';
VantComponent({ VantComponent({
mixins: [iphonex], mixins: [iphonex],
props: { props: {
show: Boolean, show: Boolean,
title: String, title: String,
cancelText: String, cancelText: String,
zIndex: { zIndex: {
type: Number, type: Number,
value: 100 value: 100
},
actions: {
type: Array,
value: []
},
overlay: {
type: Boolean,
value: true
},
closeOnClickOverlay: {
type: Boolean,
value: true
}
}, },
actions: { methods: {
type: Array, onSelect(event) {
value: [] const { index } = event.currentTarget.dataset;
}, const item = this.data.actions[index];
overlay: { if (item && !item.disabled && !item.loading) {
type: Boolean, this.$emit('select', item);
value: true }
}, },
closeOnClickOverlay: { onCancel() {
type: Boolean, this.$emit('cancel');
value: true },
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');
}
}
});

1
dist/area/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

364
dist/area/index.js vendored
View File

@ -1,208 +1,170 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
classes: ['active-class', 'toolbar-class', 'column-class'], classes: ['active-class', 'toolbar-class', 'column-class'],
props: { props: {
title: String, title: String,
value: String, value: String,
loading: Boolean, loading: Boolean,
cancelButtonText: String, cancelButtonText: String,
confirmButtonText: String, confirmButtonText: String,
itemHeight: { itemHeight: {
type: Number, type: Number,
value: 44 value: 44
}, },
visibleItemCount: { visibleItemCount: {
type: Number, type: Number,
value: 5 value: 5
}, },
columnsNum: { columnsNum: {
type: [String, Number], type: [String, Number],
value: 3 value: 3
}, },
areaList: { areaList: {
type: Object, type: Object,
value: {} 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';
} }
result = result.filter(function (item) {
return item.code.indexOf(code) === 0;
});
}
return result;
}, },
getIndex: function getIndex(type, code) { data: {
var compareNum = type === 'province' ? 2 : type === 'city' ? 4 : 6; columns: [{ values: [] }, { values: [] }, { values: [] }],
var list = this.getList(type, code.slice(0, compareNum - 2)); // oversea code displayColumns: [{ values: [] }, { values: [] }, { values: [] }]
},
if (code[0] === '9' && type === 'province') { watch: {
compareNum = 1; value(value) {
} this.code = value;
this.setValues();
code = code.slice(0, compareNum); },
areaList: 'setValues',
for (var i = 0; i < list.length; i++) { columnsNum(value) {
if (list[i].code.slice(0, compareNum) === code) { this.set({
return i; displayColumns: this.data.columns.slice(0, +value)
});
} }
}
return 0;
}, },
setValues: function setValues() { methods: {
var _this2 = this; getPicker() {
if (this.picker == null) {
var county = this.getConfig('county'); this.picker = this.selectComponent('.van-area__picker');
var code = this.code || Object.keys(county)[0] || ''; }
var province = this.getList('province'); return this.picker;
var city = this.getList('city', code.slice(0, 2)); },
var picker = this.getPicker(); onCancel(event) {
this.emit('cancel', event.detail);
if (!picker) { },
return; onConfirm(event) {
} this.emit('confirm', event.detail);
},
var stack = []; emit(type, detail) {
stack.push(picker.setColumnValues(0, province, false)); detail.values = detail.value;
stack.push(picker.setColumnValues(1, city, false)); delete detail.value;
this.$emit(type, detail);
if (city.length && code.slice(2, 4) === '00') { },
; onChange(event) {
code = city[0].code; const { index, picker, value } = event.detail;
} this.code = value[index].code;
this.setValues().then(() => {
stack.push(picker.setColumnValues(2, this.getList('county', code.slice(0, 4)), false)); this.$emit('change', {
return Promise.all(stack).then(function () { picker,
return picker.setIndexes([_this2.getIndex('province', code), _this2.getIndex('city', code), _this2.getIndex('county', code)]); values: picker.getValues(),
}).catch(function () {}); index
}, });
getValues: function getValues() { });
var picker = this.getPicker(); },
return picker ? picker.getValues().filter(function (value) { getConfig(type) {
return !!value; const { areaList } = this.data;
}) : []; return (areaList && areaList[`${type}_list`]) || {};
}, },
getDetail: function getDetail() { getList(type, code) {
var values = this.getValues(); let result = [];
var area = { if (type !== 'province' && !code) {
code: '', return result;
country: '', }
province: '', const list = this.getConfig(type);
city: '', result = Object.keys(list).map(code => ({
county: '' code,
}; name: list[code]
}));
if (!values.length) { if (code) {
return area; // oversea code
} if (code[0] === '9' && type === 'city') {
code = '9';
var names = values.map(function (item) { }
return item.name; result = result.filter(item => item.code.indexOf(code) === 0);
}); }
area.code = values[values.length - 1].code; return result;
},
if (area.code[0] === '9') { getIndex(type, code) {
area.country = names[1] || ''; let compareNum = type === 'province' ? 2 : type === 'city' ? 4 : 6;
area.province = names[2] || ''; const list = this.getList(type, code.slice(0, compareNum - 2));
} else { // oversea code
area.province = names[0] || ''; if (code[0] === '9' && type === 'province') {
area.city = names[1] || ''; compareNum = 1;
area.county = names[2] || ''; }
} code = code.slice(0, compareNum);
for (let i = 0; i < list.length; i++) {
return area; if (list[i].code.slice(0, compareNum) === code) {
}, return i;
reset: function reset() { }
this.code = ''; }
return this.setValues(); 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();
}
} }
} });
});

1
dist/badge-group/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -1,55 +1,49 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { isNumber } from '../common/utils'; import { isNumber } from '../common/utils';
VantComponent({ VantComponent({
relation: { relation: {
name: 'badge', name: 'badge',
type: 'descendant', type: 'descendant',
linked: function linked(target) { linked(target) {
this.badges.push(target); this.badges.push(target);
this.setActive(); this.setActive();
},
unlinked(target) {
this.badges = this.badges.filter(item => item !== target);
this.setActive();
}
}, },
unlinked: function unlinked(target) { props: {
this.badges = this.badges.filter(function (item) { active: {
return item !== target; type: Number,
}); value: 0
this.setActive(); }
},
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;
}
}
}
});

1
dist/badge/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

39
dist/badge/index.js vendored
View File

@ -1,25 +1,22 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
relation: { relation: {
type: 'ancestor', type: 'ancestor',
name: 'badge-group' 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);
}
}, },
setActive: function setActive(active) { props: {
this.set({ info: null,
active: active title: String
}); },
methods: {
onClick() {
const group = this.getRelationNodes('../badge-group/index')[0];
if (group) {
group.setActive(this);
}
},
setActive(active) {
this.set({ active });
}
} }
} });
});

1
dist/button/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

58
dist/button/index.js vendored
View File

@ -2,34 +2,34 @@ import { VantComponent } from '../common/component';
import { button } from '../mixins/button'; import { button } from '../mixins/button';
import { openType } from '../mixins/open-type'; import { openType } from '../mixins/open-type';
VantComponent({ VantComponent({
mixins: [button, openType], mixins: [button, openType],
classes: ['hover-class', 'loading-class'], classes: ['hover-class', 'loading-class'],
props: { props: {
plain: Boolean, plain: Boolean,
block: Boolean, block: Boolean,
round: Boolean, round: Boolean,
square: Boolean, square: Boolean,
loading: Boolean, loading: Boolean,
disabled: Boolean, disabled: Boolean,
loadingText: String, loadingText: String,
type: { type: {
type: String, type: String,
value: 'default' value: 'default'
},
size: {
type: String,
value: 'normal'
},
loadingSize: {
type: String,
value: '20px'
}
}, },
size: { methods: {
type: String, onClick() {
value: 'normal' if (!this.data.disabled && !this.data.loading) {
}, this.$emit('click');
loadingSize: { }
type: String, }
value: '20px'
} }
}, });
methods: {
onClick: function onClick() {
if (!this.data.disabled && !this.data.loading) {
this.$emit('click');
}
}
}
});

1
dist/card/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

59
dist/card/index.js vendored
View File

@ -1,31 +1,38 @@
import { link } from '../mixins/link'; import { link } from '../mixins/link';
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
classes: ['num-class', 'desc-class', 'thumb-class', 'title-class', 'price-class', 'origin-price-class'], classes: [
mixins: [link], 'num-class',
props: { 'desc-class',
tag: String, 'thumb-class',
num: String, 'title-class',
desc: String, 'price-class',
thumb: String, 'origin-price-class',
title: String, ],
price: String, mixins: [link],
centered: Boolean, props: {
lazyLoad: Boolean, tag: String,
thumbLink: String, num: String,
originPrice: String, desc: String,
thumbMode: { thumb: String,
type: String, title: String,
value: 'aspectFit' price: String,
centered: Boolean,
lazyLoad: Boolean,
thumbLink: String,
originPrice: String,
thumbMode: {
type: String,
value: 'aspectFit'
},
currency: {
type: String,
value: '¥'
}
}, },
currency: { methods: {
type: String, onClickThumb() {
value: '¥' this.jumpLink('thumbLink');
}
} }
}, });
methods: {
onClickThumb: function onClickThumb() {
this.jumpLink('thumbLink');
}
}
});

1
dist/cell-group/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -1,9 +1,9 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
props: { props: {
border: { border: {
type: Boolean, type: Boolean,
value: true value: true
}
} }
} });
});

1
dist/cell/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

58
dist/cell/index.js vendored
View File

@ -1,30 +1,36 @@
import { link } from '../mixins/link'; import { link } from '../mixins/link';
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
classes: ['title-class', 'label-class', 'value-class', 'right-icon-class', 'hover-class'], classes: [
mixins: [link], 'title-class',
props: { 'label-class',
title: null, 'value-class',
value: null, 'right-icon-class',
icon: String, 'hover-class'
size: String, ],
label: String, mixins: [link],
center: Boolean, props: {
isLink: Boolean, title: null,
required: Boolean, value: null,
clickable: Boolean, icon: String,
titleWidth: String, size: String,
customStyle: String, label: String,
arrowDirection: String, center: Boolean,
border: { isLink: Boolean,
type: Boolean, required: Boolean,
value: true 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();
}
}
});

1
dist/checkbox-group/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -1,40 +1,34 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
field: true, field: true,
relation: { relation: {
name: 'checkbox', name: 'checkbox',
type: 'descendant', type: 'descendant',
linked: function linked(target) { linked(target) {
var _this$data = this.data, const { value, disabled } = this.data;
value = _this$data.value, target.set({
disabled = _this$data.disabled; value: value.indexOf(target.data.name) !== -1,
target.set({ disabled: disabled || target.data.disabled
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
});
});
}, },
disabled: function disabled(_disabled) { props: {
var children = this.getRelationNodes('../checkbox/index'); max: Number,
children.forEach(function (child) { value: Array,
child.set({ disabled: Boolean
disabled: _disabled || child.data.disabled },
}); 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 });
});
}
} }
} });
});

1
dist/checkbox/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

131
dist/checkbox/index.js vendored
View File

@ -1,70 +1,67 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
field: true, field: true,
relation: { relation: {
name: 'checkbox-group', name: 'checkbox-group',
type: 'ancestor' type: 'ancestor'
}, },
classes: ['icon-class', 'label-class'], classes: ['icon-class', 'label-class'],
props: { props: {
value: null, value: null,
disabled: Boolean, disabled: Boolean,
useIconSlot: Boolean, useIconSlot: Boolean,
checkedColor: String, checkedColor: String,
labelPosition: String, labelPosition: String,
labelDisabled: Boolean, labelDisabled: Boolean,
shape: { shape: {
type: String, type: String,
value: 'round' 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);
}
}
}
}
});

1
dist/col/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

43
dist/col/index.js vendored
View File

@ -1,26 +1,23 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
relation: { relation: {
name: 'row', name: 'row',
type: 'ancestor' type: 'ancestor'
}, },
props: { props: {
span: Number, span: Number,
offset: Number offset: Number
}, },
data: { data: {
style: '' style: ''
}, },
methods: { methods: {
setGutter: function setGutter(gutter) { setGutter(gutter) {
var padding = gutter / 2 + "px"; const padding = `${gutter / 2}px`;
var style = gutter ? "padding-left: " + padding + "; padding-right: " + padding + ";" : ''; const style = gutter ? `padding-left: ${padding}; padding-right: ${padding};` : '';
if (style !== this.data.style) {
if (style !== this.data.style) { this.set({ style });
this.set({ }
style: style }
});
}
} }
} });
});

1
dist/collapse-item/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -1,105 +1,91 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
classes: ['title-class', 'content-class'], classes: ['title-class', 'content-class'],
relation: { relation: {
name: 'collapse', name: 'collapse',
type: 'ancestor', type: 'ancestor',
linked: function linked(parent) { linked(parent) {
this.parent = 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);
});
} }
});
}, },
onClick: function onClick() { props: {
if (this.data.disabled) { name: null,
return; title: null,
} value: null,
icon: String,
var _this$data = this.data, label: String,
name = _this$data.name, disabled: Boolean,
expanded = _this$data.expanded; border: {
var index = this.parent.data.items.indexOf(this); type: Boolean,
var currentName = name == null ? index : name; value: true
this.parent.switch(currentName, !expanded); },
isLink: {
type: Boolean,
value: true
}
}, },
onTransitionEnd: function onTransitionEnd() { data: {
if (this.data.expanded) { contentHeight: 0,
this.set({ expanded: false
contentHeight: 'auto' },
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'
});
}
}
} }
} });
});

1
dist/collapse/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -1,51 +1,48 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
relation: { relation: {
name: 'collapse-item', name: 'collapse-item',
type: 'descendant', type: 'descendant',
linked: function linked(child) { linked(child) {
this.set({ this.set({
items: [].concat(this.data.items, [child]) items: [...this.data.items, child]
}, function () { }, () => {
child.updateExpanded(); child.updateExpanded();
}); });
} }
},
props: {
accordion: Boolean,
value: null
},
data: {
items: []
},
watch: {
value: function value() {
this.data.items.forEach(function (child) {
child.updateExpanded();
});
}, },
accordion: function accordion() { props: {
this.data.items.forEach(function (child) { accordion: Boolean,
child.updateExpanded(); 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);
}
}
});

3
dist/common/color.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
export declare const RED = "#f44";
export declare const BLUE = "#1989fa";
export declare const GREEN = "#07c160";

View File

@ -1,3 +1,3 @@
export var RED = '#f44'; export const RED = '#f44';
export var BLUE = '#1989fa'; export const BLUE = '#1989fa';
export var GREEN = '#07c160'; export const GREEN = '#07c160';

2
dist/common/component.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
declare function VantComponent<Data, Props, Watch, Methods, Computed>(vantOptions?: VantComponentOptions<Data, Props, Watch, Methods, Computed, CombinedComponentInstance<Data, Props, Watch, Methods, Computed>>): void;
export { VantComponent };

View File

@ -1,59 +1,48 @@
import { basic } from '../mixins/basic'; import { basic } from '../mixins/basic';
import { observe } from '../mixins/observer/index'; import { observe } from '../mixins/observer/index';
function mapKeys(source, target, map) { function mapKeys(source, target, map) {
Object.keys(map).forEach(function (key) { Object.keys(map).forEach(key => {
if (source[key]) { if (source[key]) {
target[map[key]] = 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
}); });
} // 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);
} }
function VantComponent(vantOptions = {}) {
export { VantComponent }; 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 };

5
dist/common/utils.d.ts vendored Normal file
View File

@ -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 };

16
dist/common/utils.js vendored
View File

@ -1,18 +1,14 @@
function isDef(value) { function isDef(value) {
return value !== undefined && value !== null; return value !== undefined && value !== null;
} }
function isObj(x) { function isObj(x) {
var type = typeof x; const type = typeof x;
return x !== null && (type === 'object' || type === 'function'); return x !== null && (type === 'object' || type === 'function');
} }
function isNumber(value) { function isNumber(value) {
return /^\d+$/.test(value); return /^\d+$/.test(value);
} }
function range(num, min, max) { 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 };
export { isObj, isDef, isNumber, range };

1
dist/datetime-picker/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -1,355 +1,295 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { isDef } from '../common/utils'; import { isDef } from '../common/utils';
var currentYear = new Date().getFullYear(); const currentYear = new Date().getFullYear();
function isValidDate(date) { function isValidDate(date) {
return isDef(date) && !isNaN(new Date(date).getTime()); return isDef(date) && !isNaN(new Date(date).getTime());
} }
function range(num, min, max) { function range(num, min, max) {
return Math.min(Math.max(num, min), max); return Math.min(Math.max(num, min), max);
} }
function padZero(val) { function padZero(val) {
return ("00" + val).slice(-2); return `00${val}`.slice(-2);
} }
function times(n, iteratee) { function times(n, iteratee) {
var index = -1; let index = -1;
var result = Array(n); const result = Array(n);
while (++index < n) {
while (++index < n) { result[index] = iteratee(index);
result[index] = iteratee(index); }
} return result;
return result;
} }
function getTrueValue(formattedValue) { function getTrueValue(formattedValue) {
if (!formattedValue) return; if (!formattedValue)
return;
while (isNaN(parseInt(formattedValue, 10))) { while (isNaN(parseInt(formattedValue, 10))) {
formattedValue = formattedValue.slice(1); formattedValue = formattedValue.slice(1);
} }
return parseInt(formattedValue, 10);
return parseInt(formattedValue, 10);
} }
function getMonthEndDay(year, month) { function getMonthEndDay(year, month) {
return 32 - new Date(year, month - 1, 32).getDate(); return 32 - new Date(year, month - 1, 32).getDate();
} }
VantComponent({ VantComponent({
props: { props: {
value: null, value: null,
title: String, title: String,
loading: Boolean, loading: Boolean,
itemHeight: { itemHeight: {
type: Number, type: Number,
value: 44 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: { data: {
type: Number, innerValue: Date.now(),
value: 5 columns: []
}, },
confirmButtonText: { watch: {
type: String, value(val) {
value: '确认' const { data } = this;
}, val = this.correctValue(val);
cancelButtonText: { const isEqual = val === data.innerValue;
type: String, if (!isEqual) {
value: '取消' this.updateColumnValue(val).then(() => {
}, this.$emit('input', val);
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();
} }
} },
} type: 'updateColumns',
} minHour: 'updateColumns',
maxHour: 'updateColumns',
return { minMinute: 'updateColumns',
[type + "Year"]: year, maxMinute: 'updateColumns'
[type + "Month"]: month,
[type + "Date"]: date,
[type + "Hour"]: hour,
[type + "Minute"]: minute
};
}, },
onCancel: function onCancel() { methods: {
this.$emit('cancel'); 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() { created() {
this.$emit('confirm', this.data.innerValue); const innerValue = this.correctValue(this.data.value);
}, this.updateColumnValue(innerValue).then(() => {
onChange: function onChange() { this.$emit('input', innerValue);
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: function created() {
var _this4 = this;
var innerValue = this.correctValue(this.data.value);
this.updateColumnValue(innerValue).then(function () {
_this4.$emit('input', innerValue);
});
}
});

42
dist/dialog/dialog.d.ts vendored Normal file
View File

@ -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<DialogAction>;
alert?: (options: DialogOptions) => Promise<DialogAction>;
confirm?: (options: DialogOptions) => Promise<DialogAction>;
close?: () => void;
stopLoading?: () => void;
install?: () => void;
setDefaultOptions?: (options: DialogOptions) => void;
resetDefaultOptions?: () => void;
defaultOptions?: DialogOptions;
currentOptions?: DialogOptions;
}
declare const Dialog: Dialog;
export default Dialog;

112
dist/dialog/dialog.js vendored
View File

@ -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); } let queue = [];
var queue = [];
function getContext() { function getContext() {
var pages = getCurrentPages(); const pages = getCurrentPages();
return pages[pages.length - 1]; return pages[pages.length - 1];
} }
const Dialog = options => {
var Dialog = function Dialog(options) { options = Object.assign({}, Dialog.currentOptions, options);
options = _extends({}, Dialog.currentOptions, options); return new Promise((resolve, reject) => {
return new Promise(function (resolve, reject) { const context = options.context || getContext();
var context = options.context || getContext(); const dialog = context.selectComponent(options.selector);
var dialog = context.selectComponent(options.selector); delete options.selector;
delete options.selector; if (dialog) {
dialog.set(Object.assign({ onCancel: reject, onConfirm: resolve }, options));
if (dialog) { queue.push(dialog);
dialog.set(_extends({ }
onCancel: reject, else {
onConfirm: resolve console.warn('未找到 van-dialog 节点,请确认 selector 及 context 是否正确');
}, options)); }
queue.push(dialog); });
} else {
console.warn('未找到 van-dialog 节点,请确认 selector 及 context 是否正确');
}
});
}; };
Dialog.defaultOptions = { Dialog.defaultOptions = {
show: true, show: true,
title: '', title: '',
message: '', message: '',
zIndex: 100, zIndex: 100,
overlay: true, overlay: true,
asyncClose: false, asyncClose: false,
messageAlign: '', messageAlign: '',
transition: 'scale', transition: 'scale',
selector: '#van-dialog', selector: '#van-dialog',
confirmButtonText: '确认', confirmButtonText: '确认',
cancelButtonText: '取消', cancelButtonText: '取消',
showConfirmButton: true, showConfirmButton: true,
showCancelButton: false, showCancelButton: false,
closeOnClickOverlay: false, closeOnClickOverlay: false,
confirmButtonOpenType: '' confirmButtonOpenType: ''
}; };
Dialog.alert = Dialog; Dialog.alert = Dialog;
Dialog.confirm = options => Dialog(Object.assign({ showCancelButton: true }, options));
Dialog.confirm = function (options) { Dialog.close = () => {
return Dialog(_extends({ queue.forEach(dialog => {
showCancelButton: true dialog.close();
}, options)); });
queue = [];
}; };
Dialog.stopLoading = () => {
Dialog.close = function () { queue.forEach(dialog => {
queue.forEach(function (dialog) { dialog.stopLoading();
dialog.close(); });
});
queue = [];
}; };
Dialog.setDefaultOptions = options => {
Dialog.stopLoading = function () { Object.assign(Dialog.currentOptions, options);
queue.forEach(function (dialog) {
dialog.stopLoading();
});
}; };
Dialog.resetDefaultOptions = () => {
Dialog.setDefaultOptions = function (options) { Dialog.currentOptions = Object.assign({}, Dialog.defaultOptions);
Object.assign(Dialog.currentOptions, options);
}; };
Dialog.resetDefaultOptions = function () {
Dialog.currentOptions = _extends({}, Dialog.defaultOptions);
};
Dialog.resetDefaultOptions(); Dialog.resetDefaultOptions();
export default Dialog; export default Dialog;

1
dist/dialog/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

183
dist/dialog/index.js vendored
View File

@ -2,100 +2,95 @@ import { VantComponent } from '../common/component';
import { button } from '../mixins/button'; import { button } from '../mixins/button';
import { openType } from '../mixins/open-type'; import { openType } from '../mixins/open-type';
VantComponent({ VantComponent({
mixins: [button, openType], mixins: [button, openType],
props: { props: {
show: Boolean, show: Boolean,
title: String, title: String,
message: String, message: String,
useSlot: Boolean, useSlot: Boolean,
asyncClose: Boolean, asyncClose: Boolean,
messageAlign: String, messageAlign: String,
showCancelButton: Boolean, showCancelButton: Boolean,
closeOnClickOverlay: Boolean, closeOnClickOverlay: Boolean,
confirmButtonOpenType: String, confirmButtonOpenType: String,
zIndex: { zIndex: {
type: Number, type: Number,
value: 2000 value: 2000
}, },
confirmButtonText: { confirmButtonText: {
type: String, type: String,
value: '确认' value: '确认'
}, },
cancelButtonText: { cancelButtonText: {
type: String, type: String,
value: '取消' value: '取消'
}, },
showConfirmButton: { showConfirmButton: {
type: Boolean, type: Boolean,
value: true value: true
}, },
overlay: { overlay: {
type: Boolean, type: Boolean,
value: true value: true
}, },
transition: { transition: {
type: String, type: String,
value: 'scale' 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
} }
});
}, },
onClose: function onClose(action) { data: {
if (!this.data.asyncClose) { loading: {
this.close(); confirm: false,
} cancel: false
}
this.$emit('close', action); //把 dialog 实例传递出去,可以通过 stopLoading() 在外部关闭按钮的 loading },
watch: {
this.$emit(action, { show(show) {
dialog: this !show && this.stopLoading();
}); }
var callback = this.data[action === 'confirm' ? 'onConfirm' : 'onCancel']; },
methods: {
if (callback) { onConfirm() {
callback(this); 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);
}
}
} }
} });
});

1
dist/field/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

273
dist/field/index.js vendored
View File

@ -1,155 +1,130 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
field: true, field: true,
classes: ['input-class'], classes: ['input-class'],
props: { props: {
icon: String, size: String,
label: String, icon: String,
error: Boolean, label: String,
fixed: Boolean, error: Boolean,
focus: Boolean, fixed: Boolean,
center: Boolean, focus: Boolean,
isLink: Boolean, center: Boolean,
leftIcon: String, isLink: Boolean,
disabled: Boolean, leftIcon: String,
autosize: Boolean, disabled: Boolean,
readonly: Boolean, autosize: Boolean,
required: Boolean, readonly: Boolean,
iconClass: String, required: Boolean,
clearable: Boolean, iconClass: String,
inputAlign: String, clearable: Boolean,
customClass: String, inputAlign: String,
confirmType: String, customClass: String,
confirmHold: Boolean, confirmType: String,
errorMessage: String, confirmHold: Boolean,
placeholder: String, errorMessage: String,
customStyle: String, placeholder: String,
useIconSlot: Boolean, customStyle: String,
useButtonSlot: Boolean, useIconSlot: Boolean,
showConfirmBar: { useButtonSlot: Boolean,
type: Boolean, showConfirmBar: {
value: true 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, data: {
adjustPosition: { showClear: false
type: Boolean,
value: true
}, },
cursorSpacing: { beforeCreate() {
type: Number, this.focused = false;
value: 50
}, },
maxlength: { methods: {
type: Number, onInput(event) {
value: -1 const { value = '' } = event.detail || {};
}, this.set({
type: { value,
type: String, showClear: this.getShowClear(value)
value: 'text' }, () => {
}, this.emitChange(value);
border: { });
type: Boolean, },
value: true onFocus(event) {
}, const { value = '', height = 0 } = event.detail || {};
titleWidth: { this.$emit('focus', { value, height });
type: String, this.focused = true;
value: '90px' 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);
}
}
});

View File

@ -10,6 +10,7 @@
custom-style="{{ customStyle }}" custom-style="{{ customStyle }}"
title-width="{{ titleWidth }}" title-width="{{ titleWidth }}"
custom-class="van-field" custom-class="van-field"
size="{{ size }}"
> >
<slot name="left-icon" slot="icon" /> <slot name="left-icon" slot="icon" />
<slot name="label" slot="title" /> <slot name="label" slot="title" />

1
dist/goods-action-button/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -3,20 +3,20 @@ import { link } from '../mixins/link';
import { button } from '../mixins/button'; import { button } from '../mixins/button';
import { openType } from '../mixins/open-type'; import { openType } from '../mixins/open-type';
VantComponent({ VantComponent({
mixins: [link, button, openType], mixins: [link, button, openType],
props: { props: {
text: String, text: String,
loading: Boolean, loading: Boolean,
disabled: Boolean, disabled: Boolean,
type: { type: {
type: String, type: String,
value: 'danger' value: 'danger'
}
},
methods: {
onClick(event) {
this.$emit('click', event.detail);
this.jumpLink();
}
} }
}, });
methods: {
onClick: function onClick(event) {
this.$emit('click', event.detail);
this.jumpLink();
}
}
});

1
dist/goods-action-icon/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -3,17 +3,17 @@ import { link } from '../mixins/link';
import { button } from '../mixins/button'; import { button } from '../mixins/button';
import { openType } from '../mixins/open-type'; import { openType } from '../mixins/open-type';
VantComponent({ VantComponent({
classes: ['icon-class', 'text-class'], classes: ['icon-class', 'text-class'],
mixins: [link, button, openType], mixins: [link, button, openType],
props: { props: {
text: String, text: String,
info: String, info: String,
icon: String icon: String
}, },
methods: { methods: {
onClick: function onClick(event) { onClick(event) {
this.$emit('click', event.detail); this.$emit('click', event.detail);
this.jumpLink(); this.jumpLink();
}
} }
} });
});

1
dist/goods-action/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -1,5 +1,5 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { iphonex } from '../mixins/iphonex'; import { iphonex } from '../mixins/iphonex';
VantComponent({ VantComponent({
mixins: [iphonex] mixins: [iphonex]
}); });

1
dist/icon/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

32
dist/icon/index.js vendored
View File

@ -1,19 +1,19 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
props: { props: {
info: null, info: null,
name: String, name: String,
size: String, size: String,
color: String, color: String,
customStyle: String, customStyle: String,
classPrefix: { classPrefix: {
type: String, type: String,
value: 'van-icon' value: 'van-icon'
}
},
methods: {
onClick() {
this.$emit('click');
}
} }
}, });
methods: {
onClick: function onClick() {
this.$emit('click');
}
}
});

File diff suppressed because one or more lines are too long

1
dist/info/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

10
dist/info/index.js vendored
View File

@ -1,7 +1,7 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
props: { props: {
info: null, info: null,
customStyle: String customStyle: String
} }
}); });

1
dist/loading/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

28
dist/loading/index.js vendored
View File

@ -1,17 +1,17 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
props: { props: {
size: { size: {
type: String, type: String,
value: '30px' value: '30px'
}, },
type: { type: {
type: String, type: String,
value: 'circular' value: 'circular'
}, },
color: { color: {
type: String, type: String,
value: '#c9c9c9' value: '#c9c9c9'
}
} }
} });
});

1
dist/mixins/basic.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare const basic: void;

42
dist/mixins/basic.js vendored
View File

@ -1,22 +1,22 @@
export var basic = Behavior({ export const basic = Behavior({
methods: { methods: {
$emit: function $emit() { $emit() {
this.triggerEvent.apply(this, arguments); this.triggerEvent.apply(this, arguments);
}, },
getRect: function getRect(selector, all) { getRect(selector, all) {
var _this = this; return new Promise(resolve => {
wx.createSelectorQuery()
return new Promise(function (resolve) { .in(this)[all ? 'selectAll' : 'select'](selector)
wx.createSelectorQuery().in(_this)[all ? 'selectAll' : 'select'](selector).boundingClientRect(function (rect) { .boundingClientRect(rect => {
if (all && Array.isArray(rect) && rect.length) { if (all && Array.isArray(rect) && rect.length) {
resolve(rect); resolve(rect);
} }
if (!all && rect) {
if (!all && rect) { resolve(rect);
resolve(rect); }
} })
}).exec(); .exec();
}); });
}
} }
} });
});

1
dist/mixins/button.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare const button: void;

36
dist/mixins/button.js vendored
View File

@ -1,18 +1,18 @@
export var button = Behavior({ export const button = Behavior({
externalClasses: ['hover-class'], externalClasses: ['hover-class'],
properties: { properties: {
id: String, id: String,
lang: { lang: {
type: String, type: String,
value: 'en' value: 'en'
}, },
businessId: Number, businessId: Number,
sessionFrom: String, sessionFrom: String,
sendMessageTitle: String, sendMessageTitle: String,
sendMessagePath: String, sendMessagePath: String,
sendMessageImg: String, sendMessageImg: String,
showMessageCard: Boolean, showMessageCard: Boolean,
appParameter: String, appParameter: String,
ariaLabel: String ariaLabel: String
} }
}); });

1
dist/mixins/iphonex.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare const iphonex: void;

View File

@ -1,39 +1,32 @@
var isIPhoneX = null; let isIPhoneX = null;
function getIsIPhoneX() { function getIsIPhoneX() {
return new Promise(function (resolve, reject) { return new Promise((resolve, reject) => {
if (isIPhoneX !== null) { if (isIPhoneX !== null) {
resolve(isIPhoneX); resolve(isIPhoneX);
} else { }
wx.getSystemInfo({ else {
success: function success(_ref) { wx.getSystemInfo({
var model = _ref.model, success: ({ model, screenHeight }) => {
screenHeight = _ref.screenHeight; const iphoneX = /iphone x/i.test(model);
var iphoneX = /iphone x/i.test(model); const iphoneNew = /iPhone11/i.test(model) && screenHeight === 812;
var iphoneNew = /iPhone11/i.test(model) && screenHeight === 812; isIPhoneX = iphoneX || iphoneNew;
isIPhoneX = iphoneX || iphoneNew; resolve(isIPhoneX);
resolve(isIPhoneX); },
}, fail: reject
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
});
}); });
} }
}); export const iphonex = Behavior({
properties: {
safeAreaInsetBottom: {
type: Boolean,
value: true
}
},
created() {
getIsIPhoneX().then(isIPhoneX => {
this.set({ isIPhoneX });
});
}
});

1
dist/mixins/link.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare const link: void;

39
dist/mixins/link.js vendored
View File

@ -1,24 +1,17 @@
export var link = Behavior({ export const link = Behavior({
properties: { properties: {
url: String, url: String,
linkType: { linkType: {
type: String, type: String,
value: 'navigateTo' 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
});
}
}
}
});

1
dist/mixins/observer/behavior.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare const behavior: void;

View File

@ -1,62 +1,47 @@
function setAsync(context, data) { function setAsync(context, data) {
return new Promise(function (resolve) { return new Promise(resolve => {
context.setData(data, resolve); context.setData(data, resolve);
}); });
} }
; ;
export var behavior = Behavior({ export const behavior = Behavior({
created: function created() { created() {
var _this = this; if (!this.$options) {
return;
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;
} }
}); const cache = {};
return needUpdate; const { computed } = this.$options();
}; const keys = Object.keys(computed);
}, this.calcComputed = () => {
attached: function attached() { const needUpdate = {};
this.set(); keys.forEach(key => {
}, const value = computed[key].call(this);
methods: { if (cache[key] !== value) {
// set data and set computed data cache[key] = needUpdate[key] = value;
set: function set(data, callback) { }
var _this2 = this; });
return needUpdate;
var stack = []; };
},
if (data) { attached() {
stack.push(setAsync(this, data)); this.set();
} },
methods: {
if (this.calcComputed) { // set data and set computed data
stack.push(setAsync(this, this.calcComputed())); set(data, callback) {
} const stack = [];
if (data) {
return Promise.all(stack).then(function (res) { stack.push(setAsync(this, data));
if (callback && typeof callback === 'function') { }
callback.call(_this2); 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;
});
} }
} });
});

1
dist/mixins/observer/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare function observe(vantOptions: any, options: any): void;

View File

@ -1,38 +1,27 @@
import { behavior } from './behavior'; import { behavior } from './behavior';
import { observeProps } from './props'; import { observeProps } from './props';
export function observe(vantOptions, options) { export function observe(vantOptions, options) {
var watch = vantOptions.watch, const { watch, computed } = vantOptions;
computed = vantOptions.computed; options.behaviors.push(behavior);
options.behaviors.push(behavior); if (watch) {
const props = options.properties || {};
if (watch) { Object.keys(watch).forEach(key => {
var props = options.properties || {}; if (key in props) {
Object.keys(watch).forEach(function (key) { let prop = props[key];
if (key in props) { if (prop === null || !('type' in prop)) {
var prop = props[key]; prop = { type: prop };
}
if (prop === null || !('type' in prop)) { prop.observer = watch[key];
prop = { props[key] = prop;
type: prop }
}; });
} options.properties = props;
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);
} }
} if (computed) {
} options.methods = options.methods || {};
options.methods.$options = () => vantOptions;
if (options.properties) {
observeProps(options.properties);
}
}
}

1
dist/mixins/observer/props.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare function observeProps(props: any): void;

View File

@ -1,32 +1,22 @@
export function observeProps(props) { export function observeProps(props) {
if (!props) { if (!props) {
return; return;
}
Object.keys(props).forEach(function (key) {
var prop = props[key];
if (prop === null || !('type' in prop)) {
prop = {
type: prop
};
} }
Object.keys(props).forEach(key => {
var _prop = prop, let prop = props[key];
observer = _prop.observer; if (prop === null || !('type' in prop)) {
prop = { type: prop };
prop.observer = function () {
if (observer) {
if (typeof observer === 'string') {
observer = this[observer];
} }
let { observer } = prop;
observer.apply(this, arguments); prop.observer = function () {
} if (observer) {
if (typeof observer === 'string') {
this.set(); observer = this[observer];
}; }
observer.apply(this, arguments);
props[key] = prop; }
}); this.set();
} };
props[key] = prop;
});
}

1
dist/mixins/open-type.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare const openType: void;

View File

@ -1,25 +1,25 @@
export var openType = Behavior({ export const openType = Behavior({
properties: { properties: {
openType: String openType: String
},
methods: {
bindGetUserInfo: function bindGetUserInfo(event) {
this.$emit('getuserinfo', event.detail);
}, },
bindContact: function bindContact(event) { methods: {
this.$emit('contact', event.detail); bindGetUserInfo(event) {
}, this.$emit('getuserinfo', event.detail);
bindGetPhoneNumber: function bindGetPhoneNumber(event) { },
this.$emit('getphonenumber', event.detail); bindContact(event) {
}, this.$emit('contact', event.detail);
bindError: function bindError(event) { },
this.$emit('error', event.detail); bindGetPhoneNumber(event) {
}, this.$emit('getphonenumber', event.detail);
bindLaunchApp: function bindLaunchApp(event) { },
this.$emit('launchapp', event.detail); bindError(event) {
}, this.$emit('error', event.detail);
bindOpenSetting: function bindOpenSetting(event) { },
this.$emit('opensetting', event.detail); bindLaunchApp(event) {
this.$emit('launchapp', event.detail);
},
bindOpenSetting(event) {
this.$emit('opensetting', event.detail);
},
} }
} });
});

1
dist/mixins/touch.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare const touch: void;

40
dist/mixins/touch.js vendored
View File

@ -1,21 +1,21 @@
export var touch = Behavior({ export const touch = Behavior({
methods: { methods: {
touchStart: function touchStart(event) { touchStart(event) {
this.direction = ''; this.direction = '';
this.deltaX = 0; this.deltaX = 0;
this.deltaY = 0; this.deltaY = 0;
this.offsetX = 0; this.offsetX = 0;
this.offsetY = 0; this.offsetY = 0;
this.startX = event.touches[0].clientX; this.startX = event.touches[0].clientX;
this.startY = event.touches[0].clientY; this.startY = event.touches[0].clientY;
}, },
touchMove: function touchMove(event) { touchMove(event) {
var touch = event.touches[0]; const touch = event.touches[0];
this.deltaX = touch.clientX - this.startX; this.deltaX = touch.clientX - this.startX;
this.deltaY = touch.clientY - this.startY; this.deltaY = touch.clientY - this.startY;
this.offsetX = Math.abs(this.deltaX); this.offsetX = Math.abs(this.deltaX);
this.offsetY = Math.abs(this.deltaY); this.offsetY = Math.abs(this.deltaY);
this.direction = this.offsetX > this.offsetY ? 'horizontal' : this.offsetX < this.offsetY ? 'vertical' : ''; this.direction = this.offsetX > this.offsetY ? 'horizontal' : this.offsetX < this.offsetY ? 'vertical' : '';
}
} }
} });
});

1
dist/mixins/transition.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare const transition: (showDefaultValue: boolean) => void;

View File

@ -1,105 +1,89 @@
import { isObj } from '../common/utils'; import { isObj } from '../common/utils';
const getClassNames = (name) => ({
var getClassNames = function getClassNames(name) { enter: `van-${name}-enter van-${name}-enter-active enter-class enter-active-class`,
return { 'enter-to': `van-${name}-enter-to van-${name}-enter-active enter-to-class enter-active-class`,
enter: "van-" + name + "-enter van-" + name + "-enter-active enter-class enter-active-class", leave: `van-${name}-leave van-${name}-leave-active leave-class leave-active-class`,
'enter-to': "van-" + name + "-enter-to van-" + name + "-enter-active enter-to-class enter-active-class", 'leave-to': `van-${name}-leave-to van-${name}-leave-active leave-to-class leave-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: {
var requestAnimationFrame = function requestAnimationFrame(cb) { customStyle: String,
return setTimeout(cb, 1000 / 60); show: {
}; type: Boolean,
value: showDefaultValue,
export var transition = function transition(showDefaultValue) { observer: 'observeShow'
return Behavior({ },
properties: { duration: {
customStyle: String, type: [Number, Object],
show: { value: 300,
type: Boolean, observer: 'observeDuration'
value: showDefaultValue, },
observer: 'observeShow' name: {
}, type: String,
duration: { value: 'fade',
type: [Number, Object], observer: 'updateClasses'
value: 300, }
observer: 'observeDuration' },
}, data: {
name: { type: '',
type: String, inited: false,
value: 'fade', display: false,
observer: 'updateClasses' classNames: getClassNames('fade')
} },
}, attached() {
data: { if (this.data.show) {
type: '', this.show();
inited: false, }
display: false, },
classNames: getClassNames('fade') methods: {
}, observeShow(value) {
attached: function attached() { if (value) {
if (this.data.show) { this.show();
this.show(); }
} else {
}, this.leave();
methods: { }
observeShow: function observeShow(value) { },
if (value) { updateClasses(name) {
this.show(); this.set({
} else { classNames: getClassNames(name)
this.leave(); });
},
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
});
}
}
}
});
};

1
dist/nav-bar/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

46
dist/nav-bar/index.js vendored
View File

@ -1,27 +1,27 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
classes: ['title-class'], classes: ['title-class'],
props: { props: {
title: String, title: String,
fixed: Boolean, fixed: Boolean,
leftText: String, leftText: String,
rightText: String, rightText: String,
leftArrow: Boolean, leftArrow: Boolean,
border: { border: {
type: Boolean, type: Boolean,
value: true value: true
},
zIndex: {
type: Number,
value: 1
}
}, },
zIndex: { methods: {
type: Number, onClickLeft() {
value: 1 this.$emit('click-left');
},
onClickRight() {
this.$emit('click-right');
}
} }
}, });
methods: {
onClickLeft: function onClickLeft() {
this.$emit('click-left');
},
onClickRight: function onClickRight() {
this.$emit('click-right');
}
}
});

1
dist/notice-bar/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -1,131 +1,128 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
var FONT_COLOR = '#ed6a0c'; const FONT_COLOR = '#ed6a0c';
var BG_COLOR = '#fffbe8'; const BG_COLOR = '#fffbe8';
VantComponent({ VantComponent({
props: { props: {
text: { text: {
type: String, type: String,
value: '' value: ''
}, },
mode: { mode: {
type: String, type: String,
value: '' value: ''
}, },
url: { url: {
type: String, type: String,
value: '' value: ''
}, },
openType: { openType: {
type: String, type: String,
value: 'navigate' value: 'navigate'
}, },
delay: { delay: {
type: Number, type: Number,
value: 0 value: 0
}, },
speed: { speed: {
type: Number, type: Number,
value: 50 value: 50
}, },
scrollable: { scrollable: {
type: Boolean, type: Boolean,
value: true value: true
}, },
leftIcon: { leftIcon: {
type: String, type: String,
value: '' value: ''
}, },
color: { color: {
type: String, type: String,
value: FONT_COLOR value: FONT_COLOR
}, },
backgroundColor: { backgroundColor: {
type: String, type: String,
value: BG_COLOR 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;
} }
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() { data: {
var _this2 = this; show: true,
hasRightIcon: false
this.timer && clearTimeout(this.timer); },
this.timer = null; watch: {
this.set({ text() {
animationData: this.resetAnimation.translateX(this.wrapWidth).step().export() this.set({}, this.init);
}); }
setTimeout(function () { },
_this2.set({ created() {
animationData: _this2.animation.translateX(-_this2.contentWidth).step().export() 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() { destroyed() {
this.timer && clearTimeout(this.timer); this.timer && clearTimeout(this.timer);
this.timer = null;
this.set({
show: false
});
}, },
onClick: function onClick(event) { methods: {
this.$emit('click', event); 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);
}
} }
} });
});

1
dist/notify/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

71
dist/notify/index.js vendored
View File

@ -1,42 +1,39 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { RED } from '../common/color'; import { RED } from '../common/color';
VantComponent({ VantComponent({
props: { props: {
text: String, text: String,
color: { color: {
type: String, type: String,
value: '#fff' value: '#fff'
},
backgroundColor: {
type: String,
value: RED
},
duration: {
type: Number,
value: 3000
}
}, },
backgroundColor: { methods: {
type: String, show() {
value: RED const { duration } = this.data;
}, clearTimeout(this.timer);
duration: { this.set({
type: Number, show: true
value: 3000 });
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
});
}
}
});

7
dist/notify/notify.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
declare type NotifyOptions = {
selector?: string;
duration?: number;
context?: any;
};
export default function Notify(options?: NotifyOptions): void;
export {};

47
dist/notify/notify.js vendored
View File

@ -1,34 +1,25 @@
import { isObj } from '../common/utils'; import { isObj } from '../common/utils';
var defaultOptions = { const defaultOptions = {
selector: '#van-notify', selector: '#van-notify',
duration: 3000 duration: 3000
}; };
function parseOptions(text) { function parseOptions(text) {
return isObj(text) ? text : { return isObj(text) ? text : { text };
text: text
};
} }
function getContext() { function getContext() {
var pages = getCurrentPages(); const pages = getCurrentPages();
return pages[pages.length - 1]; 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 是否正确');
}
}

1
dist/overlay/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

38
dist/overlay/index.js vendored
View File

@ -1,23 +1,23 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
props: { props: {
show: Boolean, show: Boolean,
mask: Boolean, mask: Boolean,
customStyle: String, customStyle: String,
duration: { duration: {
type: [Number, Object], type: [Number, Object],
value: 300 value: 300
},
zIndex: {
type: Number,
value: 1
}
}, },
zIndex: { methods: {
type: Number, onClick() {
value: 1 this.$emit('click');
},
// for prevent touchmove
noop() { }
} }
}, });
methods: {
onClick: function onClick() {
this.$emit('click');
},
// for prevent touchmove
noop: function noop() {}
}
});

1
dist/panel/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

16
dist/panel/index.js vendored
View File

@ -1,10 +1,10 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
classes: ['header-class', 'footer-class'], classes: ['header-class', 'footer-class'],
props: { props: {
desc: String, desc: String,
title: String, title: String,
status: String, status: String,
useFooterSlot: Boolean useFooterSlot: Boolean
} }
}); });

1
dist/picker-column/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -1,144 +1,136 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { isObj, range } from '../common/utils'; import { isObj, range } from '../common/utils';
var DEFAULT_DURATION = 200; const DEFAULT_DURATION = 200;
VantComponent({ VantComponent({
classes: ['active-class'], classes: ['active-class'],
props: { props: {
valueKey: String, valueKey: String,
className: String, className: String,
itemHeight: Number, itemHeight: Number,
visibleItemCount: Number, visibleItemCount: Number,
initialOptions: { initialOptions: {
type: Array, type: Array,
value: [] value: []
}, },
defaultIndex: { defaultIndex: {
type: Number, type: Number,
value: 0 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);
} }
}
return Promise.resolve();
}, },
getValue: function getValue() { data: {
var data = this.data; startY: 0,
return data.options[data.currentIndex]; 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];
}
} }
} });
});

1
dist/picker/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

318
dist/picker/index.js vendored
View File

@ -1,185 +1,147 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
function isSimple(columns) { function isSimple(columns) {
return columns.length && !columns[0].values; return columns.length && !columns[0].values;
} }
VantComponent({ VantComponent({
classes: ['active-class', 'toolbar-class', 'column-class'], classes: ['active-class', 'toolbar-class', 'column-class'],
props: { props: {
title: String, title: String,
loading: Boolean, loading: Boolean,
showToolbar: Boolean, showToolbar: Boolean,
confirmButtonText: String, confirmButtonText: String,
cancelButtonText: String, cancelButtonText: String,
visibleItemCount: { visibleItemCount: {
type: Number, type: Number,
value: 5 value: 5
}, },
valueKey: { valueKey: {
type: String, type: String,
value: 'text' value: 'text'
}, },
itemHeight: { itemHeight: {
type: Number, type: Number,
value: 44 value: 44
}, },
columns: { columns: {
type: Array, type: Array,
value: [], value: [],
observer: function observer(columns) { observer(columns = []) {
if (columns === void 0) { this.simple = isSimple(columns);
columns = []; this.children = this.selectAllComponents('.van-picker__column');
if (Array.isArray(this.children) && this.children.length) {
this.setColumns().catch(() => { });
}
}
} }
},
this.simple = isSimple(columns); beforeCreate() {
this.children = this.selectAllComponents('.van-picker__column'); this.children = [];
},
if (Array.isArray(this.children) && this.children.length) { methods: {
this.setColumns().catch(function () {}); 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);
}
}
});

1
dist/popup/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

90
dist/popup/index.js vendored
View File

@ -2,49 +2,53 @@ import { VantComponent } from '../common/component';
import { transition } from '../mixins/transition'; import { transition } from '../mixins/transition';
import { iphonex } from '../mixins/iphonex'; import { iphonex } from '../mixins/iphonex';
VantComponent({ VantComponent({
classes: ['enter-class', 'enter-active-class', 'enter-to-class', 'leave-class', 'leave-active-class', 'leave-to-class'], classes: [
mixins: [transition(false), iphonex], 'enter-class',
props: { 'enter-active-class',
transition: { 'enter-to-class',
type: String, 'leave-class',
observer: 'observeClass' '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, created() {
overlayStyle: String, this.observeClass();
zIndex: {
type: Number,
value: 100
}, },
overlay: { methods: {
type: Boolean, onClickOverlay() {
value: true this.$emit('click-overlay');
}, if (this.data.closeOnClickOverlay) {
closeOnClickOverlay: { this.$emit('close');
type: Boolean, }
value: true },
}, observeClass() {
position: { const { transition, position } = this.data;
type: String, this.updateClasses(transition || position);
value: 'center', }
observer: 'observeClass'
} }
}, });
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);
}
}
});

1
dist/progress/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

120
dist/progress/index.js vendored
View File

@ -1,67 +1,65 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { BLUE } from '../common/color'; import { BLUE } from '../common/color';
VantComponent({ VantComponent({
props: { props: {
inactive: Boolean, inactive: Boolean,
percentage: Number, percentage: Number,
pivotText: String, pivotText: String,
pivotColor: String, pivotColor: String,
showPivot: { showPivot: {
type: Boolean, type: Boolean,
value: true value: true
},
color: {
type: String,
value: BLUE
},
textColor: {
type: String,
value: '#fff'
}
}, },
color: { data: {
type: String, pivotWidth: 0,
value: BLUE progressWidth: 0
}, },
textColor: { watch: {
type: String, pivotText: 'getWidth',
value: '#fff' 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
});
});
}
}
});

1
dist/radio-group/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -1,39 +1,33 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
field: true, field: true,
relation: { relation: {
name: 'radio', name: 'radio',
type: 'descendant', type: 'descendant',
linked: function linked(target) { linked(target) {
var _this$data = this.data, const { value, disabled } = this.data;
value = _this$data.value, target.set({
disabled = _this$data.disabled; value: value,
target.set({ disabled: disabled || target.data.disabled
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
});
});
}, },
disabled: function disabled(_disabled) { props: {
var children = this.getRelationNodes('../radio/index'); value: null,
children.forEach(function (child) { disabled: Boolean
child.set({ },
disabled: _disabled || child.data.disabled 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 });
});
}
} }
} });
});

1
dist/radio/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

54
dist/radio/index.js vendored
View File

@ -1,32 +1,32 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
field: true, field: true,
relation: { relation: {
name: 'radio-group', name: 'radio-group',
type: 'ancestor' 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);
}, },
onChange: function onChange(event) { classes: ['icon-class', 'label-class'],
this.emitChange(event.detail.value); props: {
name: null,
value: null,
disabled: Boolean,
labelDisabled: Boolean,
labelPosition: String,
checkedColor: String
}, },
onClickLabel: function onClickLabel() { methods: {
if (!this.data.disabled && !this.data.labelDisabled) { emitChange(value) {
this.emitChange(this.data.name); 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);
}
}
} }
} });
});

1
dist/rate/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

171
dist/rate/index.js vendored
View File

@ -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'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
field: true, field: true,
classes: ['icon-class'], classes: ['icon-class'],
props: { props: {
readonly: Boolean, readonly: Boolean,
disabled: Boolean, disabled: Boolean,
size: { size: {
type: Number, type: Number,
value: 20 value: 20
}, },
icon: { icon: {
type: String, type: String,
value: 'star' value: 'star'
}, },
voidIcon: { voidIcon: {
type: String, type: String,
value: 'star-o' value: 'star-o'
}, },
color: { color: {
type: String, type: String,
value: '#ffd21e' value: '#ffd21e'
}, },
voidColor: { voidColor: {
type: String, type: String,
value: '#c7c7c7' value: '#c7c7c7'
}, },
disabledColor: { disabledColor: {
type: String, type: String,
value: '#bdbdbd' value: '#bdbdbd'
}, },
count: { count: {
type: Number, type: Number,
value: 5 value: 5
}, },
value: { value: {
type: Number, type: Number,
value: 0 value: 0
} }
}, },
data: { data: {
innerValue: 0 innerValue: 0
}, },
watch: { watch: {
value: function value(_value) { value(value) {
if (_value !== this.data.innerValue) { if (value !== this.data.innerValue) {
this.set({ this.set({ innerValue: value });
innerValue: _value }
}); }
} },
} computed: {
}, list() {
computed: { const { count, innerValue } = this.data;
list: function list() { return Array.from({ length: count }, (_, index) => index < innerValue);
var _this$data = this.data, }
count = _this$data.count, },
innerValue = _this$data.innerValue; methods: {
return Array.from({ onSelect(event) {
length: count const { data } = this;
}, function (_, index) { const { index } = event.currentTarget.dataset;
return index < innerValue; if (!data.disabled && !data.readonly) {
}); this.set({ innerValue: index + 1 });
} this.$emit('input', index + 1);
}, this.$emit('change', index + 1);
methods: { }
onSelect: function onSelect(event) { },
var data = this.data; onTouchMove(event) {
var index = event.currentTarget.dataset.index; const { clientX, clientY } = event.touches[0];
this.getRect('.van-rate__item', true).then(list => {
if (!data.disabled && !data.readonly) { const target = list.find(item => clientX >= item.left &&
this.set({ clientX <= item.right &&
innerValue: index + 1 clientY >= item.top &&
}); clientY <= item.bottom);
this.$emit('input', index + 1); if (target != null) {
this.$emit('change', index + 1); this.onSelect(Object.assign({}, event, { currentTarget: target }));
} }
}, });
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
}));
} }
});
} }
} });
});

Some files were not shown because too many files have changed in this diff Show More