33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
|
import areaData from 'china-area-data/data';
|
||
|
// 修改导入语句
|
||
|
import type { CascaderProps, DefaultOptionType } from 'antd/es/cascader';
|
||
|
|
||
|
// 修改转换函数类型
|
||
|
function transformAreaData(): CascaderProps['options'] {
|
||
|
const provinces = areaData['86'] as Record<string, string>;
|
||
|
|
||
|
return Object.entries(provinces).map(([provinceCode, provinceName]): DefaultOptionType => {
|
||
|
const cities = areaData[provinceCode] as Record<string, string>;
|
||
|
|
||
|
return {
|
||
|
value: provinceCode,
|
||
|
label: provinceName as string,
|
||
|
children: Object.entries(cities).map(([cityCode, cityName]): DefaultOptionType => {
|
||
|
const districts = areaData[cityCode] as Record<string, string>;
|
||
|
|
||
|
return {
|
||
|
value: cityCode,
|
||
|
label: cityName as string,
|
||
|
children: districts
|
||
|
? Object.entries(districts).map(([districtCode, districtName]): DefaultOptionType => ({
|
||
|
value: districtCode,
|
||
|
label: districtName as string,
|
||
|
}))
|
||
|
: [],
|
||
|
};
|
||
|
}),
|
||
|
};
|
||
|
});
|
||
|
}
|
||
|
|
||
|
export const areaOptions: DefaultOptionType[] = transformAreaData();
|