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

View File

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

View File

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

View File

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

View File

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