Merge branch 'dev' of https://github.com/youzan/vant into dev
This commit is contained in:
@@ -72,6 +72,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/* eslint-disable camelcase */
|
||||
import { create } from '../utils';
|
||||
import Field from '../field';
|
||||
import Cell from '../cell';
|
||||
@@ -149,7 +150,7 @@ export default create({
|
||||
this.isEdit = !!val.id;
|
||||
},
|
||||
deep: true
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
|
||||
+57
-88
@@ -1,26 +1,21 @@
|
||||
<template>
|
||||
<div class="van-area">
|
||||
<picker
|
||||
ref="picker"
|
||||
showToolbar
|
||||
:title="title"
|
||||
valueKey="name"
|
||||
:columns="areaColumns"
|
||||
@change="onChange"
|
||||
@confirm="$emit('confirm', $event)"
|
||||
@cancel="$emit('cancel', $event)"
|
||||
/>
|
||||
</div>
|
||||
<picker
|
||||
class="van-area"
|
||||
ref="picker"
|
||||
showToolbar
|
||||
valueKey="name"
|
||||
:title="title"
|
||||
:columns="columns"
|
||||
@change="onChange"
|
||||
@confirm="$emit('confirm', $event)"
|
||||
@cancel="$emit('cancel', $event)"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { create } from '../utils';
|
||||
import Picker from '../picker';
|
||||
|
||||
const PROVINCE_TYPE = 'provice';
|
||||
const CITY_TYPE = 'city';
|
||||
const COUNTY_TYPE = 'county';
|
||||
|
||||
export default create({
|
||||
name: 'van-area',
|
||||
|
||||
@@ -40,52 +35,33 @@ export default create({
|
||||
},
|
||||
|
||||
computed: {
|
||||
DEFAULT_PROVINCE() {
|
||||
return {
|
||||
code: '-1',
|
||||
name: this.$t('province')
|
||||
};
|
||||
},
|
||||
DEFAULT_CITY() {
|
||||
return {
|
||||
code: '-1',
|
||||
name: this.$t('city')
|
||||
};
|
||||
},
|
||||
DEFAULT_COUNTY() {
|
||||
return {
|
||||
code: '-1',
|
||||
name: this.$t('district')
|
||||
};
|
||||
},
|
||||
areaColumns() {
|
||||
const areaList = this.areaList;
|
||||
|
||||
if (!areaList || (areaList && typeof areaList.province_list !== 'object')) return [];
|
||||
|
||||
columns() {
|
||||
const columns = [];
|
||||
const curValue = this.value || '';
|
||||
const { columnsNum } = this;
|
||||
const { areaList } = this;
|
||||
|
||||
if (!areaList || typeof areaList.province_list !== 'object') {
|
||||
return columns;
|
||||
}
|
||||
|
||||
const code = this.value || '';
|
||||
const columnsNum = +this.columnsNum;
|
||||
|
||||
columns.push({
|
||||
values: [this.DEFAULT_PROVINCE].concat(this.computedAreaList(PROVINCE_TYPE)),
|
||||
className: 'van-area__province',
|
||||
defaultIndex: this.getAreaIndex(PROVINCE_TYPE, curValue)
|
||||
values: this.getList('province'),
|
||||
defaultIndex: this.getIndex('province', code)
|
||||
});
|
||||
|
||||
if (+columnsNum > 1) {
|
||||
if (columnsNum > 1) {
|
||||
columns.push({
|
||||
values: [this.DEFAULT_CITY].concat(this.computedAreaList(CITY_TYPE, curValue.slice(0, 2))),
|
||||
className: 'van-area__city',
|
||||
defaultIndex: this.getAreaIndex(CITY_TYPE, curValue)
|
||||
values: this.getList('city', code.slice(0, 2)),
|
||||
defaultIndex: this.getIndex('city', code)
|
||||
});
|
||||
}
|
||||
|
||||
if (+columnsNum > 2) {
|
||||
if (columnsNum > 2) {
|
||||
columns.push({
|
||||
values: [this.DEFAULT_COUNTY].concat(this.computedAreaList(COUNTY_TYPE, curValue.slice(0, 4))),
|
||||
className: 'van-area__county',
|
||||
defaultIndex: this.getAreaIndex(COUNTY_TYPE, curValue)
|
||||
values: this.getList('county', code.slice(0, 4)),
|
||||
defaultIndex: this.getIndex('county', code)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -95,37 +71,40 @@ export default create({
|
||||
|
||||
methods: {
|
||||
// 根据省市县类型和对应的`code`获取对应列表
|
||||
computedAreaList(type, code) {
|
||||
const result = [];
|
||||
const curAreaList = this.areaList;
|
||||
const areaList = type === PROVINCE_TYPE
|
||||
? curAreaList.province_list
|
||||
: (type === CITY_TYPE ? curAreaList.city_list : curAreaList.county_list);
|
||||
getList(type, code) {
|
||||
const { areaList } = this;
|
||||
const list =
|
||||
type === 'province'
|
||||
? areaList.province_list
|
||||
: type === 'city' ? areaList.city_list : areaList.county_list;
|
||||
|
||||
for (const i in areaList) {
|
||||
// 如果为省类型直接插入,因为省那一列是全部显示的
|
||||
// 其他类型需要找到前缀相同的
|
||||
if (type === PROVINCE_TYPE || (code && i.slice(0, code.length) === code)) {
|
||||
result.push({
|
||||
code: i,
|
||||
name: areaList[i]
|
||||
});
|
||||
}
|
||||
let result = Object.keys(list).map(code => ({
|
||||
code,
|
||||
name: list[code]
|
||||
}));
|
||||
|
||||
if (type !== 'province' && code) {
|
||||
result = result.filter(item => item.code.indexOf(code) === 0);
|
||||
}
|
||||
|
||||
result.unshift({
|
||||
code: '-1',
|
||||
name: this.$t(type)
|
||||
});
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
// 获取对应省市县在列表中的索引
|
||||
getAreaIndex(type, code) {
|
||||
const compareNum = type === PROVINCE_TYPE
|
||||
? 2
|
||||
: (type === CITY_TYPE ? 4 : 6);
|
||||
const areaList = this.computedAreaList(type, code.slice(0, compareNum - 2));
|
||||
getIndex(type, code) {
|
||||
const compareNum = type === 'province' ? 2 : type === 'city' ? 4 : 6;
|
||||
const areaList = this.getList(type, code.slice(0, compareNum - 2));
|
||||
|
||||
for (let i = 0; i < areaList.length; i++) {
|
||||
if (+areaList[i].code.slice(0, compareNum) === +code.slice(0, compareNum)) {
|
||||
return i + 1;
|
||||
if (
|
||||
+areaList[i].code.slice(0, compareNum) === +code.slice(0, compareNum)
|
||||
) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,25 +115,15 @@ export default create({
|
||||
const code = values[index].code;
|
||||
// 处理省变化
|
||||
if (index === 0) {
|
||||
picker.setColumnValues(
|
||||
1,
|
||||
[this.DEFAULT_CITY].concat(this.computedAreaList(CITY_TYPE, code.slice(0, 2)))
|
||||
);
|
||||
picker.setColumnValues(
|
||||
2,
|
||||
[this.DEFAULT_COUNTY].concat(this.computedAreaList(COUNTY_TYPE, code.slice(0, 4)))
|
||||
);
|
||||
picker.setColumnValues(1, this.getList('city', code.slice(0, 2)));
|
||||
picker.setColumnValues(2, this.getList('county', code.slice(0, 4)));
|
||||
} else if (index === 1) {
|
||||
picker.setColumnValues(
|
||||
2,
|
||||
[this.DEFAULT_COUNTY].concat(this.computedAreaList(COUNTY_TYPE, code.slice(0, 4)))
|
||||
);
|
||||
picker.setColumnValues(2, this.getList('county', code.slice(0, 4)));
|
||||
}
|
||||
},
|
||||
|
||||
getValues() {
|
||||
const { picker } = this.$refs;
|
||||
return picker ? picker.getValues() : [];
|
||||
return this.$refs.picker ? this.$refs.picker.getValues() : [];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
import { create } from '../utils';
|
||||
import Picker from '../picker';
|
||||
|
||||
const isValidDate = date => Object.prototype.toString.call(date) === "[object Date]" && !isNaN(date.getTime());
|
||||
const isValidDate = date => Object.prototype.toString.call(date) === '[object Date]' && !isNaN(date.getTime());
|
||||
|
||||
export default create({
|
||||
name: 'van-datetime-picker',
|
||||
|
||||
@@ -58,7 +58,7 @@ export default {
|
||||
vanArea: {
|
||||
province: 'Province',
|
||||
city: 'City',
|
||||
district: 'District'
|
||||
county: 'District'
|
||||
},
|
||||
vanAddressEdit: {
|
||||
areaTitle: 'Area',
|
||||
|
||||
@@ -61,7 +61,7 @@ export default {
|
||||
vanArea: {
|
||||
province: '选择省份',
|
||||
city: '选择城市',
|
||||
district: '选择地区'
|
||||
county: '选择地区'
|
||||
},
|
||||
vanAddressEdit: {
|
||||
areaTitle: '收件地区',
|
||||
|
||||
@@ -9,12 +9,18 @@
|
||||
@touchend="blurKey"
|
||||
@touchcancel="blurKey"
|
||||
@animationend="onAnimationEnd"
|
||||
@webkitAnimationEnd="onAnimationEnd"
|
||||
>
|
||||
<div class="van-number-keyboard__title van-hairline--top" v-if="title">
|
||||
<div class="van-number-keyboard__title van-hairline--top" v-if="title || closeButtonText">
|
||||
<span>{{ title }}</span>
|
||||
<span
|
||||
class="van-number-keyboard__close"
|
||||
v-text="closeButtonText"
|
||||
@click="blurKeyboard"
|
||||
/>
|
||||
</div>
|
||||
<i
|
||||
v-for="(key, index) in keys"
|
||||
<i
|
||||
v-for="(key, index) in keys"
|
||||
v-text="key"
|
||||
:data-key="index"
|
||||
class="van-hairline"
|
||||
@@ -35,6 +41,11 @@ export default create({
|
||||
|
||||
props: {
|
||||
show: Boolean,
|
||||
closeButtonText: String,
|
||||
theme: {
|
||||
type: String,
|
||||
default: 'default'
|
||||
},
|
||||
extraKey: {
|
||||
type: String,
|
||||
default: ''
|
||||
@@ -51,6 +62,10 @@ export default create({
|
||||
showDeleteKey: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
hideOnClickOutside: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
},
|
||||
|
||||
@@ -103,7 +118,7 @@ export default create({
|
||||
|
||||
methods: {
|
||||
handler(action) {
|
||||
if (action !== this.handlerStatus) {
|
||||
if (action !== this.handlerStatus && this.hideOnClickOutside) {
|
||||
this.handlerStatus = action;
|
||||
document.body[(action ? 'add' : 'remove') + 'EventListener']('touchstart', this.blurKeyboard);
|
||||
}
|
||||
|
||||
@@ -79,7 +79,8 @@ export default create({
|
||||
const pageCount = this.computedPageCount;
|
||||
|
||||
// Default page limits
|
||||
let startPage = 1, endPage = pageCount;
|
||||
let startPage = 1;
|
||||
let endPage = pageCount;
|
||||
const isMaxSized = this.showPageSize !== undefined && this.showPageSize < pageCount;
|
||||
|
||||
// recompute if showPageSize
|
||||
@@ -97,19 +98,19 @@ export default create({
|
||||
|
||||
// Add page number links
|
||||
for (let number = startPage; number <= endPage; number++) {
|
||||
let page = this.makePage(number, number, number === this.value);
|
||||
const page = this.makePage(number, number, number === this.value);
|
||||
pages.push(page);
|
||||
}
|
||||
|
||||
// Add links to move between page sets
|
||||
if (isMaxSized && this.showPageSize > 0 && this.forceEllipses) {
|
||||
if (startPage > 1) {
|
||||
let previousPageSet = this.makePage(startPage - 1, '...', false);
|
||||
const previousPageSet = this.makePage(startPage - 1, '...', false);
|
||||
pages.unshift(previousPageSet);
|
||||
}
|
||||
|
||||
if (endPage < pageCount) {
|
||||
let nextPageSet = this.makePage(endPage + 1, '...', false);
|
||||
const nextPageSet = this.makePage(endPage + 1, '...', false);
|
||||
pages.push(nextPageSet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,9 @@ export default create({
|
||||
|
||||
currentValue: {
|
||||
get() {
|
||||
return this.isGroup && this.parentGroup ? this.parentGroup.value : this.value;
|
||||
return this.isGroup && this.parentGroup
|
||||
? this.parentGroup.value
|
||||
: this.value;
|
||||
},
|
||||
|
||||
set(val) {
|
||||
@@ -55,8 +57,8 @@ export default create({
|
||||
|
||||
isDisabled() {
|
||||
return this.isGroup && this.parentGroup
|
||||
? this.parentGroup.disabled || this.disabled
|
||||
: this.disabled;
|
||||
? this.parentGroup.disabled || this.disabled
|
||||
: this.disabled;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ export default create({
|
||||
width: `${tab.offsetWidth || 0}px`,
|
||||
transform: `translate3d(${tab.offsetLeft || 0}px, 0, 0)`,
|
||||
transitionDuration: `${this.duration}s`
|
||||
}
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
@@ -197,7 +197,7 @@ export default create({
|
||||
if (++count < frames) {
|
||||
raf(animate);
|
||||
}
|
||||
}
|
||||
};
|
||||
animate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable */
|
||||
export default function email(value) {
|
||||
const reg = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
|
||||
return reg.test(value);
|
||||
|
||||
@@ -14,7 +14,21 @@
|
||||
text-align: center;
|
||||
color: $gray-dark;
|
||||
font-size: 12px;
|
||||
line-height: 25px;
|
||||
height: 30px;
|
||||
line-height: 30px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
&__close {
|
||||
right: 0;
|
||||
color: $blue;
|
||||
font-size: 14px;
|
||||
padding: 0 15px;
|
||||
position: absolute;
|
||||
|
||||
&:active {
|
||||
background-color: $active-color;
|
||||
}
|
||||
}
|
||||
|
||||
i {
|
||||
|
||||
Reference in New Issue
Block a user