breaking change(AddressEdit): adjust change-area event params

This commit is contained in:
chenjiahan 2022-02-16 12:14:01 +08:00
parent 35a50012c7
commit b3cf1dfb54
5 changed files with 50 additions and 51 deletions

View File

@ -20,6 +20,7 @@
- 支持通过 `v-model` 绑定当前选中的值,移除 `default-index` 属性 - 支持通过 `v-model` 绑定当前选中的值,移除 `default-index` 属性
- 重新定义了 `columns` 属性的结构 - 重新定义了 `columns` 属性的结构
- 移除了操作内部数据的实例方法,仅保留 `confirm` 方法 - 移除了操作内部数据的实例方法,仅保留 `confirm` 方法
- 新增 `getSelectedOptions` 实例方法
- 调整了 `confirm``cancel``change` 事件的参数 - 调整了 `confirm``cancel``change` 事件的参数
- 重命名 `item-height` 属性为 `option-height` - 重命名 `item-height` 属性为 `option-height`
- 重命名 `visible-item-count` 属性为 `visible-option-num` - 重命名 `visible-item-count` 属性为 `visible-option-num`
@ -89,6 +90,11 @@ emit('clickInput');
- 移除了 `click``disabled` 事件,请使用 `click-tab` 事件代替 - 移除了 `click``disabled` 事件,请使用 `click-tab` 事件代替
#### AddressEdit
- `change-area` 事件的参数调整为 `PickerOption[]` 类型
- 移除未在文档中标注的 `getArea` 实例方法
## 样式变量调整 ## 样式变量调整
### 移除 Less 变量 ### 移除 Less 变量

View File

