[Improvement] extract component common part (#703)

This commit is contained in:
neverland 2018-03-16 17:10:46 +08:00 committed by GitHub
parent f26ad3b912
commit ffd72e5442
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
81 changed files with 174 additions and 207 deletions

View File

@ -17,19 +17,20 @@ components.forEach(componentName => {
// Analyze component dependencies // Analyze component dependencies
function analyzeDependencies(componentName, libDir) { function analyzeDependencies(componentName, libDir) {
const checkList = ['base']; const checkList = ['base'];
const whiteList = ['icon', 'loading', 'cell', 'button'];
search(dependencyTree({ search(dependencyTree({
directory: libDir, directory: libDir,
filename: path.resolve(libDir, componentName, 'index.js'), filename: path.resolve(libDir, componentName, 'index.js'),
filter: path => path.indexOf(`vant${SEP}lib${SEP}`) !== -1 filter: path => path.indexOf(`vant${SEP}lib${SEP}`) !== -1
}), checkList); }), checkList, whiteList);
return checkList.filter(component => checkComponentHasStyle(component)); return checkList.filter(component => checkComponentHasStyle(component));
} }
function search(tree, checkList) { function search(tree, checkList, whiteList) {
tree && Object.keys(tree).forEach(key => { tree && Object.keys(tree).forEach(key => {
search(tree[key], checkList); search(tree[key], checkList, whiteList);
const component = key.split(`${SEP}vant${SEP}lib${SEP}`)[1].replace(`${SEP}index.js`, '').replace(`mixins${SEP}`, ''); const component = key.split(`${SEP}vant${SEP}lib${SEP}`)[1].replace(`${SEP}index.js`, '').replace(`mixins${SEP}`, '');
if (checkList.indexOf(component) === -1) { if (checkList.indexOf(component) === -1 && whiteList.indexOf(component) === -1) {
checkList.push(component); checkList.push(component);
} }
}); });

View File

@ -38,7 +38,7 @@ import { create } from '../utils';
import Popup from '../mixins/popup'; import Popup from '../mixins/popup';
export default create({ export default create({
name: 'van-actionsheet', name: 'actionsheet',
mixins: [Popup], mixins: [Popup],

View File

@ -41,17 +41,13 @@
<script> <script>
import { create } from '../utils'; import { create } from '../utils';
import Field from '../field'; import Field from '../field';
import Cell from '../cell';
import CellGroup from '../cell-group';
import { isAndroid } from '../utils'; import { isAndroid } from '../utils';
export default create({ export default create({
name: 'van-address-edit-detail', name: 'address-edit-detail',
components: { components: {
Field, Field
Cell,
CellGroup
}, },
props: { props: {

View File

@ -5,7 +5,7 @@
maxlength="15" maxlength="15"
:placeholder="$t('name')" :placeholder="$t('name')"
:label="$t('label.name', computedAddressText)" :label="$t('label.name', computedAddressText)"
v-model="currentInfo.name" v-model="data.name"
:error="errorInfo.name" :error="errorInfo.name"
@focus="onFocus('name')" @focus="onFocus('name')"
/> />
@ -13,7 +13,7 @@
type="tel" type="tel"
:label="$t('tel')" :label="$t('tel')"
:placeholder="$t('telPlaceholder')" :placeholder="$t('telPlaceholder')"
v-model="currentInfo.tel" v-model="data.tel"
:error="errorInfo.tel" :error="errorInfo.tel"
@focus="onFocus('tel')" @focus="onFocus('tel')"
/> />
@ -23,17 +23,17 @@
:title="$t('area')" :title="$t('area')"
@click="showArea = true" @click="showArea = true"
> >
<span>{{ currentInfo.province || $t('province') }}</span> <span>{{ data.province || $t('province') }}</span>
<span>{{ currentInfo.city || $t('city') }}</span> <span>{{ data.city || $t('city') }}</span>
<span>{{ currentInfo.county || $t('county') }}</span> <span>{{ data.county || $t('county') }}</span>
</cell> </cell>
<address-edit-detail <address-edit-detail
:value="currentInfo.address_detail" :value="data.address_detail"
:is-error="errorInfo.address_detail" :is-error="errorInfo.address_detail"
:show-search-result="showSearchResult" :show-search-result="showSearchResult"
:search-result="searchResult" :search-result="searchResult"
@focus="onFocus('address_detail')" @focus="onFocus('address_detail')"
@blur="onDetailBlur" @blur="detailFocused = false"
@input="onChangeDetail" @input="onChangeDetail"
@select-search="$emit('select-search', $event)" @select-search="$emit('select-search', $event)"
/> />
@ -43,7 +43,7 @@
type="tel" type="tel"
:label="$t('label.postal')" :label="$t('label.postal')"
:placeholder="$t('placeholder.postal')" :placeholder="$t('placeholder.postal')"
v-model="currentInfo.postal_code" v-model="data.postal_code"
maxlength="6" maxlength="6"
class="van-hairline--top" class="van-hairline--top"
:error="errorInfo.postal_code" :error="errorInfo.postal_code"
@ -53,7 +53,7 @@
<switch-cell <switch-cell
v-if="showSetDefault" v-if="showSetDefault"
v-show="!hideBottomFields" v-show="!hideBottomFields"
v-model="currentInfo.is_default" v-model="data.is_default"
:title="$t('defaultAddress', computedAddressText)" :title="$t('defaultAddress', computedAddressText)"
/> />
</cell-group> </cell-group>
@ -69,7 +69,7 @@
<van-area <van-area
ref="area" ref="area"
:loading="!areaListLoaded" :loading="!areaListLoaded"
:value="currentInfo.area_code" :value="data.area_code"
:area-list="areaList" :area-list="areaList"
@confirm="onAreaConfirm" @confirm="onAreaConfirm"
@cancel="showArea = false" @cancel="showArea = false"
@ -82,8 +82,6 @@
/* eslint-disable camelcase */ /* eslint-disable camelcase */
import { create, isObj } from '../utils'; import { create, isObj } from '../utils';
import Field from '../field'; import Field from '../field';
import Cell from '../cell';
import CellGroup from '../cell-group';
import VanButton from '../button'; import VanButton from '../button';
import Popup from '../popup'; import Popup from '../popup';
import Toast from '../toast'; import Toast from '../toast';
@ -106,12 +104,10 @@ const defaultAddress = {
}; };
export default create({ export default create({
name: 'van-address-edit', name: 'address-edit',
components: { components: {
Field, Field,
Cell,
CellGroup,
SwitchCell, SwitchCell,
VanButton, VanButton,
Popup, Popup,
@ -144,7 +140,7 @@ export default create({
data() { data() {
return { return {
showArea: false, showArea: false,
currentInfo: { data: {
...defaultAddress, ...defaultAddress,
...this.addressInfo ...this.addressInfo
}, },
@ -162,7 +158,7 @@ export default create({
watch: { watch: {
addressInfo: { addressInfo: {
handler(val) { handler(val) {
this.currentInfo = { this.data = {
...defaultAddress, ...defaultAddress,
...val ...val
}; };
@ -176,8 +172,8 @@ export default create({
}, },
areaList() { areaList() {
if (this.currentInfo.area_code) { if (this.data.area_code) {
this.setAreaCode(this.currentInfo.area_code); this.setAreaCode(this.data.area_code);
} }
} }
}, },
@ -204,12 +200,8 @@ export default create({
this.$emit('focus', key); this.$emit('focus', key);
}, },
onDetailBlur() {
this.detailFocused = false;
},
onChangeDetail(val) { onChangeDetail(val) {
this.currentInfo.address_detail = val; this.data.address_detail = val;
this.$emit('change-detail', val); this.$emit('change-detail', val);
}, },
@ -223,7 +215,7 @@ export default create({
}, },
assignAreaValues(values) { assignAreaValues(values) {
Object.assign(this.currentInfo, { Object.assign(this.data, {
province: values[0].name, province: values[0].name,
city: values[1].name, city: values[1].name,
county: values[2].name, county: values[2].name,
@ -253,12 +245,12 @@ export default create({
}); });
if (isValid && !this.isSaving) { if (isValid && !this.isSaving) {
this.$emit('save', this.currentInfo); this.$emit('save', this.data);
} }
}, },
getErrorMessageByKey(key) { getErrorMessageByKey(key) {
const value = this.currentInfo[key]; const value = this.data[key];
const { $t } = this; const { $t } = this;
switch (key) { switch (key) {
@ -283,7 +275,7 @@ export default create({
Dialog.confirm({ Dialog.confirm({
message: this.$t('confirmDelete', this.computedAddressText) message: this.$t('confirmDelete', this.computedAddressText)
}).then(() => { }).then(() => {
this.$emit('delete', this.currentInfo); this.$emit('delete', this.data);
}); });
}, },
@ -295,7 +287,7 @@ export default create({
// set area code to area component // set area code to area component
setAreaCode(code) { setAreaCode(code) {
this.currentInfo.area_code = code; this.data.area_code = code;
this.$nextTick(() => { this.$nextTick(() => {
this.$nextTick(() => { this.$nextTick(() => {
const { area } = this.$refs; const { area } = this.$refs;

View File

@ -23,18 +23,14 @@
<script> <script>
import { create } from '../utils'; import { create } from '../utils';
import Cell from '../cell';
import CellGroup from '../cell-group';
import Radio from '../radio'; import Radio from '../radio';
import RadioGroup from '../radio-group'; import RadioGroup from '../radio-group';
export default create({ export default create({
name: 'van-address-list', name: 'address-list',
components: { components: {
Cell,
Radio, Radio,
CellGroup,
RadioGroup RadioGroup
}, },

View File

@ -20,7 +20,7 @@ import { create, isObj } from '../utils';
import Picker from '../picker'; import Picker from '../picker';
export default create({ export default create({
name: 'van-area', name: 'area',
components: { components: {
Picker Picker

View File

@ -8,7 +8,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-badge-group', name: 'badge-group',
props: { props: {
activeKey: { activeKey: {

View File

@ -9,7 +9,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-badge', name: 'badge',
props: { props: {
url: String, url: String,

View File

@ -27,7 +27,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-button', name: 'button',
props: { props: {
text: String, text: String,

View File

@ -30,7 +30,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-card', name: 'card',
props: { props: {
thumb: String, thumb: String,

View File

@ -5,10 +5,12 @@
</template> </template>
<script> <script>
import { create } from '../utils'; import install from '../utils/install';
export default create({ export default {
name: 'van-cell-group', install,
name: 'cell-group',
props: { props: {
border: { border: {
@ -16,5 +18,5 @@ export default create({
default: true default: true
} }
} }
}); };
</script> </script>

View File

@ -27,7 +27,7 @@ import Clickoutside from '../utils/clickoutside';
const THRESHOLD = 0.15; const THRESHOLD = 0.15;
export default create({ export default create({
name: 'van-cell-swipe', name: 'cell-swipe',
props: { props: {
onClose: Function, onClose: Function,

View File

@ -37,11 +37,18 @@
</template> </template>
<script> <script>
import { create } from '../utils'; import Icon from '../icon';
import install from '../utils/install';
import RouterLink from '../mixins/router-link'; import RouterLink from '../mixins/router-link';
export default create({ export default {
name: 'van-cell', install,
name: 'cell',
components: {
Icon
},
mixins: [RouterLink], mixins: [RouterLink],
@ -65,5 +72,5 @@ export default create({
this.routerLink(); this.routerLink();
} }
} }
}); };
</script> </script>

View File

@ -8,7 +8,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-checkbox-group', name: 'checkbox-group',
props: { props: {
value: {}, value: {},

View File

@ -21,7 +21,7 @@ import { create, isDef } from '../utils';
import findParent from '../mixins/find-parent'; import findParent from '../mixins/find-parent';
export default create({ export default create({
name: 'van-checkbox', name: 'checkbox',
mixins: [findParent], mixins: [findParent],

View File

@ -15,7 +15,7 @@ import { create } from '../utils';
import { raf, cancel } from '../utils/raf'; import { raf, cancel } from '../utils/raf';
export default create({ export default create({
name: 'van-circle', name: 'circle',
props: { props: {
text: String, text: String,

View File

@ -12,7 +12,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-col', name: 'col',
props: { props: {
span: [Number, String], span: [Number, String],

View File

@ -16,19 +16,14 @@
</template> </template>
<script> <script>
import Cell from '../cell';
import findParent from '../mixins/find-parent'; import findParent from '../mixins/find-parent';
import { create, isDef } from '../utils'; import { create, isDef } from '../utils';
export default create({ export default create({
name: 'van-collapse-item', name: 'collapse-item',
mixins: [findParent], mixins: [findParent],
components: {
Cell
},
props: { props: {
name: [String, Number], name: [String, Number],
title: String title: String

View File

@ -8,7 +8,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-collapse', name: 'collapse',
model: { model: {
prop: 'activeNames' prop: 'activeNames'

View File

@ -21,7 +21,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-contact-card', name: 'contact-card',
props: { props: {
tel: String, tel: String,

View File

@ -2,7 +2,7 @@
<div class="van-contact-edit"> <div class="van-contact-edit">
<cell-group> <cell-group>
<field <field
v-model="currentInfo.name" v-model="data.name"
maxlength="30" maxlength="30"
:label="$t('contact')" :label="$t('contact')"
:placeholder="$t('name')" :placeholder="$t('name')"
@ -10,7 +10,7 @@
@focus="onFocus('name')" @focus="onFocus('name')"
/> />
<field <field
v-model="currentInfo.tel" v-model="data.tel"
type="tel" type="tel"
:label="$t('tel')" :label="$t('tel')"
:placeholder="$t('telPlaceholder')" :placeholder="$t('telPlaceholder')"
@ -28,19 +28,17 @@
<script> <script>
import Field from '../field'; import Field from '../field';
import VanButton from '../button'; import VanButton from '../button';
import CellGroup from '../cell-group';
import Dialog from '../dialog'; import Dialog from '../dialog';
import Toast from '../toast'; import Toast from '../toast';
import validateMobile from '../utils/validate/mobile'; import validateMobile from '../utils/validate/mobile';
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-contact-edit', name: 'contact-edit',
components: { components: {
Field, Field,
VanButton, VanButton
CellGroup
}, },
props: { props: {
@ -63,7 +61,7 @@ export default create({
data() { data() {
return { return {
currentInfo: this.contactInfo, data: this.contactInfo,
errorInfo: { errorInfo: {
name: false, name: false,
tel: false tel: false
@ -73,7 +71,7 @@ export default create({
watch: { watch: {
contactInfo(val) { contactInfo(val) {
this.currentInfo = val; this.data = val;
} }
}, },
@ -83,7 +81,7 @@ export default create({
}, },
getErrorMessageByKey(key) { getErrorMessageByKey(key) {
const value = this.currentInfo[key]; const value = this.data[key];
switch (key) { switch (key) {
case 'name': case 'name':
return value ? value.length <= 15 ? '' : this.$t('nameOverlimit') : this.$t('nameEmpty'); return value ? value.length <= 15 ? '' : this.$t('nameOverlimit') : this.$t('nameEmpty');
@ -108,7 +106,7 @@ export default create({
}); });
if (isValid && !this.isSaving) { if (isValid && !this.isSaving) {
this.$emit('save', this.currentInfo); this.$emit('save', this.data);
} }
}, },
@ -120,7 +118,7 @@ export default create({
Dialog.confirm({ Dialog.confirm({
message: this.$t('confirmDelete') message: this.$t('confirmDelete')
}).then(() => { }).then(() => {
this.$emit('delete', this.currentInfo); this.$emit('delete', this.data);
}); });
} }
} }

View File

@ -22,19 +22,15 @@
</template> </template>
<script> <script>
import Cell from '../cell';
import Radio from '../radio'; import Radio from '../radio';
import CellGroup from '../cell-group';
import RadioGroup from '../radio-group'; import RadioGroup from '../radio-group';
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-contact-list', name: 'contact-list',
components: { components: {
Cell,
Radio, Radio,
CellGroup,
RadioGroup RadioGroup
}, },

View File

@ -6,16 +6,9 @@
<script> <script>
import { create } from '../utils'; import { create } from '../utils';
import Cell from '../cell';
import CellGroup from '../cell-group';
export default create({ export default create({
name: 'van-coupon-cell', name: 'coupon-cell',
components: {
Cell,
CellGroup
},
model: { model: {
prop: 'chosenCoupon' prop: 'chosenCoupon'

View File

@ -22,7 +22,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-coupon-item', name: 'coupon-item',
props: { props: {
data: Object, data: Object,

View File

@ -49,19 +49,15 @@
<script> <script>
import { create } from '../utils'; import { create } from '../utils';
import Cell from '../cell';
import CellGroup from '../cell-group';
import CouponItem from './Item'; import CouponItem from './Item';
import Field from '../field'; import Field from '../field';
import VanButton from '../button'; import VanButton from '../button';
export default create({ export default create({
name: 'van-coupon-list', name: 'coupon-list',
components: { components: {
VanButton, VanButton,
Cell,
CellGroup,
Field, Field,
CouponItem CouponItem
}, },

View File

@ -17,7 +17,7 @@ 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({ export default create({
name: 'van-datetime-picker', name: 'datetime-picker',
components: { components: {
Picker Picker

View File

@ -36,7 +36,7 @@ import VanButton from '../button';
import Popup from '../mixins/popup'; import Popup from '../mixins/popup';
export default create({ export default create({
name: 'van-dialog', name: 'dialog',
components: { components: {
VanButton VanButton

View File

@ -50,17 +50,12 @@
<script> <script>
import { create } from '../utils'; import { create } from '../utils';
import Cell from '../cell';
export default create({ export default create({
name: 'van-field', name: 'field',
inheritAttrs: false, inheritAttrs: false,
components: {
Cell
},
props: { props: {
type: { type: {
type: String, type: String,

View File

@ -17,7 +17,7 @@ import VanButton from '../button';
import RouterLink from '../mixins/router-link'; import RouterLink from '../mixins/router-link';
export default create({ export default create({
name: 'van-goods-action-big-btn', name: 'goods-action-big-btn',
mixins: [RouterLink], mixins: [RouterLink],

View File

@ -10,7 +10,7 @@ import { create } from '../utils';
import RouterLink from '../mixins/router-link'; import RouterLink from '../mixins/router-link';
export default create({ export default create({
name: 'van-goods-action-mini-btn', name: 'goods-action-mini-btn',
mixins: [RouterLink], mixins: [RouterLink],

View File

@ -8,6 +8,6 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-goods-action' name: 'goods-action'
}); });
</script> </script>

View File

@ -11,7 +11,7 @@ import install from '../utils/install';
export default { export default {
install, install,
name: 'van-icon', name: 'icon',
props: { props: {
name: String, name: String,

View File

@ -22,7 +22,7 @@ import Swipe from '../swipe';
import SwipeItem from '../swipe-item'; import SwipeItem from '../swipe-item';
export default create({ export default create({
name: 'van-image-preview', name: 'image-preview',
mixins: [Popup], mixins: [Popup],

View File

@ -16,7 +16,7 @@ import utils from '../utils/scroll';
import { on, off } from '../utils/event'; import { on, off } from '../utils/event';
export default create({ export default create({
name: 'van-list', name: 'list',
model: { model: {
prop: 'loading' prop: 'loading'

View File

@ -15,7 +15,7 @@ import install from '../utils/install';
export default { export default {
install, install,
name: 'van-loading', name: 'loading',
props: { props: {
size: String, size: String,

View File

@ -13,7 +13,7 @@
<script> <script>
export default { export default {
name: 'van-modal', name: 'modal',
props: { props: {
visible: Boolean, visible: Boolean,

View File

@ -25,7 +25,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-nav-bar', name: 'nav-bar',
props: { props: {
title: String, title: String,

View File

@ -29,7 +29,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-notice-bar', name: 'notice-bar',
props: { props: {
text: String, text: String,

View File

@ -39,7 +39,7 @@ import { create } from '../utils';
import Key from './Key'; import Key from './Key';
export default create({ export default create({
name: 'van-number-keyboard', name: 'number-keyboard',
components: { Key }, components: { Key },

View File

@ -34,7 +34,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-pagination', name: 'pagination',
props: { props: {
value: Number, value: Number,

View File

@ -20,7 +20,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-panel', name: 'panel',
props: { props: {
desc: String, desc: String,
title: String, title: String,

View File

@ -17,7 +17,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-password-input', name: 'password-input',
props: { props: {
info: String, info: String,

View File

@ -31,7 +31,7 @@ const DEFAULT_DURATION = 200;
const range = (num, arr) => Math.min(Math.max(num, arr[0]), arr[1]); const range = (num, arr) => Math.min(Math.max(num, arr[0]), arr[1]);
export default create({ export default create({
name: 'van-picker-column', name: 'picker-column',
props: { props: {
valueKey: String, valueKey: String,

View File

@ -33,7 +33,7 @@ import PickerColumn from './PickerColumn';
import deepClone from '../utils/deep-clone'; import deepClone from '../utils/deep-clone';
export default create({ export default create({
name: 'van-picker', name: 'picker',
components: { components: {
PickerColumn PickerColumn

View File

@ -11,7 +11,7 @@ import { create } from '../utils';
import Popup from '../mixins/popup'; import Popup from '../mixins/popup';
export default create({ export default create({
name: 'van-popup', name: 'popup',
mixins: [Popup], mixins: [Popup],

View File

@ -9,7 +9,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-progress', name: 'progress',
props: { props: {
inactive: Boolean, inactive: Boolean,

View File

@ -33,7 +33,7 @@ import { create } from '../utils';
import scrollUtils from '../utils/scroll'; import scrollUtils from '../utils/scroll';
export default create({ export default create({
name: 'van-pull-refresh', name: 'pull-refresh',
props: { props: {
pullingText: String, pullingText: String,

View File

@ -8,7 +8,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-radio-group', name: 'radio-group',
props: { props: {
value: {}, value: {},

View File

@ -25,7 +25,7 @@ import { create } from '../utils';
import findParent from '../mixins/find-parent'; import findParent from '../mixins/find-parent';
export default create({ export default create({
name: 'van-radio', name: 'radio',
mixins: [findParent], mixins: [findParent],

View File

@ -8,7 +8,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-row', name: 'row',
props: { props: {
gutter: { gutter: {

View File

@ -28,7 +28,7 @@ import { create } from '../utils';
import Clickoutside from '../utils/clickoutside'; import Clickoutside from '../utils/clickoutside';
export default create({ export default create({
name: 'van-search', name: 'search',
inheritAttrs: false, inheritAttrs: false,

View File

@ -120,7 +120,7 @@ import { create } from '../utils';
const { QUOTA_LIMIT } = LIMIT_TYPE; const { QUOTA_LIMIT } = LIMIT_TYPE;
export default create({ export default create({
name: 'van-sku', name: 'sku',
components: { components: {
Popup, Popup,

View File

@ -20,7 +20,7 @@ import VanButton from '../../button';
import { create } from '../../utils'; import { create } from '../../utils';
export default create({ export default create({
name: 'van-sku-actions', name: 'sku-actions',
components: { components: {
VanButton VanButton

View File

@ -15,7 +15,7 @@
import { create } from '../../utils'; import { create } from '../../utils';
export default create({ export default create({
name: 'van-sku-header', name: 'sku-header',
props: { props: {
skuEventBus: Object, skuEventBus: Object,

View File

@ -46,7 +46,7 @@ import Loading from '../../loading';
import { create } from '../../utils'; import { create } from '../../utils';
export default create({ export default create({
name: 'van-sku-img-uploader', name: 'sku-img-uploader',
components: { components: {
'van-uploader': Uploader, 'van-uploader': Uploader,

View File

@ -30,20 +30,16 @@
<script> <script>
import { create } from '../../utils'; import { create } from '../../utils';
import Field from '../../field'; import Field from '../../field';
import CellGroup from '../../cell-group';
import Cell from '../../cell';
import validateEmail from '../../utils/validate/email'; import validateEmail from '../../utils/validate/email';
import validateNumber from '../../utils/validate/number'; import validateNumber from '../../utils/validate/number';
import SkuImgUploader from './SkuImgUploader'; import SkuImgUploader from './SkuImgUploader';
export default create({ export default create({
name: 'van-sku-messages', name: 'sku-messages',
components: { components: {
SkuImgUploader, SkuImgUploader,
Field, Field
Cell,
CellGroup
}, },
props: { props: {

View File

@ -9,7 +9,7 @@
<script> <script>
export default { export default {
name: 'van-sku-row', name: 'sku-row',
props: { props: {
skuRow: Object skuRow: Object

View File

@ -15,7 +15,7 @@
import { create } from '../../utils'; import { create } from '../../utils';
export default create({ export default create({
name: 'van-sku-row-item', name: 'sku-row-item',
props: { props: {
skuEventBus: Object, skuEventBus: Object,

View File

@ -25,7 +25,7 @@ import { LIMIT_TYPE } from '../constants';
const { QUOTA_LIMIT, STOCK_LIMIT } = LIMIT_TYPE; const { QUOTA_LIMIT, STOCK_LIMIT } = LIMIT_TYPE;
export default create({ export default create({
name: 'van-sku-stepper', name: 'sku-stepper',
components: { components: {
Stepper Stepper

View File

@ -15,7 +15,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-step', name: 'step',
beforeCreate() { beforeCreate() {
this.$parent.steps.push(this); this.$parent.steps.push(this);

View File

@ -24,7 +24,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-stepper', name: 'stepper',
props: { props: {
value: {}, value: {},

View File

@ -22,7 +22,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-steps', name: 'steps',
props: { props: {
icon: String, icon: String,

View File

@ -24,7 +24,7 @@ import VanButton from '../button';
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-submit-bar', name: 'submit-bar',
components: { components: {
VanButton VanButton

View File

@ -8,7 +8,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-swipe-item', name: 'swipe-item',
data() { data() {
return { return {

View File

@ -25,7 +25,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-swipe', name: 'swipe',
props: { props: {
autoplay: Number, autoplay: Number,

View File

@ -5,15 +5,13 @@
</template> </template>
<script> <script>
import Cell from '../cell';
import VanSwitch from '../switch'; import VanSwitch from '../switch';
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-switch-cell', name: 'switch-cell',
components: { components: {
Cell,
VanSwitch VanSwitch
}, },

View File

@ -11,7 +11,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-switch', name: 'switch',
props: { props: {
value: Boolean, value: Boolean,

View File

@ -9,7 +9,7 @@ import { create } from '../utils';
import findParent from '../mixins/find-parent'; import findParent from '../mixins/find-parent';
export default create({ export default create({
name: 'van-tab', name: 'tab',
mixins: [findParent], mixins: [findParent],

View File

@ -17,7 +17,7 @@ import { create } from '../utils';
import RouterLink from '../mixins/router-link'; import RouterLink from '../mixins/router-link';
export default create({ export default create({
name: 'van-tabbar-item', name: 'tabbar-item',
mixins: [RouterLink], mixins: [RouterLink],

View File

@ -8,7 +8,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-tabbar', name: 'tabbar',
data() { data() {
return { return {

View File

@ -40,7 +40,7 @@ import VanNode from '../utils/node';
import scrollUtils from '../utils/scroll'; import scrollUtils from '../utils/scroll';
export default create({ export default create({
name: 'van-tabs', name: 'tabs',
components: { components: {
VanNode VanNode

View File

@ -15,7 +15,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-tag', name: 'tag',
props: { props: {
type: String, type: String,
mark: Boolean, mark: Boolean,

View File

@ -24,7 +24,7 @@ import { create } from '../utils';
const STYLE_LIST = ['success', 'fail', 'loading']; const STYLE_LIST = ['success', 'fail', 'loading'];
export default create({ export default create({
name: 'van-toast', name: 'toast',
props: { props: {
mask: Boolean, mask: Boolean,

View File

@ -31,7 +31,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-tree-select', name: 'tree-select',
props: { props: {
items: { items: {

View File

@ -16,7 +16,7 @@
import { create } from '../utils'; import { create } from '../utils';
export default create({ export default create({
name: 'van-uploader', name: 'uploader',
inheritAttrs: false, inheritAttrs: false,

View File

@ -2,18 +2,24 @@
* Create a component with common options * Create a component with common options
*/ */
import '../locale'; import '../locale';
import Icon from '../icon';
import i18n from '../mixins/i18n'; import i18n from '../mixins/i18n';
import install from './install'; import install from './install';
import Icon from '../icon';
import Loading from '../loading'; import Loading from '../loading';
import Cell from '../cell';
import CellGroup from '../cell-group';
export default function(sfc) { export default function(sfc) {
sfc.name = 'van-' + sfc.name;
sfc.install = sfc.install || install; sfc.install = sfc.install || install;
sfc.mixins = sfc.mixins || []; sfc.mixins = sfc.mixins || [];
sfc.mixins.push(i18n); sfc.mixins.push(i18n);
sfc.components = sfc.components || {}; sfc.components = Object.assign(sfc.components || {}, {
sfc.components.icon = Icon; Icon,
sfc.components.loading = Loading; Loading,
Cell,
CellGroup
});
return sfc; return sfc;
}; };

View File

@ -1,4 +1,4 @@
export default function mobile(value) { export default function mobile(value) {
return /^((\+86)|(86))?(1)\d{10}$/.test(value) || value = value.replace(/[^-|\d]/g, '');
/^\+?(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1|)-?\d{1,14}$/.test(String(value)); return /^((\+86)|(86))?(1)\d{10}$/.test(value) || /^0[0-9\-]{10,13}$/.test(value);
} }

View File

@ -7,3 +7,7 @@
@import "./common/ellipsis.css"; @import "./common/ellipsis.css";
@import "./common/hairline.css"; @import "./common/hairline.css";
@import "./common/animation.css"; @import "./common/animation.css";
@import './icon.css';
@import './loading.css';
@import './button.css';
@import './cell.css';

View File

@ -4,10 +4,6 @@
/* base */ /* base */
@import './base.css'; @import './base.css';
@import './icon.css';
@import './loading.css';
@import './button.css';
@import './cell.css';
/* common components */ /* common components */
@import './col.css'; @import './col.css';

View File

@ -99,42 +99,42 @@ describe('AddressEdit', () => {
const saveButton = wrapper.find('.van-button')[0]; const saveButton = wrapper.find('.van-button')[0];
// name empty // name empty
wrapper.vm.currentInfo.name = ''; wrapper.vm.data.name = '';
saveButton.trigger('click'); saveButton.trigger('click');
expect(wrapper.vm.errorInfo['name']).to.be.true; expect(wrapper.vm.errorInfo['name']).to.be.true;
wrapper.find('.van-field__control')[0].trigger('focus'); wrapper.find('.van-field__control')[0].trigger('focus');
expect(wrapper.vm.errorInfo['name']).to.be.false; expect(wrapper.vm.errorInfo['name']).to.be.false;
// name too long // name too long
wrapper.vm.currentInfo.name = '111111111111111111111111111'; wrapper.vm.data.name = '111111111111111111111111111';
saveButton.trigger('click'); saveButton.trigger('click');
expect(wrapper.vm.errorInfo['name']).to.be.true; expect(wrapper.vm.errorInfo['name']).to.be.true;
wrapper.find('.van-field__control')[0].trigger('focus'); wrapper.find('.van-field__control')[0].trigger('focus');
expect(wrapper.vm.errorInfo['name']).to.be.false; expect(wrapper.vm.errorInfo['name']).to.be.false;
// tel empty // tel empty
wrapper.vm.currentInfo.name = '123'; wrapper.vm.data.name = '123';
wrapper.vm.currentInfo.tel = ''; wrapper.vm.data.tel = '';
saveButton.trigger('click'); saveButton.trigger('click');
expect(wrapper.vm.errorInfo['tel']).to.be.true; expect(wrapper.vm.errorInfo['tel']).to.be.true;
wrapper.find('.van-field__control')[1].trigger('focus'); wrapper.find('.van-field__control')[1].trigger('focus');
expect(wrapper.vm.errorInfo['tel']).to.be.false; expect(wrapper.vm.errorInfo['tel']).to.be.false;
// area_code empty // area_code empty
wrapper.vm.currentInfo.tel = '13000000000'; wrapper.vm.data.tel = '13000000000';
wrapper.vm.currentInfo.area_code = ''; wrapper.vm.data.area_code = '';
saveButton.trigger('click'); saveButton.trigger('click');
expect(wrapper.vm.errorInfo['area_code']).to.be.true; expect(wrapper.vm.errorInfo['area_code']).to.be.true;
// area_code invalid // area_code invalid
wrapper.vm.currentInfo.tel = '13000000000'; wrapper.vm.data.tel = '13000000000';
wrapper.vm.currentInfo.area_code = '-1'; wrapper.vm.data.area_code = '-1';
saveButton.trigger('click'); saveButton.trigger('click');
expect(wrapper.vm.errorInfo['area_code']).to.be.true; expect(wrapper.vm.errorInfo['area_code']).to.be.true;
// address_detail empty // address_detail empty
wrapper.vm.currentInfo.area_code = '100000'; wrapper.vm.data.area_code = '100000';
wrapper.vm.currentInfo.address_detail = ''; wrapper.vm.data.address_detail = '';
saveButton.trigger('click'); saveButton.trigger('click');
expect(wrapper.vm.errorInfo['address_detail']).to.be.true; expect(wrapper.vm.errorInfo['address_detail']).to.be.true;
wrapper.find('.van-field__control')[2].trigger('focus'); wrapper.find('.van-field__control')[2].trigger('focus');
@ -145,26 +145,26 @@ describe('AddressEdit', () => {
for (let i = 0; i < 300; i++) { for (let i = 0; i < 300; i++) {
longAddress += '1'; longAddress += '1';
} }
wrapper.vm.currentInfo.address_detail = longAddress; wrapper.vm.data.address_detail = longAddress;
saveButton.trigger('click'); saveButton.trigger('click');
expect(wrapper.vm.errorInfo['address_detail']).to.be.true; expect(wrapper.vm.errorInfo['address_detail']).to.be.true;
wrapper.find('.van-field__control')[2].trigger('focus'); wrapper.find('.van-field__control')[2].trigger('focus');
expect(wrapper.vm.errorInfo['address_detail']).to.be.false; expect(wrapper.vm.errorInfo['address_detail']).to.be.false;
// postal_code invalid // postal_code invalid
wrapper.vm.currentInfo.address_detail = '123'; wrapper.vm.data.address_detail = '123';
wrapper.vm.currentInfo.postal_code = '123'; wrapper.vm.data.postal_code = '123';
saveButton.trigger('click'); saveButton.trigger('click');
expect(wrapper.vm.errorInfo['postal_code']).to.be.true; expect(wrapper.vm.errorInfo['postal_code']).to.be.true;
wrapper.find('.van-field__control')[3].trigger('focus'); wrapper.find('.van-field__control')[3].trigger('focus');
expect(wrapper.vm.errorInfo['postal_code']).to.be.false; expect(wrapper.vm.errorInfo['postal_code']).to.be.false;
// valid result // valid result
wrapper.vm.currentInfo.postal_code = '123456'; wrapper.vm.data.postal_code = '123456';
saveButton.trigger('click'); saveButton.trigger('click');
// not show postal_code // not show postal_code
wrapper.vm.currentInfo.postal_code = '156'; wrapper.vm.data.postal_code = '156';
wrapper.vm.showPostal = false; wrapper.vm.showPostal = false;
saveButton.trigger('click'); saveButton.trigger('click');
expect(wrapper.vm.errorInfo['postal_code']).to.be.false; expect(wrapper.vm.errorInfo['postal_code']).to.be.false;
@ -235,17 +235,17 @@ describe('AddressEdit', () => {
wrapper.vm.onAreaConfirm([{ code: -1 }]); wrapper.vm.onAreaConfirm([{ code: -1 }]);
wrapper.vm.onAreaConfirm([{ code: 1 }, { code: -1 }]); wrapper.vm.onAreaConfirm([{ code: 1 }, { code: -1 }]);
wrapper.vm.onAreaConfirm([{ code: 1 }, { code: 1 }, { code: -1 }]); wrapper.vm.onAreaConfirm([{ code: 1 }, { code: 1 }, { code: -1 }]);
expect(wrapper.vm.currentInfo['area_code']).to.equal(''); expect(wrapper.vm.data['area_code']).to.equal('');
wrapper.vm.onAreaConfirm([ wrapper.vm.onAreaConfirm([
{ name: '浙江省' }, { name: '浙江省' },
{ name: '杭州市' }, { name: '杭州市' },
{ name: '西湖区', code: '123456' } { name: '西湖区', code: '123456' }
]); ]);
expect(wrapper.vm.currentInfo['province']).to.equal('浙江省'); expect(wrapper.vm.data['province']).to.equal('浙江省');
expect(wrapper.vm.currentInfo['city']).to.equal('杭州市'); expect(wrapper.vm.data['city']).to.equal('杭州市');
expect(wrapper.vm.currentInfo['county']).to.equal('西湖区'); expect(wrapper.vm.data['county']).to.equal('西湖区');
expect(wrapper.vm.currentInfo['area_code']).to.equal('123456'); expect(wrapper.vm.data['area_code']).to.equal('123456');
}); });
it('delete address', done => { it('delete address', done => {
@ -308,7 +308,7 @@ describe('AddressEdit', () => {
wrapper.vm.$nextTick(() => { wrapper.vm.$nextTick(() => {
wrapper.find('.van-field__icon')[0].trigger('touchstart'); wrapper.find('.van-field__icon')[0].trigger('touchstart');
wrapper.vm.$nextTick(() => { wrapper.vm.$nextTick(() => {
expect(wrapper.vm.currentInfo.address_detail).to.equal(''); expect(wrapper.vm.data.address_detail).to.equal('');
done(); done();
}); });
}); });
@ -352,7 +352,7 @@ describe('AddressEdit', () => {
wrapper.setProps({ addressInfo }); wrapper.setProps({ addressInfo });
wrapper.vm.$nextTick(() => { wrapper.vm.$nextTick(() => {
expect(wrapper.vm.currentInfo.name).to.equal('123'); expect(wrapper.vm.data.name).to.equal('123');
done(); done();
}); });
}); });
@ -375,7 +375,7 @@ describe('AddressEdit', () => {
wrapper.vm.setAreaCode('110101'); wrapper.vm.setAreaCode('110101');
setTimeout(() => { setTimeout(() => {
expect(wrapper.vm.currentInfo.area_code).to.eql('110101'); expect(wrapper.vm.data.area_code).to.eql('110101');
expect(wrapper.vm.getArea()).to.eql([ expect(wrapper.vm.getArea()).to.eql([
{ code: '110000', name: '北京市' }, { code: '110000', name: '北京市' },
{ code: '110100', name: '北京市' }, { code: '110100', name: '北京市' },
@ -399,22 +399,22 @@ describe('AddressEdit', () => {
} }
}); });
expect(wrapper.vm.currentInfo.city).to.equal(''); expect(wrapper.vm.data.city).to.equal('');
wrapper.vm.areaList = areaList; wrapper.vm.areaList = areaList;
setTimeout(() => { setTimeout(() => {
expect(wrapper.vm.currentInfo.city).to.equal('温州市'); expect(wrapper.vm.data.city).to.equal('温州市');
wrapper.vm.addressInfo = { area_code: '' }; wrapper.vm.addressInfo = { area_code: '' };
wrapper.vm.areaList = {}; wrapper.vm.areaList = {};
setTimeout(() => { setTimeout(() => {
expect(wrapper.vm.currentInfo.city).to.equal(''); expect(wrapper.vm.data.city).to.equal('');
wrapper.vm.areaList = areaList; wrapper.vm.areaList = areaList;
wrapper.vm.addressInfo = { area_code: '330304' }; wrapper.vm.addressInfo = { area_code: '330304' };
setTimeout(() => { setTimeout(() => {
expect(wrapper.vm.currentInfo.city).to.equal('温州市'); expect(wrapper.vm.data.city).to.equal('温州市');
done(); done();
}, 50); }, 50);
}); });

View File

@ -179,36 +179,36 @@ describe('ContactEdit', () => {
const saveButton = wrapper.find('.van-button')[0]; const saveButton = wrapper.find('.van-button')[0];
// name empty // name empty
wrapper.vm.contactInfo.name = ''; wrapper.vm.data.name = '';
saveButton.trigger('click'); saveButton.trigger('click');
expect(wrapper.vm.errorInfo['name']).to.be.true; expect(wrapper.vm.errorInfo['name']).to.be.true;
wrapper.find('.van-field__control')[0].trigger('focus'); wrapper.find('.van-field__control')[0].trigger('focus');
expect(wrapper.vm.errorInfo['name']).to.be.false; expect(wrapper.vm.errorInfo['name']).to.be.false;
// name too long // name too long
wrapper.vm.contactInfo.name = '111111111111111111111111111'; wrapper.vm.data.name = '111111111111111111111111111';
saveButton.trigger('click'); saveButton.trigger('click');
expect(wrapper.vm.errorInfo['name']).to.be.true; expect(wrapper.vm.errorInfo['name']).to.be.true;
wrapper.find('.van-field__control')[0].trigger('focus'); wrapper.find('.van-field__control')[0].trigger('focus');
expect(wrapper.vm.errorInfo['name']).to.be.false; expect(wrapper.vm.errorInfo['name']).to.be.false;
// tel empty // tel empty
wrapper.vm.contactInfo.name = '123'; wrapper.vm.data.name = '123';
wrapper.vm.contactInfo.tel = ''; wrapper.vm.data.tel = '';
saveButton.trigger('click'); saveButton.trigger('click');
expect(wrapper.vm.errorInfo['tel']).to.be.true; expect(wrapper.vm.errorInfo['tel']).to.be.true;
wrapper.find('.van-field__control')[1].trigger('focus'); wrapper.find('.van-field__control')[1].trigger('focus');
expect(wrapper.vm.errorInfo['tel']).to.be.false; expect(wrapper.vm.errorInfo['tel']).to.be.false;
// tel invalid // tel invalid
wrapper.vm.contactInfo.tel = 'abc'; wrapper.vm.data.tel = 'abc';
saveButton.trigger('click'); saveButton.trigger('click');
expect(wrapper.vm.errorInfo['tel']).to.be.true; expect(wrapper.vm.errorInfo['tel']).to.be.true;
wrapper.find('.van-field__control')[1].trigger('focus'); wrapper.find('.van-field__control')[1].trigger('focus');
expect(wrapper.vm.errorInfo['tel']).to.be.false; expect(wrapper.vm.errorInfo['tel']).to.be.false;
// saving // saving
wrapper.vm.contactInfo.tel = '13000000000'; wrapper.vm.data.tel = '13000000000';
saveButton.trigger('click'); saveButton.trigger('click');
wrapper.vm.isSaving = true; wrapper.vm.isSaving = true;
saveButton.trigger('click'); saveButton.trigger('click');
@ -260,7 +260,7 @@ describe('ContactEdit', () => {
wrapper.setProps({ contactInfo }); wrapper.setProps({ contactInfo });
wrapper.vm.$nextTick(() => { wrapper.vm.$nextTick(() => {
expect(wrapper.vm.currentInfo.name).to.equal('123'); expect(wrapper.vm.data.name).to.equal('123');
done(); done();
}); });
}); });