通过腾讯地图服务API接口(https://lbs.qq.com/service/webService/webServiceGuide/webServiceDistrict#2
)获取省市区数据: apis.map.qq.com/ws/district…
,key为网上所找,如需要删除,请联系
将data json转为一级、二级、三级结构
//level 获取层级,1(一级,省),2(2级,省市),3(3级,省市区)
const getCityData = (level: number) => {
const list = [],
obj = {};
provinceData.forEach((arr, index) => {
if (index > level - 1) return;
arr.forEach((item) => {
const res =
index === 0
? list
: obj[item.id.substring(0, index * 2)].children ||
(obj[item.id.substring(0, index * 2)].children = []);
res.push(
(obj[item.id.substring(0, index * 2 + 2)] = {
value: item.id,
label: item.fullname,
})
);
});
});
return list;
};
getCityData(1)
getCityData(2)
getCityData(3)