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.
|
|
|
/*
|
|
|
|
* @Author: donghao donghao@supervision.ltd
|
|
|
|
* @Date: 2024-04-19 17:10:21
|
|
|
|
* @LastEditors: donghao donghao@supervision.ltd
|
|
|
|
* @LastEditTime: 2024-04-24 15:05:21
|
|
|
|
* @FilePath: \general-ai-platform-web\src\hooks\useCity.tsx
|
|
|
|
* @Description: 省份城市数据转换
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
function formatCityByProvinceData(arg1) {
|
|
|
|
const cityData = arg1?.children?.map((item) => {
|
|
|
|
item.label = item.cityName;
|
|
|
|
item.value = item.cityName;
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
return cityData;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
formatProvinceByData,
|
|
|
|
formatCityByProvinceData,
|
|
|
|
};
|
|
|
|
};
|