UNPKG

@tplc/business

Version:

63 lines (59 loc) 1.48 kB
// /api/provinces/provinceCityArea export interface ProvinceCityArea { cityList: CityList[] provinceId: string provinceName: string } interface CityList { areaList?: AreaList[] cityId: string cityName: string provinceId: string } interface AreaList { areaId: string areaName: string cityId: string provinceId: string } export interface AreaOptions { label: string value: string children?: AreaOptions[] } export const getProvinceCityArea = async () => { const { data } = await uni.$lcb.http.post<ProvinceCityArea[]>('/provinces/provinceCityArea') return data.map(({ provinceId, provinceName, cityList }) => { return { label: provinceName, value: provinceId, children: cityList.map(({ cityId, cityName, areaList }) => { return { label: cityName, value: cityId, children: areaList?.map(({ areaId, areaName }) => { return { label: areaName, value: areaId, } }), } }), } }) } export const getProvinceCity = async () => { const { data } = await uni.$lcb.http.post<ProvinceCityArea[]>('/provinces/provinceCityArea') return data.map(({ provinceId, provinceName, cityList }) => { return { label: provinceName, value: provinceId, children: cityList.map(({ cityId, cityName }) => { return { label: cityName, value: cityId, } }), } }) }