1
0
mirror of https://gitee.com/vant-contrib/vant-weapp.git synced 2025-04-06 03:58:05 +08:00

[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

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

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

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

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

364
dist/area/index.js vendored

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

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

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

@ -1,55 +1,49 @@
import { VantComponent } from '../common/component';
import { isNumber } from '../common/utils';
VantComponent({
relation: {
name: 'badge',
type: 'descendant',
linked: function linked(target) {
this.badges.push(target);
this.setActive();
relation: {
name: 'badge',
type: 'descendant',
linked(target) {
this.badges.push(target);
this.setActive();
},
unlinked(target) {
this.badges = this.badges.filter(item => item !== target);
this.setActive();
}
},
unlinked: function unlinked(target) {
this.badges = this.badges.filter(function (item) {
return item !== target;
});
this.setActive();
props: {
active: {
type: Number,
value: 0
}
},
watch: {
active: 'setActive'
},
beforeCreate() {
this.badges = [];
this.currentActive = -1;
},
methods: {
setActive(badge) {
let { active } = this.data;
const { badges } = this;
if (badge && !isNumber(badge)) {
active = badges.indexOf(badge);
}
if (active === this.currentActive) {
return;
}
if (this.currentActive !== -1 && badges[this.currentActive]) {
this.$emit('change', active);
badges[this.currentActive].setActive(false);
}
if (badges[active]) {
badges[active].setActive(true);
this.currentActive = active;
}
}
}
},
props: {
active: {
type: Number,
value: 0
}
},
watch: {
active: 'setActive'
},
beforeCreate: function beforeCreate() {
this.badges = [];
this.currentActive = -1;
},
methods: {
setActive: function setActive(badge) {
var active = this.data.active;
var badges = this.badges;
if (badge && !isNumber(badge)) {
active = badges.indexOf(badge);
}
if (active === this.currentActive) {
return;
}
if (this.currentActive !== -1 && badges[this.currentActive]) {
this.$emit('change', active);
badges[this.currentActive].setActive(false);
}
if (badges[active]) {
badges[active].setActive(true);
this.currentActive = active;
}
}
}
});
});

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

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

39
dist/badge/index.js vendored

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

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

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

58
dist/button/index.js vendored

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

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

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

59
dist/card/index.js vendored

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

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

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

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

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

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

58
dist/cell/index.js vendored

@ -1,30 +1,36 @@
import { link } from '../mixins/link';
import { VantComponent } from '../common/component';
VantComponent({
classes: ['title-class', 'label-class', 'value-class', 'right-icon-class', 'hover-class'],
mixins: [link],
props: {
title: null,
value: null,
icon: String,
size: String,
label: String,
center: Boolean,
isLink: Boolean,
required: Boolean,
clickable: Boolean,
titleWidth: String,
customStyle: String,
arrowDirection: String,
border: {
type: Boolean,
value: true
classes: [
'title-class',
'label-class',
'value-class',
'right-icon-class',
'hover-class'
],
mixins: [link],
props: {
title: null,
value: null,
icon: String,
size: String,
label: String,
center: Boolean,
isLink: Boolean,
required: Boolean,
clickable: Boolean,
titleWidth: String,
customStyle: String,
arrowDirection: String,
border: {
type: Boolean,
value: true
}
},
methods: {
onClick(event) {
this.$emit('click', event.detail);
this.jumpLink();
}
}
},
methods: {
onClick: function onClick(event) {
this.$emit('click', event.detail);
this.jumpLink();
}
}
});
});

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

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

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

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

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

131
dist/checkbox/index.js vendored

@ -1,70 +1,67 @@
import { VantComponent } from '../common/component';
VantComponent({
field: true,
relation: {
name: 'checkbox-group',
type: 'ancestor'
},
classes: ['icon-class', 'label-class'],
props: {
value: null,
disabled: Boolean,
useIconSlot: Boolean,
checkedColor: String,
labelPosition: String,
labelDisabled: Boolean,
shape: {
type: String,
value: 'round'
field: true,
relation: {
name: 'checkbox-group',
type: 'ancestor'
},
classes: ['icon-class', 'label-class'],
props: {
value: null,
disabled: Boolean,
useIconSlot: Boolean,
checkedColor: String,
labelPosition: String,
labelDisabled: Boolean,
shape: {
type: String,
value: 'round'
}
},
methods: {
emitChange(value) {
const parent = this.getRelationNodes('../checkbox-group/index')[0];
if (parent) {
this.setParentValue(parent, value);
}
else {
this.$emit('input', value);
this.$emit('change', value);
}
},
toggle() {
if (!this.data.disabled) {
this.emitChange(!this.data.value);
}
},
onClickLabel() {
if (!this.data.disabled && !this.data.labelDisabled) {
this.emitChange(!this.data.value);
}
},
setParentValue(parent, value) {
const parentValue = parent.data.value.slice();
const { name } = this.data;
if (value) {
if (parent.data.max && parentValue.length >= parent.data.max) {
return;
}
/* istanbul ignore else */
if (parentValue.indexOf(name) === -1) {
parentValue.push(name);
parent.$emit('input', parentValue);
parent.$emit('change', parentValue);
}
}
else {
const index = parentValue.indexOf(name);
/* istanbul ignore else */
if (index !== -1) {
parentValue.splice(index, 1);
parent.$emit('input', parentValue);
parent.$emit('change', parentValue);
}
}
}
}
},
methods: {
emitChange: function emitChange(value) {
var parent = this.getRelationNodes('../checkbox-group/index')[0];
if (parent) {
this.setParentValue(parent, value);
} else {
this.$emit('input', value);
this.$emit('change', value);
}
},
toggle: function toggle() {
if (!this.data.disabled) {
this.emitChange(!this.data.value);
}
},
onClickLabel: function onClickLabel() {
if (!this.data.disabled && !this.data.labelDisabled) {
this.emitChange(!this.data.value);
}
},
setParentValue: function setParentValue(parent, value) {
var parentValue = parent.data.value.slice();
var name = this.data.name;
if (value) {
if (parent.data.max && parentValue.length >= parent.data.max) {
return;
}
/* istanbul ignore else */
if (parentValue.indexOf(name) === -1) {
parentValue.push(name);
parent.$emit('input', parentValue);
parent.$emit('change', parentValue);
}
} else {
var index = parentValue.indexOf(name);
/* istanbul ignore else */
if (index !== -1) {
parentValue.splice(index, 1);
parent.$emit('input', parentValue);
parent.$emit('change', parentValue);
}
}
}
}
});
});

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

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

43
dist/col/index.js vendored

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

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

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

