breaking change(AddressEdit): remove postal

This commit is contained in:
chenjiahan 2022-03-26 20:12:24 +08:00
parent 8e822a591d
commit e08e9845a2
34 changed files with 6 additions and 163 deletions

View File

@ -101,6 +101,8 @@ emit('clickInput');
#### AddressEdit
- 移除 `show-postal` 属性
- 移除 `postal-validator` 属性
- `change-area` 事件的参数调整为 `PickerOption[]` 类型
- 移除未在文档中标注的 `getArea` 实例方法

View File

@ -51,12 +51,9 @@ const DEFAULT_DATA: AddressEditInfo = {
province: '',
areaCode: '',
isDefault: false,
postalCode: '',
addressDetail: '',
};
const isPostal = (value: string) => /^\d{6}$/.test(value);
const addressEditProps = {
areaList: Object as PropType<AreaList>,
isSaving: Boolean,
@ -67,7 +64,6 @@ const addressEditProps = {
showArea: truthProp,
showDetail: truthProp,
showDelete: Boolean,
showPostal: Boolean,
disableArea: Boolean,
searchResult: Array as PropType<AddressEditSearchItem[]>,
telMaxlength: numericProp,
@ -87,10 +83,6 @@ const addressEditProps = {
type: Function as PropType<(val: string) => boolean>,
default: isMobile,
},
postalValidator: {
type: Function as PropType<(val: string) => boolean>,
default: isPostal,
},
};
export type AddressEditProps = ExtractPropTypes<typeof addressEditProps>;
@ -145,7 +137,7 @@ export default defineComponent({
};
const rules = computed<Record<string, FieldRule[]>>(() => {
const { validator, telValidator, postalValidator } = props;
const { validator, telValidator } = props;
const makeRule = (name: string, emptyMessage: string): FieldRule => ({
validator: (value) => {
@ -170,10 +162,6 @@ export default defineComponent({
],
areaCode: [makeRule('areaCode', t('areaEmpty'))],
addressDetail: [makeRule('addressDetail', t('addressEmpty'))],
postalCode: [
makeRule('addressDetail', t('postalEmpty')),
{ validator: postalValidator, message: t('postalEmpty') },
],
};
});
@ -323,18 +311,6 @@ export default defineComponent({
onInput={onChangeDetail}
onSelectSearch={(event: Event) => emit('selectSearch', event)}
/>
{props.showPostal && (
<Field
v-show={!hideBottomFields.value}
v-model={data.postalCode}
type="tel"
rules={rules.value.postalCode}
label={t('postal')}
maxlength="6"
placeholder={t('postal')}
onFocus={() => onFocus('postalCode')}
/>
)}
{slots.default?.()}
</div>
{renderSetDefaultCell()}

View File

@ -23,7 +23,6 @@ app.use(AddressEdit);
```html
<van-address-edit
:area-list="areaList"
show-postal
show-delete
show-set-default
show-search-result
@ -80,7 +79,6 @@ export default {
| area-placeholder | placeholder of area input field | _string_ | `Area` |
| address-info | Address Info | _AddressEditInfo_ | `{}` |
| search-result | Address search result | _AddressEditSearchItem[]_ | `[]` |
| show-postal | Whether to show postal field | _boolean_ | `false` |
| show-delete | Whether to show delete button | _boolean_ | `false` |
| show-set-default | Whether to show default address switch | _boolean_ | `false` |
| show-search-result | Whether to show address search result | _boolean_ | `false` |
@ -95,7 +93,6 @@ export default {
| is-deleting | Whether to show delete button loading status | _boolean_ | `false` |
| tel-validator | The method to validate tel | _(tel: string) => boolean_ | - |
| tel-maxlength | Tel maxlength | _number \| string_ | - |
| postal-validator | The method to validate postal | _(tel: string) => boolean_ | - |
| validator | Custom validator | _(key, val) => string_ | - |
### Events
@ -114,8 +111,8 @@ export default {
### Slots
| Name | Description |
| ------- | --------------------------- |
| default | Custom content below postal |
| ------- | ----------------------------------- |
| default | Custom content below address detail |
### Methods
@ -160,7 +157,6 @@ addressEditRef.value?.setAddressDetail('');
| county | County | _string_ |
| addressDetail | Detailed Address | _string_ |
| areaCode | Area code | _string_ |
| postalCode | Postal code | _string_ |
| isDefault | Is default address | _boolean_ |
### AddressEditSearchItem Data Structure

View File

@ -23,7 +23,6 @@ app.use(AddressEdit);
```html
<van-address-edit
:area-list="areaList"
show-postal
show-delete
show-set-default
show-search-result
@ -80,7 +79,6 @@ export default {
| area-placeholder | 地区输入框占位提示文字 | _string_ | `选择省 / 市 / 区` |
| address-info | 地址信息初始值 | _AddressEditInfo_ | `{}` |
| search-result | 详细地址搜索结果 | _AddressEditSearchItem[]_ | `[]` |
| show-postal | 是否显示邮政编码 | _boolean_ | `false` |
| show-delete | 是否显示删除按钮 | _boolean_ | `false` |
| show-set-default | 是否显示默认地址栏 | _boolean_ | `false` |
| show-search-result | 是否显示搜索结果 | _boolean_ | `false` |
@ -95,7 +93,6 @@ export default {
| is-deleting | 是否显示删除按钮加载动画 | _boolean_ | `false` |
| tel-validator | 手机号格式校验函数 | _string => boolean_ | - |
| tel-maxlength | 手机号最大长度 | _number \| string_ | - |
| postal-validator | 邮政编码格式校验函数 | _string => boolean_ | - |
| validator | 自定义校验函数 | _(key, val) => string_ | - |
### Events
@ -162,7 +159,6 @@ addressEditRef.value?.setAddressDetail('');
| county | 区县 | _string_ |
| addressDetail | 详细地址 | _string_ |
| areaCode | 地区编码,通过 [省市区选择](#/zh-CN/area) 获取(必填) | _string_ |
| postalCode | 邮政编码 | _string_ |
| isDefault | 是否为默认地址 | _boolean_ |
### AddressEditSearchItem 数据格式

View File

@ -52,7 +52,6 @@ const onChangeDetail = (val: string) => {
<demo-block :title="t('basicUsage')">
<van-address-edit
:area-list="areaList"
show-postal
show-delete
show-set-default
show-search-result

View File

@ -88,25 +88,6 @@ exports[`should render demo and match snapshot 1`] = `
</div>
</div>
</div>
<div class="van-cell van-field">
<div class="van-cell__title van-field__label">
<label id="van-field-label"
for="van-field-input"
>
Postal
</label>
</div>
<div class="van-cell__value van-field__value">
<div class="van-field__body">
<input type="tel"
id="van-field-input"
class="van-field__control"
placeholder="Postal"
aria-labelledby="van-field-label"
>
</div>
</div>
</div>
</div>
<div class="van-cell van-cell--center van-address-edit__default">
<div class="van-cell__title">

View File

@ -193,25 +193,6 @@ exports[`should render AddressEdit with props correctly 1`] = `
</div>
</div>
</div>
<div class="van-cell van-field">
<div class="van-cell__title van-field__label">
<label id="van-field-label"
for="van-field-input"
>
Postal
</label>
</div>
<div class="van-cell__value van-field__value">
<div class="van-field__body">
<input type="tel"
id="van-field-input"
class="van-field__control"
placeholder="Postal"
aria-labelledby="van-field-label"
>
</div>
</div>
</div>
</div>
<div class="van-cell van-cell--center van-address-edit__default">
<div class="van-cell__title">
@ -322,31 +303,6 @@ exports[`should valid name and render error message correctly 1`] = `
</div>
`;
exports[`should valid postal code and render error message correctly 1`] = `
<div class="van-cell van-field">
<div class="van-cell__title van-field__label">
<label id="van-field-label"
for="van-field-input"
>
Postal
</label>
</div>
<div class="van-cell__value van-field__value">
<div class="van-field__body">
<input type="tel"
id="van-field-input"
class="van-field__control"
placeholder="Postal"
aria-labelledby="van-field-label"
>
</div>
<div class="van-field__error-message">
Wrong postal code
</div>
</div>
</div>
`;
exports[`should valid tel and render error message correctly 1`] = `
<div class="van-cell van-field">
<div class="van-cell__title van-field__label">

View File

@ -11,7 +11,6 @@ const defaultAddressInfo = {
county: '朝阳区',
addressDetail: 'address detail',
areaCode: '110101',
postalCode: '10000',
isDefault: true,
};
@ -23,7 +22,6 @@ const createComponent = (addressInfo = {}) => {
...defaultAddressInfo,
...addressInfo,
},
showPostal: true,
showSetDefault: true,
},
});
@ -45,7 +43,6 @@ test('should render AddressEdit with props correctly', () => {
props: {
areaList,
addressInfo: defaultAddressInfo,
showPostal: true,
showSetDefault: true,
showSearchResult: true,
},
@ -103,15 +100,6 @@ test('should valid address detail and render error message correctly', async ()
expect(fields[3].html()).toMatchSnapshot();
});
test('should valid postal code and render error message correctly', async () => {
const { fields, wrapper } = createComponent({
postalCode: '123',
});
await submitForm(wrapper);
expect(fields[4].html()).toMatchSnapshot();
});
test('should emit changeDetail event after changing address detail', () => {
const wrapper = mount(AddressEdit);
const field = wrapper.findAll('.van-field__control')[3];

View File

@ -15,7 +15,6 @@ export type AddressEditInfo = {
province: string;
areaCode: string;
isDefault?: boolean;
postalCode?: string;
addressDetail: string;
};

View File

@ -59,10 +59,8 @@ export default {
},
vanAddressEdit: {
area: 'এরিয়া',
postal: 'ডাক',
areaEmpty: 'অনুগ্রহ করে একটি রিসিভিং এলাকা নির্বাচন করুন',
addressEmpty: 'ঠিকানা খালি হতে পারে না',
postalEmpty: 'ভুল পোস্টাল কোড',
addressDetail: 'ঠিকানা',
defaultAddress: 'ডিফল্ট ঠিকানা হিসাবে সেট করুন',
},

View File

@ -50,10 +50,8 @@ export default {
},
vanAddressEdit: {
area: 'Standort',
postal: 'PLZ',
areaEmpty: 'Bitte geben Sie Ihren Standort an',
addressEmpty: 'Adresse darf nicht leer sein',
postalEmpty: 'Falsche Postleitzahl',
addressDetail: 'Adresse',
defaultAddress: 'Als Standardadresse festgelegen',
},

View File

@ -50,10 +50,8 @@ export default {
},
vanAddressEdit: {
area: 'Standort',
postal: 'PLZ',
areaEmpty: 'Bitte deinen Ort angeben',
addressEmpty: 'Adresse darf nicht leer sein',
postalEmpty: 'Falsche Postleitzahl',
addressDetail: 'Adresse',
defaultAddress: 'Als Standardadresse festgelegen',
},

View File

@ -50,10 +50,8 @@ export default {
},
vanAddressEdit: {
area: 'Area',
postal: 'Postal',
areaEmpty: 'Please select a receiving area',
addressEmpty: 'Address can not be empty',
postalEmpty: 'Wrong postal code',
addressDetail: 'Address',
defaultAddress: 'Set as the default address',
},

View File

@ -50,10 +50,8 @@ export default {
},
vanAddressEdit: {
area: 'Área',
postal: 'Código Postal',
areaEmpty: 'Por favor selecciona una área de recogida',
addressEmpty: 'La dirección no puede estar vacia',
postalEmpty: 'Código postal inválido',
addressDetail: 'Dirección',
defaultAddress: 'Establecer como dirección por defecto',
},

View File

@ -50,10 +50,8 @@ export default {
},
vanAddressEdit: {
area: 'Zone',
postal: 'Postal',
areaEmpty: 'Veuillez sélectionner une zone de réception',
addressEmpty: "L'adresse ne peut pas être vide",
postalEmpty: 'Mauvais code postal',
addressDetail: 'Adresse',
defaultAddress: 'Définir comme adresse par défaut',
},

View File

@ -58,10 +58,8 @@ export default {
},
vanAddressEdit: {
area: 'क्षेत्र',
postal: 'डाक का',
areaEmpty: 'कृपया एक क्षेत्र चुनें',
addressEmpty: 'पता खाली नहीं हो सकता',
postalEmpty: 'गलत पोस्टल कोड',
addressDetail: 'पता',
defaultAddress: 'डिफ़ॉल्ट पते के रूप में सेट करें',
},

View File

@ -51,10 +51,8 @@ export default {
},
vanAddressEdit: {
area: 'Daerah',
postal: 'pos',
areaEmpty: 'Silakan pilih area penerima',
addressEmpty: 'Alamat tidak boleh kosong',
postalEmpty: 'Kode pos salah',
addressDetail: 'Alamat',
defaultAddress: 'Tetapkan sebagai alamat default',
},

View File

@ -58,10 +58,8 @@ export default {
},
vanAddressEdit: {
area: 'Svæði',
postal: 'póstur',
areaEmpty: 'Vinsamlega veldu móttökusvæði',
addressEmpty: 'Heimilisfang má ekki vera tómt',
postalEmpty: 'Rangt póstnúmer',
addressDetail: 'Heimilisfang',
defaultAddress: 'Setja sem sjálfgefið heimilisfang',
},

View File

@ -58,10 +58,8 @@ export default {
},
vanAddressEdit: {
area: 'Area',
postal: 'Postale',
areaEmpty: "Seleziona un'area di ricezione",
addressEmpty: "L'indirizzo non può essere vuoto",
postalEmpty: 'Codice postale errato',
addressDetail: 'Indirizzo',
defaultAddress: 'Imposta come indirizzo predefinito',
},

View File

@ -50,10 +50,8 @@ export default {
},
vanAddressEdit: {
area: '地域',
postal: '郵便番号',
areaEmpty: '地域を選択してください',
addressEmpty: '詳しい住所を入力してください',
postalEmpty: '間違った郵便番号',
addressDetail: '詳しい住所',
defaultAddress: 'デフォルトの住所に設定',
},

View File

@ -58,10 +58,8 @@ export default {
},
vanAddressEdit: {
area: '지역',
postal: '우편 엽서',
areaEmpty: '접수지역을 선택해주세요',
addressEmpty: '주소는 비워둘 수 없습니다',
postalEmpty: '잘못된 우편번호',
addressDetail: '주소',
defaultAddress: '기본 주소로 설정',
},

View File

@ -51,10 +51,8 @@ export default {
},
vanAddressEdit: {
area: 'ພື້ນທີ່',
postal: 'ລະຫັດໄປສະນີ',
areaEmpty: 'ກະລຸນາເລືອກພື້ນທີ່',
addressEmpty: 'ກະລຸນາປ້ອນທີ່ຢູ່',
postalEmpty: 'ກະລຸນາປ້ອນລະຫັດໄປສະນີ',
addressDetail: 'ທີ່ຢູ່',
defaultAddress: 'ຕັ້ງເປັນທີ່ຢູ່ເລີ່ມຕົ້ນ',
},

View File

@ -50,10 +50,8 @@ export default {
},
vanAddressEdit: {
area: 'Område',
postal: 'Postkode',
areaEmpty: 'Vennligst fyll inn område',
addressEmpty: 'Addresse kan ikke være tomt',
postalEmpty: 'Feil postkode',
addressDetail: 'Adresse',
defaultAddress: 'Sett som standard adresse',
},

View File

@ -50,10 +50,8 @@ export default {
},
vanAddressEdit: {
area: 'Área',
postal: 'CEP',
areaEmpty: 'Por favor, selecione uma área de recebimento',
addressEmpty: 'Endereço não pode ser vazio',
postalEmpty: 'CEP inválido',
addressDetail: 'Endereço',
defaultAddress: 'Usar como endereço padrão',
},

View File

@ -50,10 +50,8 @@ export default {
},
vanAddressEdit: {
area: 'Zonă',
postal: 'Cod postal',
areaEmpty: 'Te rugăm sa selectezi o zona de primire',
addressEmpty: 'Adresa nu poate fi goală',
postalEmpty: 'Cod postal invalid',
addressDetail: 'Adresă',
defaultAddress: 'Setează ca adresă de pornire',
},

View File

@ -50,10 +50,8 @@ export default {
},
vanAddressEdit: {
area: 'Область',
postal: 'Индекс',
areaEmpty: 'Укажите зону доставки',
addressEmpty: 'Адрес не может быть пустым',
postalEmpty: 'Некорректный индекс',
addressDetail: 'Адрес',
defaultAddress: 'Сделать адресом по умолчанию',
},

View File

@ -50,10 +50,8 @@ export default {
},
vanAddressEdit: {
area: 'Område',
postal: 'Post',
areaEmpty: 'Välj ett mottagningsområde',
addressEmpty: 'Adressen får inte vara tom',
postalEmpty: 'Fel postnummer',
addressDetail: 'Adress',
defaultAddress: 'Ange som standardadress',
},

View File

@ -51,10 +51,8 @@ export default {
},
vanAddressEdit: {
area: 'พื้นที่',
postal: 'รหัสไปรษณีย์',
areaEmpty: 'โปรดเลือกภูมิภาค',
addressEmpty: 'กรุณากรอกที่อยู่โดยละเอียด',
postalEmpty: 'รูปแบบรหัสไปรษณีย์ไม่ถูกต้อง',
addressDetail: 'ที่อยู่',
defaultAddress: 'ตั้งเป็นที่อยู่จัดส่งเริ่มต้น',
},

View File

@ -50,10 +50,8 @@ export default {
},
vanAddressEdit: {
area: 'Alan',
postal: 'Posta',
areaEmpty: 'Lütfen alıcı alanını seçin',
addressEmpty: 'Adres boş olamaz!',
postalEmpty: 'Yanlış posta kodu',
addressDetail: 'Adres',
defaultAddress: 'Varsayılan adres olarak ayarla',
},

View File

@ -59,10 +59,8 @@ export default {
},
vanAddressEdit: {
area: 'Область',
postal: 'Поштовий',
areaEmpty: 'Будь ласка, виберіть зону прийому',
addressEmpty: 'Адреса не може бути порожньою',
postalEmpty: 'Неправильний поштовий індекс',
addressDetail: 'Адреса',
defaultAddress: 'Встановити як адресу за замовчуванням',
},

View File

@ -58,10 +58,8 @@ export default {
},
vanAddressEdit: {
area: 'Khu vực',
postal: 'Bưu điện',
areaEmpty: 'Vui lòng chọn khu vực nhận hàng',
addressEmpty: 'Địa chỉ không được để trống',
postalEmpty: 'Mã bưu chính sai',
addressDetail: 'Địa chỉ',
defaultAddress: 'Đặt làm địa chỉ mặc định',
},

View File

@ -50,10 +50,8 @@ export default {
},
vanAddressEdit: {
area: '地区',
postal: '邮政编码',
areaEmpty: '请选择地区',
addressEmpty: '请填写详细地址',
postalEmpty: '邮政编码不正确',
addressDetail: '详细地址',
defaultAddress: '设为默认收货地址',
},

View File

@ -50,10 +50,8 @@ export default {
},
vanAddressEdit: {
area: '地區',
postal: '郵政編碼',
areaEmpty: '請選擇地區',
addressEmpty: '請填寫詳細地址',
postalEmpty: '郵政編碼不正確',
addressDetail: '詳細地址',
defaultAddress: '設為默認收貨地址',
},

View File

@ -50,10 +50,8 @@ export default {
},
vanAddressEdit: {
area: '地區',
postal: '郵遞區號',
areaEmpty: '請選擇地區',
addressEmpty: '請填寫詳細地址',
postalEmpty: '郵遞區號不正確',
addressDetail: '詳細地址',
defaultAddress: '設為預設收貨地址',
},