[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
81 changed files with 174 additions and 207 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ import { create } from '../utils';
import Popup from '../mixins/popup';
export default create({
name: 'van-actionsheet',
name: 'actionsheet',
mixins: [Popup],
+2 -6
View File
@@ -41,17 +41,13 @@
<script>
import { create } from '../utils';
import Field from '../field';
import Cell from '../cell';
import CellGroup from '../cell-group';
import { isAndroid } from '../utils';
export default create({
name: 'van-address-edit-detail',
name: 'address-edit-detail',
components: {
Field,
Cell,
CellGroup
Field
},
props: {
+21 -29
View File
@@ -5,7 +5,7 @@
maxlength="15"
:placeholder="$t('name')"
:label="$t('label.name', computedAddressText)"
v-model="currentInfo.name"
v-model="data.name"
:error="errorInfo.name"
@focus="onFocus('name')"
/>
@@ -13,7 +13,7 @@
type="tel"
:label="$t('tel')"
:placeholder="$t('telPlaceholder')"
v-model="currentInfo.tel"
v-model="data.tel"
:error="errorInfo.tel"
@focus="onFocus('tel')"
/>
@@ -23,17 +23,17 @@
:title="$t('area')"
@click="showArea = true"
>
<span>{{ currentInfo.province || $t('province') }}</span>
<span>{{ currentInfo.city || $t('city') }}</span>
<span>{{ currentInfo.county || $t('county') }}</span>
<span>{{ data.province || $t('province') }}</span>
<span>{{ data.city || $t('city') }}</span>
<span>{{ data.county || $t('county') }}</span>
</cell>
<address-edit-detail
:value="currentInfo.address_detail"
:value="data.address_detail"
:is-error="errorInfo.address_detail"
:show-search-result="showSearchResult"
:search-result="searchResult"
@focus="onFocus('address_detail')"
@blur="onDetailBlur"
@blur="detailFocused = false"
@input="onChangeDetail"
@select-search="$emit('select-search', $event)"
/>
@@ -43,7 +43,7 @@
type="tel"
:label="$t('label.postal')"
:placeholder="$t('placeholder.postal')"
v-model="currentInfo.postal_code"
v-model="data.postal_code"
maxlength="6"
class="van-hairline--top"
:error="errorInfo.postal_code"
@@ -53,7 +53,7 @@
<switch-cell
v-if="showSetDefault"
v-show="!hideBottomFields"
v-model="currentInfo.is_default"
v-model="data.is_default"
:title="$t('defaultAddress', computedAddressText)"
/>
</cell-group>
@@ -69,7 +69,7 @@
<van-area
ref="area"
:loading="!areaListLoaded"
:value="currentInfo.area_code"
:value="data.area_code"
:area-list="areaList"
@confirm="onAreaConfirm"
@cancel="showArea = false"
@@ -82,8 +82,6 @@
/* eslint-disable camelcase */
import { create, isObj } from '../utils';
import Field from '../field';
import Cell from '../cell';
import CellGroup from '../cell-group';
import VanButton from '../button';
import Popup from '../popup';
import Toast from '../toast';
@@ -106,12 +104,10 @@ const defaultAddress = {
};
export default create({
name: 'van-address-edit',
name: 'address-edit',
components: {
Field,
Cell,
CellGroup,
SwitchCell,
VanButton,
Popup,
@@ -144,7 +140,7 @@ export default create({
data() {
return {
showArea: false,
currentInfo: {
data: {
...defaultAddress,
...this.addressInfo
},
@@ -162,7 +158,7 @@ export default create({
watch: {
addressInfo: {
handler(val) {
this.currentInfo = {
this.data = {
...defaultAddress,
...val
};
@@ -176,8 +172,8 @@ export default create({
},
areaList() {
if (this.currentInfo.area_code) {
this.setAreaCode(this.currentInfo.area_code);
if (this.data.area_code) {
this.setAreaCode(this.data.area_code);
}
}
},
@@ -204,12 +200,8 @@ export default create({
this.$emit('focus', key);
},
onDetailBlur() {
this.detailFocused = false;
},
onChangeDetail(val) {
this.currentInfo.address_detail = val;
this.data.address_detail = val;
this.$emit('change-detail', val);
},
@@ -223,7 +215,7 @@ export default create({
},
assignAreaValues(values) {
Object.assign(this.currentInfo, {
Object.assign(this.data, {
province: values[0].name,
city: values[1].name,
county: values[2].name,
@@ -253,12 +245,12 @@ export default create({
});
if (isValid && !this.isSaving) {
this.$emit('save', this.currentInfo);
this.$emit('save', this.data);
}
},
getErrorMessageByKey(key) {
const value = this.currentInfo[key];
const value = this.data[key];
const { $t } = this;
switch (key) {
@@ -283,7 +275,7 @@ export default create({
Dialog.confirm({
message: this.$t('confirmDelete', this.computedAddressText)
}).then(() => {
this.$emit('delete', this.currentInfo);
this.$emit('delete', this.data);
});
},
@@ -295,7 +287,7 @@ export default create({
// set area code to area component
setAreaCode(code) {
this.currentInfo.area_code = code;
this.data.area_code = code;
this.$nextTick(() => {
this.$nextTick(() => {
const { area } = this.$refs;
+1 -5
View File
@@ -23,18 +23,14 @@
<script>
import { create } from '../utils';
import Cell from '../cell';
import CellGroup from '../cell-group';
import Radio from '../radio';
import RadioGroup from '../radio-group';
export default create({
name: 'van-address-list',
name: 'address-list',
components: {
Cell,
Radio,
CellGroup,
RadioGroup
},
+1 -1
View File
@@ -20,7 +20,7 @@ import { create, isObj } from '../utils';
import Picker from '../picker';
export default create({
name: 'van-area',
name: 'area',
components: {
Picker
+1 -1
View File
@@ -8,7 +8,7 @@
import { create } from '../utils';
export default create({
name: 'van-badge-group',
name: 'badge-group',
props: {
activeKey: {
+1 -1
View File
@@ -9,7 +9,7 @@
import { create } from '../utils';
export default create({
name: 'van-badge',
name: 'badge',
props: {
url: String,
+1 -1
View File
@@ -27,7 +27,7 @@
import { create } from '../utils';
export default create({
name: 'van-button',
name: 'button',
props: {
text: String,
+1 -1
View File
@@ -30,7 +30,7 @@
import { create } from '../utils';
export default create({
name: 'van-card',
name: 'card',
props: {
thumb: String,
+6 -4
View File
@@ -5,10 +5,12 @@
</template>
<script>
import { create } from '../utils';
import install from '../utils/install';
export default create({
name: 'van-cell-group',
export default {
install,
name: 'cell-group',
props: {
border: {
@@ -16,5 +18,5 @@ export default create({
default: true
}
}
});
};
</script>
+1 -1
View File
@@ -27,7 +27,7 @@ import Clickoutside from '../utils/clickoutside';
const THRESHOLD = 0.15;
export default create({
name: 'van-cell-swipe',
name: 'cell-swipe',
props: {
onClose: Function,
+11 -4
View File
@@ -37,11 +37,18 @@
</template>
<script>
import { create } from '../utils';
import Icon from '../icon';
import install from '../utils/install';
import RouterLink from '../mixins/router-link';
export default create({
name: 'van-cell',
export default {
install,
name: 'cell',
components: {
Icon
},
mixins: [RouterLink],
@@ -65,5 +72,5 @@ export default create({
this.routerLink();
}
}
});
};
</script>
+1 -1
View File
@@ -8,7 +8,7 @@
import { create } from '../utils';
export default create({
name: 'van-checkbox-group',
name: 'checkbox-group',
props: {
value: {},
+1 -1
View File
@@ -21,7 +21,7 @@ import { create, isDef } from '../utils';
import findParent from '../mixins/find-parent';
export default create({
name: 'van-checkbox',
name: 'checkbox',
mixins: [findParent],
+1 -1
View File
@@ -15,7 +15,7 @@ import { create } from '../utils';
import { raf, cancel } from '../utils/raf';
export default create({
name: 'van-circle',
name: 'circle',
props: {
text: String,
+1 -1
View File
@@ -12,7 +12,7 @@
import { create } from '../utils';
export default create({
name: 'van-col',
name: 'col',
props: {
span: [Number, String],
+1 -6
View File
@@ -16,19 +16,14 @@
</template>
<script>
import Cell from '../cell';
import findParent from '../mixins/find-parent';
import { create, isDef } from '../utils';
export default create({
name: 'van-collapse-item',
name: 'collapse-item',
mixins: [findParent],
components: {
Cell
},
props: {
name: [String, Number],
title: String
+1 -1
View File
@@ -8,7 +8,7 @@
import { create } from '../utils';
export default create({
name: 'van-collapse',
name: 'collapse',
model: {
prop: 'activeNames'
+1 -1
View File
@@ -21,7 +21,7 @@
import { create } from '../utils';
export default create({
name: 'van-contact-card',
name: 'contact-card',
props: {
tel: String,
+9 -11
View File
@@ -2,7 +2,7 @@
<div class="van-contact-edit">
<cell-group>
<field
v-model="currentInfo.name"
v-model="data.name"
maxlength="30"
:label="$t('contact')"
:placeholder="$t('name')"
@@ -10,7 +10,7 @@
@focus="onFocus('name')"
/>
<field
v-model="currentInfo.tel"
v-model="data.tel"
type="tel"
:label="$t('tel')"
:placeholder="$t('telPlaceholder')"
@@ -28,19 +28,17 @@
<script>
import Field from '../field';
import VanButton from '../button';
import CellGroup from '../cell-group';
import Dialog from '../dialog';
import Toast from '../toast';
import validateMobile from '../utils/validate/mobile';
import { create } from '../utils';
export default create({
name: 'van-contact-edit',
name: 'contact-edit',
components: {
Field,
VanButton,
CellGroup
VanButton
},
props: {
@@ -63,7 +61,7 @@ export default create({
data() {
return {
currentInfo: this.contactInfo,
data: this.contactInfo,
errorInfo: {
name: false,
tel: false
@@ -73,7 +71,7 @@ export default create({
watch: {
contactInfo(val) {
this.currentInfo = val;
this.data = val;
}
},
@@ -83,7 +81,7 @@ export default create({
},
getErrorMessageByKey(key) {
const value = this.currentInfo[key];
const value = this.data[key];
switch (key) {
case 'name':
return value ? value.length <= 15 ? '' : this.$t('nameOverlimit') : this.$t('nameEmpty');
@@ -108,7 +106,7 @@ export default create({
});
if (isValid && !this.isSaving) {
this.$emit('save', this.currentInfo);
this.$emit('save', this.data);
}
},
@@ -120,7 +118,7 @@ export default create({
Dialog.confirm({
message: this.$t('confirmDelete')
}).then(() => {
this.$emit('delete', this.currentInfo);
this.$emit('delete', this.data);
});
}
}
+1 -5
View File
@@ -22,19 +22,15 @@
</template>
<script>
import Cell from '../cell';
import Radio from '../radio';
import CellGroup from '../cell-group';
import RadioGroup from '../radio-group';
import { create } from '../utils';
export default create({
name: 'van-contact-list',
name: 'contact-list',
components: {
Cell,
Radio,
CellGroup,
RadioGroup
},
+1 -8
View File
@@ -6,16 +6,9 @@
<script>
import { create } from '../utils';
import Cell from '../cell';
import CellGroup from '../cell-group';
export default create({
name: 'van-coupon-cell',
components: {
Cell,
CellGroup
},
name: 'coupon-cell',
model: {
prop: 'chosenCoupon'
+1 -1
View File
@@ -22,7 +22,7 @@
import { create } from '../utils';
export default create({
name: 'van-coupon-item',
name: 'coupon-item',
props: {
data: Object,
+1 -5
View File
@@ -49,19 +49,15 @@
<script>
import { create } from '../utils';
import Cell from '../cell';
import CellGroup from '../cell-group';
import CouponItem from './Item';
import Field from '../field';
import VanButton from '../button';
export default create({
name: 'van-coupon-list',
name: 'coupon-list',
components: {
VanButton,
Cell,
CellGroup,
Field,
CouponItem
},
+1 -1
View File
@@ -17,7 +17,7 @@ import Picker from '../picker';
const isValidDate = date => Object.prototype.toString.call(date) === '[object Date]' && !isNaN(date.getTime());
export default create({
name: 'van-datetime-picker',
name: 'datetime-picker',
components: {
Picker
+1 -1
View File
@@ -36,7 +36,7 @@ import VanButton from '../button';
import Popup from '../mixins/popup';
export default create({
name: 'van-dialog',
name: 'dialog',
components: {
VanButton
+1 -6
View File
@@ -50,17 +50,12 @@
<script>
import { create } from '../utils';
import Cell from '../cell';
export default create({
name: 'van-field',
name: 'field',
inheritAttrs: false,
components: {
Cell
},
props: {
type: {
type: String,
+1 -1
View File
@@ -17,7 +17,7 @@ import VanButton from '../button';
import RouterLink from '../mixins/router-link';
export default create({
name: 'van-goods-action-big-btn',
name: 'goods-action-big-btn',
mixins: [RouterLink],
+1 -1
View File
@@ -10,7 +10,7 @@ import { create } from '../utils';
import RouterLink from '../mixins/router-link';
export default create({
name: 'van-goods-action-mini-btn',
name: 'goods-action-mini-btn',
mixins: [RouterLink],
+1 -1
View File
@@ -8,6 +8,6 @@
import { create } from '../utils';
export default create({
name: 'van-goods-action'
name: 'goods-action'
});
</script>
+1 -1
View File
@@ -11,7 +11,7 @@ import install from '../utils/install';
export default {
install,
name: 'van-icon',
name: 'icon',
props: {
name: String,
+1 -1
View File
@@ -22,7 +22,7 @@ import Swipe from '../swipe';
import SwipeItem from '../swipe-item';
export default create({
name: 'van-image-preview',
name: 'image-preview',
mixins: [Popup],
+1 -1
View File
@@ -16,7 +16,7 @@ import utils from '../utils/scroll';
import { on, off } from '../utils/event';
export default create({
name: 'van-list',
name: 'list',
model: {
prop: 'loading'
+1 -1
View File
@@ -15,7 +15,7 @@ import install from '../utils/install';
export default {
install,
name: 'van-loading',
name: 'loading',
props: {
size: String,
+1 -1
View File
@@ -13,7 +13,7 @@
<script>
export default {
name: 'van-modal',
name: 'modal',
props: {
visible: Boolean,
+1 -1
View File
@@ -25,7 +25,7 @@
import { create } from '../utils';
export default create({
name: 'van-nav-bar',
name: 'nav-bar',
props: {
title: String,
+1 -1
View File
@@ -29,7 +29,7 @@
import { create } from '../utils';
export default create({
name: 'van-notice-bar',
name: 'notice-bar',
props: {
text: String,
+1 -1
View File
@@ -39,7 +39,7 @@ import { create } from '../utils';
import Key from './Key';
export default create({
name: 'van-number-keyboard',
name: 'number-keyboard',
components: { Key },
+1 -1
View File
@@ -34,7 +34,7 @@
import { create } from '../utils';
export default create({
name: 'van-pagination',
name: 'pagination',
props: {
value: Number,
+1 -1
View File
@@ -20,7 +20,7 @@
import { create } from '../utils';
export default create({
name: 'van-panel',
name: 'panel',
props: {
desc: String,
title: String,
+1 -1
View File
@@ -17,7 +17,7 @@
import { create } from '../utils';
export default create({
name: 'van-password-input',
name: 'password-input',
props: {
info: String,
+1 -1
View File
@@ -31,7 +31,7 @@ const DEFAULT_DURATION = 200;
const range = (num, arr) => Math.min(Math.max(num, arr[0]), arr[1]);
export default create({
name: 'van-picker-column',
name: 'picker-column',
props: {
valueKey: String,
+1 -1
View File
@@ -33,7 +33,7 @@ import PickerColumn from './PickerColumn';
import deepClone from '../utils/deep-clone';
export default create({
name: 'van-picker',
name: 'picker',
components: {
PickerColumn
+1 -1
View File
@@ -11,7 +11,7 @@ import { create } from '../utils';
import Popup from '../mixins/popup';
export default create({
name: 'van-popup',
name: 'popup',
mixins: [Popup],
+1 -1
View File
@@ -9,7 +9,7 @@
import { create } from '../utils';
export default create({
name: 'van-progress',
name: 'progress',
props: {
inactive: Boolean,
+1 -1
View File
@@ -33,7 +33,7 @@ import { create } from '../utils';
import scrollUtils from '../utils/scroll';
export default create({
name: 'van-pull-refresh',
name: 'pull-refresh',
props: {
pullingText: String,
+1 -1
View File
@@ -8,7 +8,7 @@
import { create } from '../utils';
export default create({
name: 'van-radio-group',
name: 'radio-group',
props: {
value: {},
+1 -1
View File
@@ -25,7 +25,7 @@ import { create } from '../utils';
import findParent from '../mixins/find-parent';
export default create({
name: 'van-radio',
name: 'radio',
mixins: [findParent],
+1 -1
View File
@@ -8,7 +8,7 @@
import { create } from '../utils';
export default create({
name: 'van-row',
name: 'row',
props: {
gutter: {
+1 -1
View File
@@ -28,7 +28,7 @@ import { create } from '../utils';
import Clickoutside from '../utils/clickoutside';
export default create({
name: 'van-search',
name: 'search',
inheritAttrs: false,
+1 -1
View File
@@ -120,7 +120,7 @@ import { create } from '../utils';
const { QUOTA_LIMIT } = LIMIT_TYPE;
export default create({
name: 'van-sku',
name: 'sku',
components: {
Popup,
+1 -1
View File
@@ -20,7 +20,7 @@ import VanButton from '../../button';
import { create } from '../../utils';
export default create({
name: 'van-sku-actions',
name: 'sku-actions',
components: {
VanButton
+1 -1
View File
@@ -15,7 +15,7 @@
import { create } from '../../utils';
export default create({
name: 'van-sku-header',
name: 'sku-header',
props: {
skuEventBus: Object,
+1 -1
View File
@@ -46,7 +46,7 @@ import Loading from '../../loading';
import { create } from '../../utils';
export default create({
name: 'van-sku-img-uploader',
name: 'sku-img-uploader',
components: {
'van-uploader': Uploader,
+2 -6
View File
@@ -30,20 +30,16 @@
<script>
import { create } from '../../utils';
import Field from '../../field';
import CellGroup from '../../cell-group';
import Cell from '../../cell';
import validateEmail from '../../utils/validate/email';
import validateNumber from '../../utils/validate/number';
import SkuImgUploader from './SkuImgUploader';
export default create({
name: 'van-sku-messages',
name: 'sku-messages',
components: {
SkuImgUploader,
Field,
Cell,
CellGroup
Field
},
props: {
+1 -1
View File
@@ -9,7 +9,7 @@
<script>
export default {
name: 'van-sku-row',
name: 'sku-row',
props: {
skuRow: Object
+1 -1
View File
@@ -15,7 +15,7 @@
import { create } from '../../utils';
export default create({
name: 'van-sku-row-item',
name: 'sku-row-item',
props: {
skuEventBus: Object,
+1 -1
View File
@@ -25,7 +25,7 @@ import { LIMIT_TYPE } from '../constants';
const { QUOTA_LIMIT, STOCK_LIMIT } = LIMIT_TYPE;
export default create({
name: 'van-sku-stepper',
name: 'sku-stepper',
components: {
Stepper
+1 -1
View File
@@ -15,7 +15,7 @@
import { create } from '../utils';
export default create({
name: 'van-step',
name: 'step',
beforeCreate() {
this.$parent.steps.push(this);
+1 -1
View File
@@ -24,7 +24,7 @@
import { create } from '../utils';
export default create({
name: 'van-stepper',
name: 'stepper',
props: {
value: {},
+1 -1
View File
@@ -22,7 +22,7 @@
import { create } from '../utils';
export default create({
name: 'van-steps',
name: 'steps',
props: {
icon: String,
+1 -1
View File
@@ -24,7 +24,7 @@ import VanButton from '../button';
import { create } from '../utils';
export default create({
name: 'van-submit-bar',
name: 'submit-bar',
components: {
VanButton
+1 -1
View File
@@ -8,7 +8,7 @@
import { create } from '../utils';
export default create({
name: 'van-swipe-item',
name: 'swipe-item',
data() {
return {
+1 -1
View File
@@ -25,7 +25,7 @@
import { create } from '../utils';
export default create({
name: 'van-swipe',
name: 'swipe',
props: {
autoplay: Number,
+1 -3
View File
@@ -5,15 +5,13 @@
</template>
<script>
import Cell from '../cell';
import VanSwitch from '../switch';
import { create } from '../utils';
export default create({
name: 'van-switch-cell',
name: 'switch-cell',
components: {
Cell,
VanSwitch
},
+1 -1
View File
@@ -11,7 +11,7 @@
import { create } from '../utils';
export default create({
name: 'van-switch',
name: 'switch',
props: {
value: Boolean,
+1 -1
View File
@@ -9,7 +9,7 @@ import { create } from '../utils';
import findParent from '../mixins/find-parent';
export default create({
name: 'van-tab',
name: 'tab',
mixins: [findParent],
+1 -1
View File
@@ -17,7 +17,7 @@ import { create } from '../utils';
import RouterLink from '../mixins/router-link';
export default create({
name: 'van-tabbar-item',
name: 'tabbar-item',
mixins: [RouterLink],
+1 -1
View File
@@ -8,7 +8,7 @@
import { create } from '../utils';
export default create({
name: 'van-tabbar',
name: 'tabbar',
data() {
return {
+1 -1
View File
@@ -40,7 +40,7 @@ import VanNode from '../utils/node';
import scrollUtils from '../utils/scroll';
export default create({
name: 'van-tabs',
name: 'tabs',
components: {
VanNode
+1 -1
View File
@@ -15,7 +15,7 @@
import { create } from '../utils';
export default create({
name: 'van-tag',
name: 'tag',
props: {
type: String,
mark: Boolean,
+1 -1
View File
@@ -24,7 +24,7 @@ import { create } from '../utils';
const STYLE_LIST = ['success', 'fail', 'loading'];
export default create({
name: 'van-toast',
name: 'toast',
props: {
mask: Boolean,
+1 -1
View File
@@ -31,7 +31,7 @@
import { create } from '../utils';
export default create({
name: 'van-tree-select',
name: 'tree-select',
props: {
items: {
+1 -1
View File
@@ -16,7 +16,7 @@
import { create } from '../utils';
export default create({
name: 'van-uploader',
name: 'uploader',
inheritAttrs: false,
+10 -4
View File
@@ -2,18 +2,24 @@
* Create a component with common options
*/
import '../locale';
import Icon from '../icon';
import i18n from '../mixins/i18n';
import install from './install';
import Icon from '../icon';
import Loading from '../loading';
import Cell from '../cell';
import CellGroup from '../cell-group';
export default function(sfc) {
sfc.name = 'van-' + sfc.name;
sfc.install = sfc.install || install;
sfc.mixins = sfc.mixins || [];
sfc.mixins.push(i18n);
sfc.components = sfc.components || {};
sfc.components.icon = Icon;
sfc.components.loading = Loading;
sfc.components = Object.assign(sfc.components || {}, {
Icon,
Loading,
Cell,
CellGroup
});
return sfc;
};
+2 -2
View File
@@ -1,4 +1,4 @@
export default function mobile(value) {
return /^((\+86)|(86))?(1)\d{10}$/.test(value) ||
/^\+?(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));
value = value.replace(/[^-|\d]/g, '');
return /^((\+86)|(86))?(1)\d{10}$/.test(value) || /^0[0-9\-]{10,13}$/.test(value);
}
+4
View File
@@ -7,3 +7,7 @@
@import "./common/ellipsis.css";
@import "./common/hairline.css";
@import "./common/animation.css";
@import './icon.css';
@import './loading.css';
@import './button.css';
@import './cell.css';
-4
View File
@@ -4,10 +4,6 @@
/* base */
@import './base.css';
@import './icon.css';
@import './loading.css';
@import './button.css';
@import './cell.css';
/* common components */
@import './col.css';