@ -25,7 +25,7 @@ import {
import { useExpose } from '../composables/use-expose'; import { useExpose } from '../composables/use-expose';
// Components // Components
import { Area, AreaList, AreaColumnOption, AreaInstance } from '../area'; import { Area, AreaList, AreaInstance } from '../area';
import { Cell } from '../cell'; import { Cell } from '../cell';
import { Form } from '../form'; import { Form } from '../form';
import { Field, FieldRule } from '../field'; import { Field, FieldRule } from '../field';
@ -37,6 +37,8 @@ import AddressEditDetail from './AddressEditDetail';
// Types // Types
import type { AddressEditInfo, AddressEditSearchItem } from './types'; import type { AddressEditInfo, AddressEditSearchItem } from './types';
import { PickerConfirmEventParams, PickerOption } from '../picker';
import { AREA_EMPTY_CODE } from '../area/utils';
const [name, bem, t] = createNamespace('address-edit'); const [name, bem, t] = createNamespace('address-edit');
@ -121,9 +123,9 @@ export default defineComponent({
); );
const areaText = computed(() => { const areaText = computed(() => {
const { country, province, city, county, areaCode } = data; const { province, city, county, areaCode } = data;
if (areaCode) { if (areaCode) {
const arr = [country, province, city, county]; const arr = [province, city, county];
if (province && province === city) { if (province && province === city) {
arr.splice(1, 1); arr.splice(1, 1);
} }
@ -137,15 +139,6 @@ export default defineComponent({
() => props.searchResult?.length && detailFocused.value () => props.searchResult?.length && detailFocused.value
); );
const assignAreaValues = () => {
if (areaRef.value) {
const detail: Record<string, string> = areaRef.value.getArea();
detail.areaCode = detail.code;
delete detail.code;
extend(data, detail);
}
};
const onFocus = (key: string) => { const onFocus = (key: string) => {
detailFocused.value = key === 'addressDetail'; detailFocused.value = key === 'addressDetail';
emit('focus', key); emit('focus', key);
@ -191,30 +184,30 @@ export default defineComponent({
emit('changeDetail', val); emit('changeDetail', val);
}; };
const onAreaConfirm = (values: AreaColumnOption[]) => { const assignAreaText = (options: PickerOption[]) => {
values = values.filter(Boolean); data.province = options[0].text as string;
data.city = options[1].text as string;
data.county = options[2].text as string;
};
if (values.some((value) => !value.code)) { const onAreaConfirm = ({
selectedValues,
selectedOptions,
}: PickerConfirmEventParams) => {
if (selectedValues.some((value) => value === AREA_EMPTY_CODE)) {
Toast(t('areaEmpty')); Toast(t('areaEmpty'));
} else { } else {
showAreaPopup.value = false; showAreaPopup.value = false;
assignAreaValues(); assignAreaText(selectedOptions);
emit('changeArea', values); emit('changeArea', selectedOptions);
} }
}; };
const onDelete = () => emit('delete', data); const onDelete = () => emit('delete', data);
// get values of area component
const getArea = () => areaRef.value?.getValues() || [];
// set area code to area component // set area code to area component
const setAreaCode = (code?: string) => { const setAreaCode = (code?: string) => {
data.areaCode = code || ''; data.areaCode = code || '';
if (code) {
nextTick(assignAreaValues);
}
}; };
const onDetailBlur = () => { const onDetailBlur = () => {
@ -253,21 +246,23 @@ export default defineComponent({
}; };
useExpose({ useExpose({
getArea,
setAreaCode, setAreaCode,
setAddressDetail, setAddressDetail,
}); });
watch(
() => props.areaList,
() => setAreaCode(data.areaCode)
);
watch( watch(
() => props.addressInfo, () => props.addressInfo,
(value) => { (value) => {
extend(data, DEFAULT_DATA, value); extend(data, DEFAULT_DATA, value);
setAreaCode(value.areaCode); nextTick(() => {
const options = areaRef.value?.getSelectedOptions();
if (
options &&
options.every((option) => option.value !== AREA_EMPTY_CODE)
) {
assignAreaText(options);
}
});
}, },
{ {
deep: true, deep: true,
@ -371,8 +366,8 @@ export default defineComponent({
lazyRender={false} lazyRender={false}
> >
<Area <Area
v-model={data.areaCode}
ref={areaRef} ref={areaRef}
value={data.areaCode}
loading={!areaListLoaded.value} loading={!areaListLoaded.value}
areaList={props.areaList} areaList={props.areaList}
columnsPlaceholder={props.areaColumnsPlaceholder} columnsPlaceholder={props.areaColumnsPlaceholder}

View File

@ -102,14 +102,14 @@ export default {
| Event | Description | Arguments | | Event | Description | Arguments |
| --- | --- | --- | | --- | --- | --- |
| save | Emitted when the save button is clicked | contentform content | | save | Emitted when the save button is clicked | _info: AddressEditInfo_ |
| focus | Emitted when field is focused | key: field name | | focus | Emitted when field is focused | _key: string_ |
| delete | Emitted when confirming delete | contentform content | | delete | Emitted when confirming delete | _info: AddressEditInfo_ |
| select-search | Emitted when a search result is selected | value: search content | | select-search | Emitted when a search result is selected | _value: string_ |
| click-area | Emitted when the area field is clicked | - | | click-area | Emitted when the area field is clicked | - |
| change-area | Emitted when area changed | values: area values | | change-area | Emitted when area changed | _selectedOptions: PickerOption[]_ |
| change-detail | Emitted when address detail changed | value: address detail | | change-detail | Emitted when address detail changed | _value: string_ |
| change-default | Emitted when switching default address | value: checked | | change-default | Emitted when switching default address | _checked: boolean_ |
### Slots ### Slots

View File

@ -100,16 +100,16 @@ export default {
### Events ### Events
| 事件名 | 说明 | 回调参数 | | 事件名 | 说明 | 回调参数 |
| -------------- | -------------------------- | --------------------------- | | --- | --- | --- |
| save | 点击保存按钮时触发 | content表单内容 | | save | 点击保存按钮时触发 | _info: AddressEditInfo_ |
| focus | 输入框聚焦时触发 | key: 聚焦的输入框对应的 key | | focus | 输入框聚焦时触发 | _key: string_ |
| delete | 确认删除地址时触发 | content表单内容 | | delete | 确认删除地址时触发 | _info: AddressEditInfo_ |
| select-search | 选中搜索结果时触发 | value: 搜索结果 | | select-search | 选中搜索结果时触发 | _value: string_ |
| click-area | 点击收件地区时触发 | - | | click-area | 点击收件地区时触发 | - |
| change-area | 修改收件地区时触发 | values: 地区信息 | | change-area | 修改收件地区时触发 | _selectedOptions: PickerOption[]_ |
| change-detail | 修改详细地址时触发 | value: 详细地址内容 | | change-detail | 修改详细地址时触发 | _value: string_ |
| change-default | 切换是否使用默认地址时触发 | value: 是否选中 | | change-default | 切换是否使用默认地址时触发 | _checked: boolean_ |
### Slots ### Slots

View File

@ -1,5 +1,4 @@
import type { ComponentPublicInstance } from 'vue'; import type { ComponentPublicInstance } from 'vue';
import type { AreaColumnOption } from '../area';
import type { AddressEditProps } from './AddressEdit'; import type { AddressEditProps } from './AddressEdit';
export type AddressEditSearchItem = { export type AddressEditSearchItem = {
@ -21,7 +20,6 @@ export type AddressEditInfo = {
}; };
export type AddressEditExpose = { export type AddressEditExpose = {
getArea: () => AreaColumnOption[];
setAreaCode: (code?: string | undefined) => void; setAreaCode: (code?: string | undefined) => void;
setAddressDetail: (value: string) => void; setAddressDetail: (value: string) => void;
}; };