@ -1,105 +1,91 @@
import { VantComponent } from '../common/component';
VantComponent({
classes: ['title-class', 'content-class'],
relation: {
name: 'collapse',
type: 'ancestor',
linked: function linked(parent) {
this.parent = parent;
}
},
props: {
name: null,
title: null,
value: null,
icon: String,
label: String,
disabled: Boolean,
border: {
type: Boolean,
value: true
},
isLink: {
type: Boolean,
value: true
}
},
data: {
contentHeight: 0,
expanded: false
},
beforeCreate: function beforeCreate() {
this.animation = wx.createAnimation({
duration: 300,
timingFunction: 'ease-in-out'
});
},
methods: {
updateExpanded: function updateExpanded() {
if (!this.parent) {
return null;
}
var _this$parent$data = this.parent.data,
value = _this$parent$data.value,
accordion = _this$parent$data.accordion,
items = _this$parent$data.items;
var name = this.data.name;
var index = items.indexOf(this);
var currentName = name == null ? index : name;
var expanded = accordion ? value === currentName : value.some(function (name) {
return name === currentName;
});
if (expanded !== this.data.expanded) {
this.updateStyle(expanded);
}
this.set({
expanded: expanded
});
},
updateStyle: function updateStyle(expanded) {
var _this = this;
this.getRect('.van-collapse-item__content').then(function (res) {
var animationData = _this.animation.height(expanded ? res.height : 0).step().export();
if (expanded) {
_this.set({
animationData: animationData
});
} else {
_this.set({
contentHeight: res.height + 'px'
}, function () {
setTimeout(function () {
_this.set({
animationData: animationData
});
}, 20);
});
classes: ['title-class', 'content-class'],
relation: {
name: 'collapse',
type: 'ancestor',
linked(parent) {
this.parent = parent;
}
});
},
onClick: function onClick() {
if (this.data.disabled) {
return;
}
var _this$data = this.data,
name = _this$data.name,
expanded = _this$data.expanded;
var index = this.parent.data.items.indexOf(this);
var currentName = name == null ? index : name;
this.parent.switch(currentName, !expanded);
props: {
name: null,
title: null,
value: null,
icon: String,
label: String,
disabled: Boolean,
border: {
type: Boolean,
value: true
},
isLink: {
type: Boolean,
value: true
}
},
onTransitionEnd: function onTransitionEnd() {
if (this.data.expanded) {
this.set({
contentHeight: 'auto'
data: {
contentHeight: 0,
expanded: false
},
beforeCreate() {
this.animation = wx.createAnimation({
duration: 300,
timingFunction: 'ease-in-out'
});
}
},
methods: {
updateExpanded() {
if (!this.parent) {
return null;
}
const { value, accordion, items } = this.parent.data;
const { name } = this.data;
const index = items.indexOf(this);
const currentName = name == null ? index : name;
const expanded = accordion
? value === currentName
: value.some(name => name === currentName);
if (expanded !== this.data.expanded) {
this.updateStyle(expanded);
}
this.set({ expanded });
},
updateStyle(expanded) {
this.getRect('.van-collapse-item__content').then(res => {
const animationData = this.animation
.height(expanded ? res.height : 0)
.step()
.export();
if (expanded) {
this.set({ animationData });
}
else {
this.set({
contentHeight: res.height + 'px'
}, () => {
setTimeout(() => {
this.set({ animationData });
}, 20);
});
}
});
},
onClick() {
if (this.data.disabled) {
return;
}
const { name, expanded } = this.data;
const index = this.parent.data.items.indexOf(this);
const currentName = name == null ? index : name;
this.parent.switch(currentName, !expanded);
},
onTransitionEnd() {
if (this.data.expanded) {
this.set({
contentHeight: 'auto'
});
}
}
}
}
});
});

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

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

@ -1,51 +1,48 @@
import { VantComponent } from '../common/component';
VantComponent({
relation: {
name: 'collapse-item',
type: 'descendant',
linked: function linked(child) {
this.set({
items: [].concat(this.data.items, [child])
}, function () {
child.updateExpanded();
});
}
},
props: {
accordion: Boolean,
value: null
},
data: {
items: []
},
watch: {
value: function value() {
this.data.items.forEach(function (child) {
child.updateExpanded();
});
relation: {
name: 'collapse-item',
type: 'descendant',
linked(child) {
this.set({
items: [...this.data.items, child]
}, () => {
child.updateExpanded();
});
}
},
accordion: function accordion() {
this.data.items.forEach(function (child) {
child.updateExpanded();
});
props: {
accordion: Boolean,
value: null
},
data: {
items: []
},
watch: {
value() {
this.data.items.forEach(child => {
child.updateExpanded();
});
},
accordion() {
this.data.items.forEach(child => {
child.updateExpanded();
});
}
},
methods: {
switch(name, expanded) {
const { accordion, value } = this.data;
if (!accordion) {
name = expanded
? value.concat(name)
: value.filter(activeName => activeName !== name);
}
else {
name = expanded ? name : '';
}
this.$emit('change', name);
this.$emit('input', name);
}
}
},
methods: {
switch: function _switch(name, expanded) {
var _this$data = this.data,
accordion = _this$data.accordion,
value = _this$data.value;
if (!accordion) {
name = expanded ? value.concat(name) : value.filter(function (activeName) {
return activeName !== name;
});
} else {
name = expanded ? name : '';
}
this.$emit('change', name);
this.$emit('input', name);
}
}
});
});

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

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

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

2
dist/common/component.d.ts vendored Normal 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 };

@ -1,59 +1,48 @@
import { basic } from '../mixins/basic';
import { observe } from '../mixins/observer/index';
function mapKeys(source, target, map) {
Object.keys(map).forEach(function (key) {
if (source[key]) {
target[map[key]] = source[key];
}
});
}
function VantComponent(vantOptions) {
if (vantOptions === void 0) {
vantOptions = {};
}
var options = {};
mapKeys(vantOptions, options, {
data: 'data',
props: 'properties',
mixins: 'behaviors',
methods: 'methods',
beforeCreate: 'created',
created: 'attached',
mounted: 'ready',
relations: 'relations',
destroyed: 'detached',
classes: 'externalClasses'
});
var _vantOptions = vantOptions,
relation = _vantOptions.relation;
if (relation) {
options.relations = Object.assign(options.relations || {}, {
["../" + relation.name + "/index"]: relation
Object.keys(map).forEach(key => {
if (source[key]) {
target[map[key]] = source[key];
}
});
} // add default externalClasses
options.externalClasses = options.externalClasses || [];
options.externalClasses.push('custom-class'); // add default behaviors
options.behaviors = options.behaviors || [];
options.behaviors.push(basic); // map field to form-field behavior
if (vantOptions.field) {
options.behaviors.push('wx://form-field');
} // add default options
options.options = {
multipleSlots: true,
addGlobalClass: true
};
observe(vantOptions, options);
Component(options);
}
export { VantComponent };
function VantComponent(vantOptions = {}) {
const options = {};
mapKeys(vantOptions, options, {
data: 'data',
props: 'properties',
mixins: 'behaviors',
methods: 'methods',
beforeCreate: 'created',
created: 'attached',
mounted: 'ready',
relations: 'relations',
destroyed: 'detached',
classes: 'externalClasses'
});
const { relation } = vantOptions;
if (relation) {
options.relations = Object.assign(options.relations || {}, {
[`../${relation.name}/index`]: relation
});
}
// add default externalClasses
options.externalClasses = options.externalClasses || [];
options.externalClasses.push('custom-class');
// add default behaviors
options.behaviors = options.behaviors || [];
options.behaviors.push(basic);
// map field to form-field behavior
if (vantOptions.field) {
options.behaviors.push('wx://form-field');
}
// add default options
options.options = {
multipleSlots: true,
addGlobalClass: true
};
observe(vantOptions, options);
Component(options);
}
export { VantComponent };

5
dist/common/utils.d.ts vendored Normal 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

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

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

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

@ -1,355 +1,295 @@
import { VantComponent } from '../common/component';
import { isDef } from '../common/utils';
var currentYear = new Date().getFullYear();
const currentYear = new Date().getFullYear();
function isValidDate(date) {
return isDef(date) && !isNaN(new Date(date).getTime());
return isDef(date) && !isNaN(new Date(date).getTime());
}
function range(num, min, max) {
return Math.min(Math.max(num, min), max);
return Math.min(Math.max(num, min), max);
}
function padZero(val) {
return ("00" + val).slice(-2);
return `00${val}`.slice(-2);
}
function times(n, iteratee) {
var index = -1;
var result = Array(n);
while (++index < n) {
result[index] = iteratee(index);
}
return result;
let index = -1;
const result = Array(n);
while (++index < n) {
result[index] = iteratee(index);
}
return result;
}
function getTrueValue(formattedValue) {
if (!formattedValue) return;
while (isNaN(parseInt(formattedValue, 10))) {
formattedValue = formattedValue.slice(1);
}
return parseInt(formattedValue, 10);
if (!formattedValue)
return;
while (isNaN(parseInt(formattedValue, 10))) {
formattedValue = formattedValue.slice(1);
}
return parseInt(formattedValue, 10);
}
function getMonthEndDay(year, month) {
return 32 - new Date(year, month - 1, 32).getDate();
return 32 - new Date(year, month - 1, 32).getDate();
}
VantComponent({
props: {
value: null,
title: String,
loading: Boolean,
itemHeight: {
type: Number,
value: 44
props: {
value: null,
title: String,
loading: Boolean,
itemHeight: {
type: Number,
value: 44
},
visibleItemCount: {
type: Number,
value: 5
},
confirmButtonText: {
type: String,
value: '确认'
},
cancelButtonText: {
type: String,
value: '取消'
},
type: {
type: String,
value: 'datetime'
},
showToolbar: {
type: Boolean,
value: true
},
minDate: {
type: Number,
value: new Date(currentYear - 10, 0, 1).getTime()
},
maxDate: {
type: Number,
value: new Date(currentYear + 10, 11, 31).getTime()
},
minHour: {
type: Number,
value: 0
},
maxHour: {
type: Number,
value: 23
},
minMinute: {
type: Number,
value: 0
},
maxMinute: {
type: Number,
value: 59
}
},
visibleItemCount: {
type: Number,
value: 5
data: {
innerValue: Date.now(),
columns: []
},
confirmButtonText: {
type: String,
value: '确认'
},
cancelButtonText: {
type: String,
value: '取消'
},
type: {
type: String,
value: 'datetime'
},
showToolbar: {
type: Boolean,
value: true
},
minDate: {
type: Number,
value: new Date(currentYear - 10, 0, 1).getTime()
},
maxDate: {
type: Number,
value: new Date(currentYear + 10, 11, 31).getTime()
},
minHour: {
type: Number,
value: 0
},
maxHour: {
type: Number,
value: 23
},
minMinute: {
type: Number,
value: 0
},
maxMinute: {
type: Number,
value: 59
}
},
data: {
innerValue: Date.now(),
columns: []
},
watch: {
value: function value(val) {
var _this = this;
var data = this.data;
val = this.correctValue(val);
var isEqual = val === data.innerValue;
if (!isEqual) {
this.updateColumnValue(val).then(function () {
_this.$emit('input', val);
});
}
},
type: 'updateColumns',
minHour: 'updateColumns',
maxHour: 'updateColumns',
minMinute: 'updateColumns',
maxMinute: 'updateColumns'
},
methods: {
getPicker: function getPicker() {
if (this.picker == null) {
var picker = this.picker = this.selectComponent('.van-datetime-picker');
var setColumnValues = picker.setColumnValues;
picker.setColumnValues = function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return setColumnValues.apply(picker, [].concat(args, [false]));
};
}
return this.picker;
},
updateColumns: function updateColumns() {
var results = this.getRanges().map(function (_ref, index) {
var type = _ref.type,
range = _ref.range;
var values = times(range[1] - range[0] + 1, function (index) {
var value = range[0] + index;
value = type === 'year' ? "" + value : padZero(value);
return value;
});
return {
values: values
};
});
return this.set({
columns: results
});
},
getRanges: function getRanges() {
var data = this.data;
if (data.type === 'time') {
return [{
type: 'hour',
range: [data.minHour, data.maxHour]
}, {
type: 'minute',
range: [data.minMinute, data.maxMinute]
}];
}
var _this$getBoundary = this.getBoundary('max', data.innerValue),
maxYear = _this$getBoundary.maxYear,
maxDate = _this$getBoundary.maxDate,
maxMonth = _this$getBoundary.maxMonth,
maxHour = _this$getBoundary.maxHour,
maxMinute = _this$getBoundary.maxMinute;
var _this$getBoundary2 = this.getBoundary('min', data.innerValue),
minYear = _this$getBoundary2.minYear,
minDate = _this$getBoundary2.minDate,
minMonth = _this$getBoundary2.minMonth,
minHour = _this$getBoundary2.minHour,
minMinute = _this$getBoundary2.minMinute;
var result = [{
type: 'year',
range: [minYear, maxYear]
}, {
type: 'month',
range: [minMonth, maxMonth]
}, {
type: 'day',
range: [minDate, maxDate]
}, {
type: 'hour',
range: [minHour, maxHour]
}, {
type: 'minute',
range: [minMinute, maxMinute]
}];
if (data.type === 'date') result.splice(3, 2);
if (data.type === 'year-month') result.splice(2, 3);
return result;
},
correctValue: function correctValue(value) {
var data = this.data; // validate value
var isDateType = data.type !== 'time';
if (isDateType && !isValidDate(value)) {
value = data.minDate;
} else if (!isDateType && !value) {
var minHour = data.minHour;
value = padZero(minHour) + ":00";
} // time type
if (!isDateType) {
var _value$split = value.split(':'),
hour = _value$split[0],
minute = _value$split[1];
hour = padZero(range(hour, data.minHour, data.maxHour));
minute = padZero(range(minute, data.minMinute, data.maxMinute));
return hour + ":" + minute;
} // date type
value = Math.max(value, data.minDate);
value = Math.min(value, data.maxDate);
return value;
},
getBoundary: function getBoundary(type, innerValue) {
var value = new Date(innerValue);
var boundary = new Date(this.data[type + "Date"]);
var year = boundary.getFullYear();
var month = 1;
var date = 1;
var hour = 0;
var minute = 0;
if (type === 'max') {
month = 12;
date = getMonthEndDay(value.getFullYear(), value.getMonth() + 1);
hour = 23;
minute = 59;
}
if (value.getFullYear() === year) {
month = boundary.getMonth() + 1;
if (value.getMonth() + 1 === month) {
date = boundary.getDate();
if (value.getDate() === date) {
hour = boundary.getHours();
if (value.getHours() === hour) {
minute = boundary.getMinutes();
watch: {
value(val) {
const { data } = this;
val = this.correctValue(val);
const isEqual = val === data.innerValue;
if (!isEqual) {
this.updateColumnValue(val).then(() => {
this.$emit('input', val);
});
}
}
}
}
return {
[type + "Year"]: year,
[type + "Month"]: month,
[type + "Date"]: date,
[type + "Hour"]: hour,
[type + "Minute"]: minute
};
},
type: 'updateColumns',
minHour: 'updateColumns',
maxHour: 'updateColumns',
minMinute: 'updateColumns',
maxMinute: 'updateColumns'
},
onCancel: function onCancel() {
this.$emit('cancel');
methods: {
getPicker() {
if (this.picker == null) {
const picker = this.picker = this.selectComponent('.van-datetime-picker');
const { setColumnValues } = picker;
picker.setColumnValues = (...args) => setColumnValues.apply(picker, [...args, false]);
}
return this.picker;
},
updateColumns() {
const results = this.getRanges().map(({ type, range }, index) => {
const values = times(range[1] - range[0] + 1, index => {
let value = range[0] + index;
value = type === 'year' ? `${value}` : padZero(value);
return value;
});
return { values };
});
return this.set({ columns: results });
},
getRanges() {
const { data } = this;
if (data.type === 'time') {
return [
{
type: 'hour',
range: [data.minHour, data.maxHour]
},
{
type: 'minute',
range: [data.minMinute, data.maxMinute]
}
];
}
const { maxYear, maxDate, maxMonth, maxHour, maxMinute } = this.getBoundary('max', data.innerValue);
const { minYear, minDate, minMonth, minHour, minMinute } = this.getBoundary('min', data.innerValue);
const result = [
{
type: 'year',
range: [minYear, maxYear]
},
{
type: 'month',
range: [minMonth, maxMonth]
},
{
type: 'day',
range: [minDate, maxDate]
},
{
type: 'hour',
range: [minHour, maxHour]
},
{
type: 'minute',
range: [minMinute, maxMinute]
}
];
if (data.type === 'date')
result.splice(3, 2);
if (data.type === 'year-month')
result.splice(2, 3);
return result;
},
correctValue(value) {
const { data } = this;
// validate value
const isDateType = data.type !== 'time';
if (isDateType && !isValidDate(value)) {
value = data.minDate;
}
else if (!isDateType && !value) {
const { minHour } = data;
value = `${padZero(minHour)}:00`;
}
// time type
if (!isDateType) {
let [hour, minute] = value.split(':');
hour = padZero(range(hour, data.minHour, data.maxHour));
minute = padZero(range(minute, data.minMinute, data.maxMinute));
return `${hour}:${minute}`;
}
// date type
value = Math.max(value, data.minDate);
value = Math.min(value, data.maxDate);
return value;
},
getBoundary(type, innerValue) {
const value = new Date(innerValue);
const boundary = new Date(this.data[`${type}Date`]);
const year = boundary.getFullYear();
let month = 1;
let date = 1;
let hour = 0;
let minute = 0;
if (type === 'max') {
month = 12;
date = getMonthEndDay(value.getFullYear(), value.getMonth() + 1);
hour = 23;
minute = 59;
}
if (value.getFullYear() === year) {
month = boundary.getMonth() + 1;
if (value.getMonth() + 1 === month) {
date = boundary.getDate();
if (value.getDate() === date) {
hour = boundary.getHours();
if (value.getHours() === hour) {
minute = boundary.getMinutes();
}
}
}
}
return {
[`${type}Year`]: year,
[`${type}Month`]: month,
[`${type}Date`]: date,
[`${type}Hour`]: hour,
[`${type}Minute`]: minute
};
},
onCancel() {
this.$emit('cancel');
},
onConfirm() {
this.$emit('confirm', this.data.innerValue);
},
onChange() {
const { data } = this;
let value;
const picker = this.getPicker();
if (data.type === 'time') {
const indexes = picker.getIndexes();
value = `${indexes[0] + data.minHour}:${indexes[1] + data.minMinute}`;
}
else {
const values = picker.getValues();
const year = getTrueValue(values[0]);
const month = getTrueValue(values[1]);
const maxDate = getMonthEndDay(year, month);
let date = getTrueValue(values[2]);
if (data.type === 'year-month') {
date = 1;
}
date = date > maxDate ? maxDate : date;
let hour = 0;
let minute = 0;
if (data.type === 'datetime') {
hour = getTrueValue(values[3]);
minute = getTrueValue(values[4]);
}
value = new Date(year, month - 1, date, hour, minute);
}
value = this.correctValue(value);
this.updateColumnValue(value).then(() => {
this.$emit('input', value);
this.$emit('change', picker);
});
},
updateColumnValue(value) {
let values = [];
const { data } = this;
const picker = this.getPicker();
if (data.type === 'time') {
const pair = value.split(':');
values = [pair[0], pair[1]];
}
else {
const date = new Date(value);
values = [`${date.getFullYear()}`, padZero(date.getMonth() + 1)];
if (data.type === 'date') {
values.push(padZero(date.getDate()));
}
if (data.type === 'datetime') {
values.push(padZero(date.getDate()), padZero(date.getHours()), padZero(date.getMinutes()));
}
}
return this.set({ innerValue: value })
.then(() => this.updateColumns())
.then(() => picker.setValues(values));
}
},
onConfirm: function onConfirm() {
this.$emit('confirm', this.data.innerValue);
},
onChange: function onChange() {
var _this2 = this;
var data = this.data;
var value;
var picker = this.getPicker();
if (data.type === 'time') {
var indexes = picker.getIndexes();
value = indexes[0] + data.minHour + ":" + (indexes[1] + data.minMinute);
} else {
var values = picker.getValues();
var year = getTrueValue(values[0]);
var month = getTrueValue(values[1]);
var maxDate = getMonthEndDay(year, month);
var date = getTrueValue(values[2]);
if (data.type === 'year-month') {
date = 1;
}
date = date > maxDate ? maxDate : date;
var hour = 0;
var minute = 0;
if (data.type === 'datetime') {
hour = getTrueValue(values[3]);
minute = getTrueValue(values[4]);
}
value = new Date(year, month - 1, date, hour, minute);
}
value = this.correctValue(value);
this.updateColumnValue(value).then(function () {
_this2.$emit('input', value);
_this2.$emit('change', picker);
});
},
updateColumnValue: function updateColumnValue(value) {
var _this3 = this;
var values = [];
var data = this.data;
var picker = this.getPicker();
if (data.type === 'time') {
var pair = value.split(':');
values = [pair[0], pair[1]];
} else {
var date = new Date(value);
values = ["" + date.getFullYear(), padZero(date.getMonth() + 1)];
if (data.type === 'date') {
values.push(padZero(date.getDate()));
}
if (data.type === 'datetime') {
values.push(padZero(date.getDate()), padZero(date.getHours()), padZero(date.getMinutes()));
}
}
return this.set({
innerValue: value
}).then(function () {
return _this3.updateColumns();
}).then(function () {
return picker.setValues(values);
});
created() {
const innerValue = this.correctValue(this.data.value);
this.updateColumnValue(innerValue).then(() => {
this.$emit('input', innerValue);
});
}
},
created: function created() {
var _this4 = this;
var innerValue = this.correctValue(this.data.value);
this.updateColumnValue(innerValue).then(function () {
_this4.$emit('input', innerValue);
});
}
});
});

42
dist/dialog/dialog.d.ts vendored Normal 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

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

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

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

183
dist/dialog/index.js vendored

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

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

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

273
dist/field/index.js vendored

@ -1,155 +1,130 @@
import { VantComponent } from '../common/component';
VantComponent({
field: true,
classes: ['input-class'],
props: {
icon: String,
label: String,
error: Boolean,
fixed: Boolean,
focus: Boolean,
center: Boolean,
isLink: Boolean,
leftIcon: String,
disabled: Boolean,
autosize: Boolean,
readonly: Boolean,
required: Boolean,
iconClass: String,
clearable: Boolean,
inputAlign: String,
customClass: String,
confirmType: String,
confirmHold: Boolean,
errorMessage: String,
placeholder: String,
customStyle: String,
useIconSlot: Boolean,
useButtonSlot: Boolean,
showConfirmBar: {
type: Boolean,
value: true
field: true,
classes: ['input-class'],
props: {
size: String,
icon: String,
label: String,
error: Boolean,
fixed: Boolean,
focus: Boolean,
center: Boolean,
isLink: Boolean,
leftIcon: String,
disabled: Boolean,
autosize: Boolean,
readonly: Boolean,
required: Boolean,
iconClass: String,
clearable: Boolean,
inputAlign: String,
customClass: String,
confirmType: String,
confirmHold: Boolean,
errorMessage: String,
placeholder: String,
customStyle: String,
useIconSlot: Boolean,
useButtonSlot: Boolean,
showConfirmBar: {
type: Boolean,
value: true
},
placeholderStyle: String,
adjustPosition: {
type: Boolean,
value: true
},
cursorSpacing: {
type: Number,
value: 50
},
maxlength: {
type: Number,
value: -1
},
type: {
type: String,
value: 'text'
},
border: {
type: Boolean,
value: true
},
titleWidth: {
type: String,
value: '90px'
}
},
placeholderStyle: String,
adjustPosition: {
type: Boolean,
value: true
data: {
showClear: false
},
cursorSpacing: {
type: Number,
value: 50
beforeCreate() {
this.focused = false;
},
maxlength: {
type: Number,
value: -1
},
type: {
type: String,
value: 'text'
},
border: {
type: Boolean,
value: true
},
titleWidth: {
type: String,
value: '90px'
methods: {
onInput(event) {
const { value = '' } = event.detail || {};
this.set({
value,
showClear: this.getShowClear(value)
}, () => {
this.emitChange(value);
});
},
onFocus(event) {
const { value = '', height = 0 } = event.detail || {};
this.$emit('focus', { value, height });
this.focused = true;
this.blurFromClear = false;
this.set({
showClear: this.getShowClear()
});
},
onBlur(event) {
const { value = '', cursor = 0 } = event.detail || {};
this.$emit('blur', { value, cursor });
this.focused = false;
const showClear = this.getShowClear();
if (this.data.value === value) {
this.set({
showClear
});
}
else if (!this.blurFromClear) {
// fix: the handwritten keyboard does not trigger input change
this.set({
value,
showClear
}, () => {
this.emitChange(value);
});
}
},
onClickIcon() {
this.$emit('click-icon');
},
getShowClear(value) {
value = value === undefined ? this.data.value : value;
return (this.data.clearable && this.focused && value && !this.data.readonly);
},
onClear() {
this.blurFromClear = true;
this.set({
value: '',
showClear: this.getShowClear('')
}, () => {
this.emitChange('');
this.$emit('clear', '');
});
},
onConfirm() {
this.$emit('confirm', this.data.value);
},
emitChange(value) {
this.$emit('input', value);
this.$emit('change', value);
}
}
},
data: {
showClear: false
},
beforeCreate: function beforeCreate() {
this.focused = false;
},
methods: {
onInput: function onInput(event) {
var _this = this;
var _ref = event.detail || {},
_ref$value = _ref.value,
value = _ref$value === void 0 ? '' : _ref$value;
this.set({
value: value,
showClear: this.getShowClear(value)
}, function () {
_this.emitChange(value);
});
},
onFocus: function onFocus(event) {
var _ref2 = event.detail || {},
_ref2$value = _ref2.value,
value = _ref2$value === void 0 ? '' : _ref2$value,
_ref2$height = _ref2.height,
height = _ref2$height === void 0 ? 0 : _ref2$height;
this.$emit('focus', {
value: value,
height: height
});
this.focused = true;
this.blurFromClear = false;
this.set({
showClear: this.getShowClear()
});
},
onBlur: function onBlur(event) {
var _this2 = this;
var _ref3 = event.detail || {},
_ref3$value = _ref3.value,
value = _ref3$value === void 0 ? '' : _ref3$value,
_ref3$cursor = _ref3.cursor,
cursor = _ref3$cursor === void 0 ? 0 : _ref3$cursor;
this.$emit('blur', {
value: value,
cursor: cursor
});
this.focused = false;
var showClear = this.getShowClear();
if (this.data.value === value) {
this.set({
showClear: showClear
});
} else if (!this.blurFromClear) {
// fix: the handwritten keyboard does not trigger input change
this.set({
value: value,
showClear: showClear
}, function () {
_this2.emitChange(value);
});
}
},
onClickIcon: function onClickIcon() {
this.$emit('click-icon');
},
getShowClear: function getShowClear(value) {
value = value === undefined ? this.data.value : value;
return this.data.clearable && this.focused && value && !this.data.readonly;
},
onClear: function onClear() {
var _this3 = this;
this.blurFromClear = true;
this.set({
value: '',
showClear: this.getShowClear('')
}, function () {
_this3.emitChange('');
_this3.$emit('clear', '');
});
},
onConfirm: function onConfirm() {
this.$emit('confirm', this.data.value);
},
emitChange: function emitChange(value) {
this.$emit('input', value);
this.$emit('change', value);
}
}
});
});

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

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

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

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

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

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

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

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

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

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

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

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

32
dist/icon/index.js vendored

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

File diff suppressed because one or more lines are too long

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

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

10
dist/info/index.js vendored

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

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

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

28
dist/loading/index.js vendored

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

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

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

42
dist/mixins/basic.js vendored

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

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

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

36
dist/mixins/button.js vendored

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

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

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

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

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

39
dist/mixins/link.js vendored

@ -1,24 +1,17 @@
export var link = Behavior({
properties: {
url: String,
linkType: {
type: String,
value: 'navigateTo'
export const link = Behavior({
properties: {
url: String,
linkType: {
type: String,
value: 'navigateTo'
}
},
methods: {
jumpLink(urlKey = 'url') {
const url = this.data[urlKey];
if (url) {
wx[this.data.linkType]({ url });
}
}
}
},
methods: {
jumpLink: function jumpLink(urlKey) {
if (urlKey === void 0) {
urlKey = 'url';
}
var url = this.data[urlKey];
if (url) {
wx[this.data.linkType]({
url: url
});
}
}
}
});
});

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

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

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

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

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

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

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

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

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

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

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

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

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

40
dist/mixins/touch.js vendored

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

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

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

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

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

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

46
dist/nav-bar/index.js vendored

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

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

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

@ -1,131 +1,128 @@
import { VantComponent } from '../common/component';
var FONT_COLOR = '#ed6a0c';
var BG_COLOR = '#fffbe8';
const FONT_COLOR = '#ed6a0c';
const BG_COLOR = '#fffbe8';
VantComponent({
props: {
text: {
type: String,
value: ''
},
mode: {
type: String,
value: ''
},
url: {
type: String,
value: ''
},
openType: {
type: String,
value: 'navigate'
},
delay: {
type: Number,
value: 0
},
speed: {
type: Number,
value: 50
},
scrollable: {
type: Boolean,
value: true
},
leftIcon: {
type: String,
value: ''
},
color: {
type: String,
value: FONT_COLOR
},
backgroundColor: {
type: String,
value: BG_COLOR
}
},
data: {
show: true,
hasRightIcon: false
},
watch: {
text: function text() {
this.set({}, this.init);
}
},
created: function created() {
if (this.data.mode) {
this.set({
hasRightIcon: true
});
}
this.resetAnimation = wx.createAnimation({
duration: 0,
timingFunction: 'linear'
});
},
destroyed: function destroyed() {
this.timer && clearTimeout(this.timer);
},
methods: {
init: function init() {
var _this = this;
Promise.all([this.getRect('.van-notice-bar__content'), this.getRect('.van-notice-bar__content-wrap')]).then(function (rects) {
var contentRect = rects[0],
wrapRect = rects[1];
if (contentRect == null || wrapRect == null || !contentRect.width || !wrapRect.width) {
return;
props: {
text: {
type: String,
value: ''
},
mode: {
type: String,
value: ''
},
url: {
type: String,
value: ''
},
openType: {
type: String,
value: 'navigate'
},
delay: {
type: Number,
value: 0
},
speed: {
type: Number,
value: 50
},
scrollable: {
type: Boolean,
value: true
},
leftIcon: {
type: String,
value: ''
},
color: {
type: String,
value: FONT_COLOR
},
backgroundColor: {
type: String,
value: BG_COLOR
}
var _this$data = _this.data,
speed = _this$data.speed,
scrollable = _this$data.scrollable,
delay = _this$data.delay;
if (scrollable && wrapRect.width < contentRect.width) {
var duration = contentRect.width / speed * 1000;
_this.wrapWidth = wrapRect.width;
_this.contentWidth = contentRect.width;
_this.duration = duration;
_this.animation = wx.createAnimation({
duration: duration,
timingFunction: 'linear',
delay: delay
});
_this.scroll();
}
});
},
scroll: function scroll() {
var _this2 = this;
this.timer && clearTimeout(this.timer);
this.timer = null;
this.set({
animationData: this.resetAnimation.translateX(this.wrapWidth).step().export()
});
setTimeout(function () {
_this2.set({
animationData: _this2.animation.translateX(-_this2.contentWidth).step().export()
data: {
show: true,
hasRightIcon: false
},
watch: {
text() {
this.set({}, this.init);
}
},
created() {
if (this.data.mode) {
this.set({
hasRightIcon: true
});
}
this.resetAnimation = wx.createAnimation({
duration: 0,
timingFunction: 'linear'
});
}, 20);
this.timer = setTimeout(function () {
_this2.scroll();
}, this.duration);
},
onClickIcon: function onClickIcon() {
this.timer && clearTimeout(this.timer);
this.timer = null;
this.set({
show: false
});
destroyed() {
this.timer && clearTimeout(this.timer);
},
onClick: function onClick(event) {
this.$emit('click', event);
methods: {
init() {
Promise.all([
this.getRect('.van-notice-bar__content'),
this.getRect('.van-notice-bar__content-wrap')
]).then((rects) => {
const [contentRect, wrapRect] = rects;
if (contentRect == null ||
wrapRect == null ||
!contentRect.width ||
!wrapRect.width) {
return;
}
const { speed, scrollable, delay } = this.data;
if (scrollable && wrapRect.width < contentRect.width) {
const duration = (contentRect.width / speed) * 1000;
this.wrapWidth = wrapRect.width;
this.contentWidth = contentRect.width;
this.duration = duration;
this.animation = wx.createAnimation({
duration,
timingFunction: 'linear',
delay
});
this.scroll();
}
});
},
scroll() {
this.timer && clearTimeout(this.timer);
this.timer = null;
this.set({
animationData: this.resetAnimation
.translateX(this.wrapWidth)
.step()
.export()
});
setTimeout(() => {
this.set({
animationData: this.animation
.translateX(-this.contentWidth)
.step()
.export()
});
}, 20);
this.timer = setTimeout(() => {
this.scroll();
}, this.duration);
},
onClickIcon() {
this.timer && clearTimeout(this.timer);
this.timer = null;
this.set({ show: false });
},
onClick(event) {
this.$emit('click', event);
}
}
}
});
});

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

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

71
dist/notify/index.js vendored

@ -1,42 +1,39 @@
import { VantComponent } from '../common/component';
import { RED } from '../common/color';
VantComponent({
props: {
text: String,
color: {
type: String,
value: '#fff'
props: {
text: String,
color: {
type: String,
value: '#fff'
},
backgroundColor: {
type: String,
value: RED
},
duration: {
type: Number,
value: 3000
}
},
backgroundColor: {
type: String,
value: RED
},
duration: {
type: Number,
value: 3000
methods: {
show() {
const { duration } = this.data;
clearTimeout(this.timer);
this.set({
show: true
});
if (duration > 0 && duration !== Infinity) {
this.timer = setTimeout(() => {
this.hide();
}, duration);
}
},
hide() {
clearTimeout(this.timer);
this.set({
show: false
});
}
}
},
methods: {
show: function show() {
var _this = this;
var duration = this.data.duration;
clearTimeout(this.timer);
this.set({
show: true
});
if (duration > 0 && duration !== Infinity) {
this.timer = setTimeout(function () {
_this.hide();
}, duration);
}
},
hide: function hide() {
clearTimeout(this.timer);
this.set({
show: false
});
}
}
});
});

7
dist/notify/notify.d.ts vendored Normal 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

@ -1,34 +1,25 @@
import { isObj } from '../common/utils';
var defaultOptions = {
selector: '#van-notify',
duration: 3000
const defaultOptions = {
selector: '#van-notify',
duration: 3000
};
function parseOptions(text) {
return isObj(text) ? text : {
text: text
};
return isObj(text) ? text : { text };
}
function getContext() {
var pages = getCurrentPages();
return pages[pages.length - 1];
const pages = getCurrentPages();
return pages[pages.length - 1];
}
export default function Notify(options = {}) {
options = Object.assign({}, defaultOptions, parseOptions(options));
const context = options.context || getContext();
const notify = context.selectComponent(options.selector);
delete options.selector;
if (notify) {
notify.set(options);
notify.show();
}
else {
console.warn('未找到 van-notify 节点,请确认 selector 及 context 是否正确');
}
}
export default function Notify(options) {
if (options === void 0) {
options = {};
}
options = Object.assign({}, defaultOptions, parseOptions(options));
var context = options.context || getContext();
var notify = context.selectComponent(options.selector);
delete options.selector;
if (notify) {
notify.set(options);
notify.show();
} else {
console.warn('未找到 van-notify 节点,请确认 selector 及 context 是否正确');
}
}

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

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

38
dist/overlay/index.js vendored

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

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

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

16
dist/panel/index.js vendored

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

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

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

@ -1,144 +1,136 @@
import { VantComponent } from '../common/component';
import { isObj, range } from '../common/utils';
var DEFAULT_DURATION = 200;
const DEFAULT_DURATION = 200;
VantComponent({
classes: ['active-class'],
props: {
valueKey: String,
className: String,
itemHeight: Number,
visibleItemCount: Number,
initialOptions: {
type: Array,
value: []
},
defaultIndex: {
type: Number,
value: 0
}
},
data: {
startY: 0,
offset: 0,
duration: 0,
startOffset: 0,
options: [],
currentIndex: 0
},
beforeCreate: function beforeCreate() {
var _this = this;
var _this$data = this.data,
defaultIndex = _this$data.defaultIndex,
initialOptions = _this$data.initialOptions;
this.set({
currentIndex: defaultIndex,
options: initialOptions
}).then(function () {
_this.setIndex(defaultIndex);
});
},
computed: {
count: function count() {
return this.data.options.length;
},
baseOffset: function baseOffset() {
var data = this.data;
return data.itemHeight * (data.visibleItemCount - 1) / 2;
},
wrapperStyle: function wrapperStyle() {
var data = this.data;
return ["transition: " + data.duration + "ms", "transform: translate3d(0, " + (data.offset + data.baseOffset) + "px, 0)", "line-height: " + data.itemHeight + "px"].join('; ');
}
},
watch: {
defaultIndex: function defaultIndex(value) {
this.setIndex(value);
}
},
methods: {
onTouchStart: function onTouchStart(event) {
this.set({
startY: event.touches[0].clientY,
startOffset: this.data.offset,
duration: 0
});
},
onTouchMove: function onTouchMove(event) {
var data = this.data;
var deltaY = event.touches[0].clientY - data.startY;
this.set({
offset: range(data.startOffset + deltaY, -(data.count * data.itemHeight), data.itemHeight)
});
},
onTouchEnd: function onTouchEnd() {
var data = this.data;
if (data.offset !== data.startOffset) {
this.set({
duration: DEFAULT_DURATION
});
var index = range(Math.round(-data.offset / data.itemHeight), 0, data.count - 1);
this.setIndex(index, true);
}
},
onClickItem: function onClickItem(event) {
var index = event.currentTarget.dataset.index;
this.setIndex(index, true);
},
adjustIndex: function adjustIndex(index) {
var data = this.data;
index = range(index, 0, data.count);
for (var i = index; i < data.count; i++) {
if (!this.isDisabled(data.options[i])) return i;
}
for (var _i = index - 1; _i >= 0; _i--) {
if (!this.isDisabled(data.options[_i])) return _i;
}
},
isDisabled: function isDisabled(option) {
return isObj(option) && option.disabled;
},
getOptionText: function getOptionText(option) {
var data = this.data;
return isObj(option) && data.valueKey in option ? option[data.valueKey] : option;
},
setIndex: function setIndex(index, userAction) {
var _this2 = this;
var data = this.data;
index = this.adjustIndex(index) || 0;
var offset = -index * data.itemHeight;
if (index !== data.currentIndex) {
return this.set({
offset: offset,
currentIndex: index
}).then(function () {
userAction && _this2.$emit('change', index);
});
} else {
return this.set({
offset: offset
});
}
},
setValue: function setValue(value) {
var options = this.data.options;
for (var i = 0; i < options.length; i++) {
if (this.getOptionText(options[i]) === value) {
return this.setIndex(i);
classes: ['active-class'],
props: {
valueKey: String,
className: String,
itemHeight: Number,
visibleItemCount: Number,
initialOptions: {
type: Array,
value: []
},
defaultIndex: {
type: Number,
value: 0
}
}
return Promise.resolve();
},
getValue: function getValue() {
var data = this.data;
return data.options[data.currentIndex];
data: {
startY: 0,
offset: 0,
duration: 0,
startOffset: 0,
options: [],
currentIndex: 0
},
beforeCreate() {
const { defaultIndex, initialOptions } = this.data;
this.set({
currentIndex: defaultIndex,
options: initialOptions
}).then(() => {
this.setIndex(defaultIndex);
});
},
computed: {
count() {
return this.data.options.length;
},
baseOffset() {
const { data } = this;
return (data.itemHeight * (data.visibleItemCount - 1)) / 2;
},
wrapperStyle() {
const { data } = this;
return [
`transition: ${data.duration}ms`,
`transform: translate3d(0, ${data.offset + data.baseOffset}px, 0)`,
`line-height: ${data.itemHeight}px`
].join('; ');
}
},
watch: {
defaultIndex(value) {
this.setIndex(value);
}
},
methods: {
onTouchStart(event) {
this.set({
startY: event.touches[0].clientY,
startOffset: this.data.offset,
duration: 0
});
},
onTouchMove(event) {
const { data } = this;
const deltaY = event.touches[0].clientY - data.startY;
this.set({
offset: range(data.startOffset + deltaY, -(data.count * data.itemHeight), data.itemHeight)
});
},
onTouchEnd() {
const { data } = this;
if (data.offset !== data.startOffset) {
this.set({
duration: DEFAULT_DURATION
});
const index = range(Math.round(-data.offset / data.itemHeight), 0, data.count - 1);
this.setIndex(index, true);
}
},
onClickItem(event) {
const { index } = event.currentTarget.dataset;
this.setIndex(index, true);
},
adjustIndex(index) {
const { data } = this;
index = range(index, 0, data.count);
for (let i = index; i < data.count; i++) {
if (!this.isDisabled(data.options[i]))
return i;
}
for (let i = index - 1; i >= 0; i--) {
if (!this.isDisabled(data.options[i]))
return i;
}
},
isDisabled(option) {
return isObj(option) && option.disabled;
},
getOptionText(option) {
const { data } = this;
return isObj(option) && data.valueKey in option
? option[data.valueKey]
: option;
},
setIndex(index, userAction) {
const { data } = this;
index = this.adjustIndex(index) || 0;
const offset = -index * data.itemHeight;
if (index !== data.currentIndex) {
return this.set({ offset, currentIndex: index }).then(() => {
userAction && this.$emit('change', index);
});
}
else {
return this.set({ offset });
}
},
setValue(value) {
const { options } = this.data;
for (let i = 0; i < options.length; i++) {
if (this.getOptionText(options[i]) === value) {
return this.setIndex(i);
}
}
return Promise.resolve();
},
getValue() {
const { data } = this;
return data.options[data.currentIndex];
}
}
}
});
});

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

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

318
dist/picker/index.js vendored

@ -1,185 +1,147 @@
import { VantComponent } from '../common/component';
function isSimple(columns) {
return columns.length && !columns[0].values;
return columns.length && !columns[0].values;
}
VantComponent({
classes: ['active-class', 'toolbar-class', 'column-class'],
props: {
title: String,
loading: Boolean,
showToolbar: Boolean,
confirmButtonText: String,
cancelButtonText: String,
visibleItemCount: {
type: Number,
value: 5
},
valueKey: {
type: String,
value: 'text'
},
itemHeight: {
type: Number,
value: 44
},
columns: {
type: Array,
value: [],
observer: function observer(columns) {
if (columns === void 0) {
columns = [];
classes: ['active-class', 'toolbar-class', 'column-class'],
props: {
title: String,
loading: Boolean,
showToolbar: Boolean,
confirmButtonText: String,
cancelButtonText: String,
visibleItemCount: {
type: Number,
value: 5
},
valueKey: {
type: String,
value: 'text'
},
itemHeight: {
type: Number,
value: 44
},
columns: {
type: Array,
value: [],
observer(columns = []) {
this.simple = isSimple(columns);
this.children = this.selectAllComponents('.van-picker__column');
if (Array.isArray(this.children) && this.children.length) {
this.setColumns().catch(() => { });
}
}
}
this.simple = isSimple(columns);
this.children = this.selectAllComponents('.van-picker__column');
if (Array.isArray(this.children) && this.children.length) {
this.setColumns().catch(function () {});
},
beforeCreate() {
this.children = [];
},
methods: {
noop() { },
setColumns() {
const { data } = this;
const columns = this.simple ? [{ values: data.columns }] : data.columns;
const stack = columns.map((column, index) => this.setColumnValues(index, column.values));
return Promise.all(stack);
},
emit(event) {
const { type } = event.currentTarget.dataset;
if (this.simple) {
this.$emit(type, {
value: this.getColumnValue(0),
index: this.getColumnIndex(0)
});
}
else {
this.$emit(type, {
value: this.getValues(),
index: this.getIndexes()
});
}
},
onChange(event) {
if (this.simple) {
this.$emit('change', {
picker: this,
value: this.getColumnValue(0),
index: this.getColumnIndex(0)
});
}
else {
this.$emit('change', {
picker: this,
value: this.getValues(),
index: event.currentTarget.dataset.index
});
}
},
// get column instance by index
getColumn(index) {
return this.children[index];
},
// get column value by index
getColumnValue(index) {
const column = this.getColumn(index);
return column && column.getValue();
},
// set column value by index
setColumnValue(index, value) {
const column = this.getColumn(index);
if (column == null) {
return Promise.reject('setColumnValue: 对应列不存在');
}
return column.setValue(value);
},
// get column option index by column index
getColumnIndex(columnIndex) {
return (this.getColumn(columnIndex) || {}).data.currentIndex;
},
// set column option index by column index
setColumnIndex(columnIndex, optionIndex) {
const column = this.getColumn(columnIndex);
if (column == null) {
return Promise.reject('setColumnIndex: 对应列不存在');
}
return column.setIndex(optionIndex);
},
// get options of column by index
getColumnValues(index) {
return (this.children[index] || {}).data.options;
},
// set options of column by index
setColumnValues(index, options, needReset = true) {
const column = this.children[index];
if (column == null) {
return Promise.reject('setColumnValues: 对应列不存在');
}
const isSame = JSON.stringify(column.data.options) === JSON.stringify(options);
if (isSame) {
return Promise.resolve();
}
return column.set({ options }).then(() => {
if (needReset) {
column.setIndex(0);
}
});
},
// get values of all columns
getValues() {
return this.children.map((child) => child.getValue());
},
// set values of all columns
setValues(values) {
const stack = values.map((value, index) => this.setColumnValue(index, value));
return Promise.all(stack);
},
// get indexes of all columns
getIndexes() {
return this.children.map((child) => child.data.currentIndex);
},
// set indexes of all columns
setIndexes(indexes) {
const stack = indexes.map((optionIndex, columnIndex) => this.setColumnIndex(columnIndex, optionIndex));
return Promise.all(stack);
}
}
}
},
beforeCreate: function beforeCreate() {
this.children = [];
},
methods: {
noop: function noop() {},
setColumns: function setColumns() {
var _this = this;
var data = this.data;
var columns = this.simple ? [{
values: data.columns
}] : data.columns;
var stack = columns.map(function (column, index) {
return _this.setColumnValues(index, column.values);
});
return Promise.all(stack);
},
emit: function emit(event) {
var type = event.currentTarget.dataset.type;
if (this.simple) {
this.$emit(type, {
value: this.getColumnValue(0),
index: this.getColumnIndex(0)
});
} else {
this.$emit(type, {
value: this.getValues(),
index: this.getIndexes()
});
}
},
onChange: function onChange(event) {
if (this.simple) {
this.$emit('change', {
picker: this,
value: this.getColumnValue(0),
index: this.getColumnIndex(0)
});
} else {
this.$emit('change', {
picker: this,
value: this.getValues(),
index: event.currentTarget.dataset.index
});
}
},
// get column instance by index
getColumn: function getColumn(index) {
return this.children[index];
},
// get column value by index
getColumnValue: function getColumnValue(index) {
var column = this.getColumn(index);
return column && column.getValue();
},
// set column value by index
setColumnValue: function setColumnValue(index, value) {
var column = this.getColumn(index);
if (column == null) {
return Promise.reject('setColumnValue: 对应列不存在');
}
return column.setValue(value);
},
// get column option index by column index
getColumnIndex: function getColumnIndex(columnIndex) {
return (this.getColumn(columnIndex) || {}).data.currentIndex;
},
// set column option index by column index
setColumnIndex: function setColumnIndex(columnIndex, optionIndex) {
var column = this.getColumn(columnIndex);
if (column == null) {
return Promise.reject('setColumnIndex: 对应列不存在');
}
return column.setIndex(optionIndex);
},
// get options of column by index
getColumnValues: function getColumnValues(index) {
return (this.children[index] || {}).data.options;
},
// set options of column by index
setColumnValues: function setColumnValues(index, options, needReset) {
if (needReset === void 0) {
needReset = true;
}
var column = this.children[index];
if (column == null) {
return Promise.reject('setColumnValues: 对应列不存在');
}
var isSame = JSON.stringify(column.data.options) === JSON.stringify(options);
if (isSame) {
return Promise.resolve();
}
return column.set({
options: options
}).then(function () {
if (needReset) {
column.setIndex(0);
}
});
},
// get values of all columns
getValues: function getValues() {
return this.children.map(function (child) {
return child.getValue();
});
},
// set values of all columns
setValues: function setValues(values) {
var _this2 = this;
var stack = values.map(function (value, index) {
return _this2.setColumnValue(index, value);
});
return Promise.all(stack);
},
// get indexes of all columns
getIndexes: function getIndexes() {
return this.children.map(function (child) {
return child.data.currentIndex;
});
},
// set indexes of all columns
setIndexes: function setIndexes(indexes) {
var _this3 = this;
var stack = indexes.map(function (optionIndex, columnIndex) {
return _this3.setColumnIndex(columnIndex, optionIndex);
});
return Promise.all(stack);
}
}
});
});

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

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

90
dist/popup/index.js vendored

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

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

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

120
dist/progress/index.js vendored

@ -1,67 +1,65 @@
import { VantComponent } from '../common/component';
import { BLUE } from '../common/color';
VantComponent({
props: {
inactive: Boolean,
percentage: Number,
pivotText: String,
pivotColor: String,
showPivot: {
type: Boolean,
value: true
props: {
inactive: Boolean,
percentage: Number,
pivotText: String,
pivotColor: String,
showPivot: {
type: Boolean,
value: true
},
color: {
type: String,
value: BLUE
},
textColor: {
type: String,
value: '#fff'
}
},
color: {
type: String,
value: BLUE
data: {
pivotWidth: 0,
progressWidth: 0
},
textColor: {
type: String,
value: '#fff'
watch: {
pivotText: 'getWidth',
showPivot: 'getWidth'
},
computed: {
portionStyle() {
const width = (this.data.progressWidth - this.data.pivotWidth) * this.data.percentage / 100 + 'px';
const background = this.getCurrentColor();
return `width: ${width}; background: ${background}; `;
},
pivotStyle() {
const color = this.data.textColor;
const background = this.data.pivotColor || this.getCurrentColor();
return `color: ${color}; background: ${background}`;
},
text() {
return this.data.pivotText || this.data.percentage + '%';
}
},
mounted() {
this.getWidth();
},
methods: {
getCurrentColor() {
return this.data.inactive ? '#cacaca' : this.data.color;
},
getWidth() {
this.getRect('.van-progress').then(rect => {
this.set({
progressWidth: rect.width
});
});
this.getRect('.van-progress__pivot').then(rect => {
this.set({
pivotWidth: rect.width || 0
});
});
}
}
},
data: {
pivotWidth: 0,
progressWidth: 0
},
watch: {
pivotText: 'getWidth',
showPivot: 'getWidth'
},
computed: {
portionStyle: function portionStyle() {
var width = (this.data.progressWidth - this.data.pivotWidth) * this.data.percentage / 100 + 'px';
var background = this.getCurrentColor();
return "width: " + width + "; background: " + background + "; ";
},
pivotStyle: function pivotStyle() {
var color = this.data.textColor;
var background = this.data.pivotColor || this.getCurrentColor();
return "color: " + color + "; background: " + background;
},
text: function text() {
return this.data.pivotText || this.data.percentage + '%';
}
},
mounted: function mounted() {
this.getWidth();
},
methods: {
getCurrentColor: function getCurrentColor() {
return this.data.inactive ? '#cacaca' : this.data.color;
},
getWidth: function getWidth() {
var _this = this;
this.getRect('.van-progress').then(function (rect) {
_this.set({
progressWidth: rect.width
});
});
this.getRect('.van-progress__pivot').then(function (rect) {
_this.set({
pivotWidth: rect.width || 0
});
});
}
}
});
});

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

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

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

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

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

54
dist/radio/index.js vendored

@ -1,32 +1,32 @@
import { VantComponent } from '../common/component';
VantComponent({
field: true,
relation: {
name: 'radio-group',
type: 'ancestor'
},
classes: ['icon-class', 'label-class'],
props: {
name: null,
value: null,
disabled: Boolean,
labelDisabled: Boolean,
labelPosition: String,
checkedColor: String
},
methods: {
emitChange: function emitChange(value) {
var instance = this.getRelationNodes('../radio-group/index')[0] || this;
instance.$emit('input', value);
instance.$emit('change', value);
field: true,
relation: {
name: 'radio-group',
type: 'ancestor'
},
onChange: function onChange(event) {
this.emitChange(event.detail.value);
classes: ['icon-class', 'label-class'],
props: {
name: null,
value: null,
disabled: Boolean,
labelDisabled: Boolean,
labelPosition: String,
checkedColor: String
},
onClickLabel: function onClickLabel() {
if (!this.data.disabled && !this.data.labelDisabled) {
this.emitChange(this.data.name);
}
methods: {
emitChange(value) {
const instance = this.getRelationNodes('../radio-group/index')[0] || this;
instance.$emit('input', value);
instance.$emit('change', value);
},
onChange(event) {
this.emitChange(event.detail.value);
},
onClickLabel() {
if (!this.data.disabled && !this.data.labelDisabled) {
this.emitChange(this.data.name);
}
}
}
}
});
});

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

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

171
dist/rate/index.js vendored

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

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