You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
964 B
TypeScript
34 lines
964 B
TypeScript
1 year ago
|
import { provinceAndCityEnum } from '@/enums/city';
|
||
|
export type useCityProps = {
|
||
|
formatProvinceByData: () => { label: string; value: string; children?: Record<string, any>[] }[];
|
||
|
formatCityByProvinceData: (
|
||
|
arg1: Record<string, any>,
|
||
|
) => { label: string; value: string; children?: Record<string, any>[] }[];
|
||
|
};
|
||
|
export const useCity: useCityProps = () => {
|
||
|
function formatProvinceByData() {
|
||
|
const provinceCityData = provinceAndCityEnum.map((item) => {
|
||
|
item.label = item.provinceName;
|
||
|
item.value = item.provinceName;
|
||
|
item.children = item.citys;
|
||
|
return item;
|
||
|
});
|
||
|
return provinceCityData;
|
||
|
}
|
||
|
|
||
|
// formatCityByProvinceData
|
||
|
function formatCityByProvinceData(arg1) {
|
||
|
const cityData = arg1?.children?.map((item) => {
|
||
|
item.label = item.cityName;
|
||
|
item.value = item.cityName;
|
||
|
return item;
|
||
|
});
|
||
|
return cityData;
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
formatProvinceByData,
|
||
|
formatCityByProvinceData,
|
||
|
};
|
||
|
};
|