增加处理意见展示

This commit is contained in:
2025-10-08 16:14:19 +08:00
parent b95239812d
commit d66216c669
5 changed files with 482 additions and 27 deletions

View File

@@ -0,0 +1,93 @@
// 使用china-area-data包提供完整的省市区数据
import areaData from 'china-area-data';
// 转换数据格式为我们需要的格式
function convertAreaData() {
const provinces = [];
// 遍历省份
Object.keys(areaData['86']).forEach(provinceCode => {
const provinceName = areaData['86'][provinceCode];
const province = {
value: provinceCode,
label: provinceName,
children: []
};
// 遍历城市
if (areaData[provinceCode]) {
Object.keys(areaData[provinceCode]).forEach(cityCode => {
const cityName = areaData[provinceCode][cityCode];
const city = {
value: cityCode,
label: cityName,
children: []
};
// 遍历区县
if (areaData[cityCode]) {
Object.keys(areaData[cityCode]).forEach(countyCode => {
const countyName = areaData[cityCode][countyCode];
city.children.push({
value: countyCode,
label: countyName
});
});
}
province.children.push(city);
});
}
provinces.push(province);
});
return provinces;
}
// 生成完整的省市区数据
const provinceData = convertAreaData();
// 根据省份代码获取城市列表
function getCitiesByProvince(provinceCode) {
const province = provinceData.find(p => p.value === provinceCode);
return province ? province.children : [];
}
// 根据城市代码获取区县列表
function getCountiesByCity(cityCode) {
for (const province of provinceData) {
const city = province.children.find(c => c.value === cityCode);
if (city) {
return city.children;
}
}
return [];
}
// 根据代码获取名称
function getNameByCode(code) {
// 查找省份
for (const province of provinceData) {
if (province.value === code) {
return province.label;
}
// 查找城市
for (const city of province.children) {
if (city.value === code) {
return city.label;
}
// 查找区县
if (city.children) {
for (const county of city.children) {
if (county.value === code) {
return county.label;
}
}
}
}
}
return '';
}
export { provinceData, getCitiesByProvince, getCountiesByCity, getNameByCode };