优化租户管理城市回显逻辑,统一使用cityCode字段并简化代码注释

This commit is contained in:
WUSIJIAN
2025-12-10 15:50:26 +08:00
parent ef4a0e6803
commit 860b024273

View File

@@ -212,30 +212,23 @@ const passwordStrengthClass = computed(() => {
const openDialog = (row?: any) => { const openDialog = (row?: any) => {
resetForm(); resetForm();
if (row) { if (row) {
// 处理城市回显:如果是字符串且以00结尾去掉00并转为数组这里简化处理实际可能需要根据code反查路径 // 处理城市回显:根据 cityCode 转换为级联选择器需要的数组格式
// 假设 row.city 是 "110100"element-china-area-data 的 provinceAndCityData 对应的是 "110000", "110100" // cityCode 是6位代码如 "220100",级联选择器需要 ["22", "2201"] 格式
// 注意provinceAndCityData 的二级code 通常不带后缀 00或者需要具体看数据源
// 这里假设后端存的是 "110100",前端组件需要 ["110000", "110100"] 形式的路径数组
// 由于没有反查函数,这里如果 row.city 是字符串,我们暂时将其直接放入数组,或者需要调用专门的工具函数
// 简单处理:如果 row.city 是字符串,尝试回显
let cityArray: string[] = []; let cityArray: string[] = [];
if (row.cityMergerName && typeof row.cityMergerName === 'string') { const storedCode = row.cityCode;
const storedCode = row.cityMergerName; if (storedCode && typeof storedCode === 'string') {
// 判断是否为直辖市代码 (11xxxx, 12xxxx, 31xxxx, 50xxxx) // 判断是否为直辖市代码 (11xxxx, 12xxxx, 31xxxx, 50xxxx)
if (/^(11|12|31|50)/.test(storedCode)) { if (/^(11|12|31|50)/.test(storedCode)) {
// 直辖市,回显为 [2位代码] (如 '11') // 直辖市,回显为省级代码2位
cityArray = [storedCode.substring(0, 2)]; cityArray = [storedCode.substring(0, 2)];
} else { } else {
// 普通省市,回显为 [2位省代码, 4位市代码] (如 '13', '1301') // 普通省市,回显为 [省代码(2位), 市代码(4位)]
// 假设 storedCode 是 6 位,如 130100
if (storedCode.length >= 4) { if (storedCode.length >= 4) {
const provinceCode = storedCode.substring(0, 2); const provinceCode = storedCode.substring(0, 2);
const cityCode = storedCode.substring(0, 4); const cityCode = storedCode.substring(0, 4);
cityArray = [provinceCode, cityCode]; cityArray = [provinceCode, cityCode];
} }
} }
} else if (Array.isArray(row.cityMergerName)) {
cityArray = row.cityMergerName;
} }
state.ruleForm = { state.ruleForm = {