chore: improve code style

This commit is contained in:
陈嘉涵 2019-12-16 11:29:59 +08:00
parent a7535cc948
commit 0f4ddbf13f
5 changed files with 42 additions and 21 deletions

View File

@ -140,10 +140,12 @@ export default createComponent({
onAreaConfirm(values) {
values = values.filter(value => !!value);
if (values.some(value => !value.code)) {
Toast(t('areaEmpty'));
return;
}
this.showAreaPopup = false;
this.assignAreaValues();
this.$emit('change-area', values);
@ -151,6 +153,7 @@ export default createComponent({
assignAreaValues() {
const { area } = this.$refs;
if (area) {
const detail = area.getArea();
detail.areaCode = detail.code;
@ -247,7 +250,8 @@ export default createComponent({
const onFocus = name => () => this.onFocus(name);
// hide bottom field when use search && detail get focused
const hideBottomFields = searchResult && searchResult.length && this.detailFocused;
const hideBottomFields =
searchResult && searchResult.length && this.detailFocused;
return (
<div class={bem()}>

View File

@ -94,8 +94,8 @@ function AddressItem(
return (
<Cell
class={bem({ disabled })}
valueClass={bem('value')}
border={false}
valueClass={bem('value')}
clickable={switchable && !disabled}
scopedSlots={{
default: genContent,

View File

@ -64,11 +64,11 @@ function AddressList(
return (
<div class={bem()} {...inherit(ctx)}>
{slots.top && slots.top()}
{slots.top?.()}
<RadioGroup value={props.value}>{List}</RadioGroup>
{props.disabledText && <div class={bem('disabled-text')}>{props.disabledText}</div>}
{DisabledList}
{slots.default && slots.default()}
{slots.default?.()}
<div class={bem('bottom')}>
<Button
round
@ -87,15 +87,15 @@ function AddressList(
AddressList.props = {
list: Array,
value: [Number, String],
disabledList: Array,
disabledText: String,
addButtonText: String,
value: [Number, String],
defaultTagText: String,
switchable: {
type: Boolean,
default: true
},
defaultTagText: String
}
};
export default createComponent<AddressListProps>(AddressList);

View File

@ -1,10 +1,10 @@
import { createNamespace } from '../utils';
import Picker from '../picker';
import { pickerProps } from '../picker/shared';
import Picker from '../picker';
const [createComponent, bem] = createNamespace('area');
const COLUMNSPLACEHOLDERCODE = '000000';
const PLACEHOLDER_CODE = '000000';
function isOverseaCode(code) {
return code[0] === '9';
@ -56,11 +56,11 @@ export default createComponent({
return this.columns.slice(0, +this.columnsNum);
},
typeToColumnsPlaceholder() {
placeholderMap() {
return {
province: this.columnsPlaceholder[0] || '',
city: this.columnsPlaceholder[1] || '',
county: this.columnsPlaceholder[2] || '',
county: this.columnsPlaceholder[2] || ''
};
}
},
@ -110,12 +110,18 @@ export default createComponent({
result = result.filter(item => item.code.indexOf(code) === 0);
}
if (this.typeToColumnsPlaceholder[type] && result.length) {
if (this.placeholderMap[type] && result.length) {
// set columns placeholder
const codeFill = type === 'province' ? '' : type === 'city' ? COLUMNSPLACEHOLDERCODE.slice(2, 4) : COLUMNSPLACEHOLDERCODE.slice(4, 6);
const codeFill =
type === 'province'
? ''
: type === 'city'
? PLACEHOLDER_CODE.slice(2, 4)
: PLACEHOLDER_CODE.slice(4, 6);
result.unshift({
code: `${code}${codeFill}`,
name: this.typeToColumnsPlaceholder[type]
name: this.placeholderMap[type]
});
}
@ -150,10 +156,12 @@ export default createComponent({
if (!value) return value;
value = JSON.parse(JSON.stringify(value));
if (!value.code || value.name === this.columnsPlaceholder[index]) {
value.code = '';
value.name = '';
}
return value;
});
},
@ -161,8 +169,10 @@ export default createComponent({
onChange(picker, values, index) {
this.code = values[index].code;
this.setValues();
let getValues = picker.getValues();
getValues = this.parseOutputValues(getValues);
this.$emit('change', picker, getValues, index);
},
@ -177,7 +187,7 @@ export default createComponent({
if (!code) {
if (this.columnsPlaceholder.length) {
code = COLUMNSPLACEHOLDERCODE;
code = PLACEHOLDER_CODE;
} else if (Object.keys(this.county)[0]) {
code = Object.keys(this.county)[0];
} else {
@ -196,7 +206,11 @@ export default createComponent({
picker.setColumnValues(0, province);
picker.setColumnValues(1, city);
if (city.length && code.slice(2, 4) === '00' && !this.isOverseaCode(code)) {
if (
city.length &&
code.slice(2, 4) === '00' &&
!this.isOverseaCode(code)
) {
[{ code }] = city;
}
@ -230,8 +244,11 @@ export default createComponent({
}
const names = values.map(item => item.name);
const filterCodeValues = values.filter(value => !!value.code);
area.code = filterCodeValues.length ? filterCodeValues[filterCodeValues.length - 1].code : '';
const validValues = values.filter(value => !!value.code);
area.code = validValues.length
? validValues[validValues.length - 1].code
: '';
if (this.isOverseaCode(area.code)) {
area.country = names[1] || '';

View File

@ -175,15 +175,15 @@ function Card(
<div>
{Title()}
{Desc()}
{slots.tags && slots.tags()}
{slots.tags?.()}
</div>
{showBottom && (
<div class="van-card__bottom">
{slots['price-top'] && slots['price-top']()}
{slots['price-top']?.()}
{Price()}
{OriginPrice()}
{Num()}
{slots.bottom && slots.bottom()}
{slots.bottom?.()}
</div>
)}
</div>