fix(collectionSettings): 修复地址显示异常并优化地址数据处理逻辑
修复地址显示中可能出现的'NaN'问题,并优化地址数据的拼接和处理逻辑,确保地址显示正确
Showing
1 changed file
with
32 additions
and
19 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-09-19 14:11:06 | 2 | * @Date: 2022-09-19 14:11:06 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-08-12 18:30:09 | 4 | + * @LastEditTime: 2025-08-13 09:50:04 |
| 5 | * @FilePath: /jgdl/src/pages/collectionSettings/index.vue | 5 | * @FilePath: /jgdl/src/pages/collectionSettings/index.vue |
| 6 | * @Description: 收款设置 | 6 | * @Description: 收款设置 |
| 7 | --> | 7 | --> |
| ... | @@ -199,8 +199,8 @@ | ... | @@ -199,8 +199,8 @@ |
| 199 | class="address-selector" | 199 | class="address-selector" |
| 200 | @click="showAddressSelector = true" | 200 | @click="showAddressSelector = true" |
| 201 | > | 201 | > |
| 202 | - <text class="address-text" :class="{ 'address-selected': addressData.full_address }"> | 202 | + <text class="address-text" :class="{ 'address-selected': addressData.full_address && addressData.full_address !== 'NaN' }"> |
| 203 | - {{ addressData.full_address || '请选择省市县并填写详细地址' }} | 203 | + {{ (addressData.full_address && addressData.full_address !== 'NaN' && addressData.full_address.trim()) || '请选择省市县并填写详细地址' }} |
| 204 | </text> | 204 | </text> |
| 205 | <RectRight color="#999" size="10" /> | 205 | <RectRight color="#999" size="10" /> |
| 206 | </view> | 206 | </view> |
| ... | @@ -447,7 +447,7 @@ const getUserInfo = async () => { | ... | @@ -447,7 +447,7 @@ const getUserInfo = async () => { |
| 447 | userInfo.idcard_city || '', | 447 | userInfo.idcard_city || '', |
| 448 | userInfo.idcard_district || '' | 448 | userInfo.idcard_district || '' |
| 449 | ) | 449 | ) |
| 450 | - | 450 | + |
| 451 | identityInfo.value = { | 451 | identityInfo.value = { |
| 452 | userName: userInfo.name, | 452 | userName: userInfo.name, |
| 453 | idCard: userInfo.idcard, | 453 | idCard: userInfo.idcard, |
| ... | @@ -469,7 +469,7 @@ const getUserInfo = async () => { | ... | @@ -469,7 +469,7 @@ const getUserInfo = async () => { |
| 469 | // 同时更新地址选择器的数据,包含code值用于还原选中状态 | 469 | // 同时更新地址选择器的数据,包含code值用于还原选中状态 |
| 470 | if (userInfo.idcard_province && userInfo.idcard_city && userInfo.idcard_district) { | 470 | if (userInfo.idcard_province && userInfo.idcard_city && userInfo.idcard_district) { |
| 471 | const detailAddr = userInfo.idcard_address || '' | 471 | const detailAddr = userInfo.idcard_address || '' |
| 472 | - | 472 | + |
| 473 | addressData.value = { | 473 | addressData.value = { |
| 474 | province: areaText.province, | 474 | province: areaText.province, |
| 475 | city: areaText.city, | 475 | city: areaText.city, |
| ... | @@ -691,15 +691,28 @@ const openIdentityModal = () => { | ... | @@ -691,15 +691,28 @@ const openIdentityModal = () => { |
| 691 | * 初始化地址选择器数据 | 691 | * 初始化地址选择器数据 |
| 692 | */ | 692 | */ |
| 693 | const initAddressData = () => { | 693 | const initAddressData = () => { |
| 694 | + const province = tempIdentityInfo.value.province || '' | ||
| 695 | + const city = tempIdentityInfo.value.city || '' | ||
| 696 | + const county = tempIdentityInfo.value.county || '' | ||
| 697 | + const detailAddress = tempIdentityInfo.value.idcard_address || '' | ||
| 698 | + | ||
| 699 | + // 安全地拼接完整地址,只有在有有效数据时才拼接 | ||
| 700 | + let fullAddress = '' | ||
| 701 | + if (province || city || county || detailAddress) { | ||
| 702 | + const addressParts = [province, city, county].filter(part => part && part.trim()) | ||
| 703 | + const areaText = addressParts.join('') | ||
| 704 | + fullAddress = detailAddress ? `${areaText} ${detailAddress}`.trim() : areaText | ||
| 705 | + } | ||
| 706 | + | ||
| 694 | addressData.value = { | 707 | addressData.value = { |
| 695 | - province: tempIdentityInfo.value.province || '', | 708 | + province, |
| 696 | - city: tempIdentityInfo.value.city || '', | 709 | + city, |
| 697 | - county: tempIdentityInfo.value.county || '', | 710 | + county, |
| 698 | province_code: tempIdentityInfo.value.idcard_province || '', | 711 | province_code: tempIdentityInfo.value.idcard_province || '', |
| 699 | city_code: tempIdentityInfo.value.idcard_city || '', | 712 | city_code: tempIdentityInfo.value.idcard_city || '', |
| 700 | county_code: tempIdentityInfo.value.idcard_district || '', | 713 | county_code: tempIdentityInfo.value.idcard_district || '', |
| 701 | - detail_address: tempIdentityInfo.value.idcard_address || '', | 714 | + detail_address: detailAddress, |
| 702 | - full_address: (tempIdentityInfo.value.province + tempIdentityInfo.value.city + tempIdentityInfo.value.county + tempIdentityInfo.value.idcard_address) || '' | 715 | + full_address: fullAddress |
| 703 | } | 716 | } |
| 704 | }; | 717 | }; |
| 705 | 718 | ||
| ... | @@ -1156,16 +1169,16 @@ const addressData = ref({ | ... | @@ -1156,16 +1169,16 @@ const addressData = ref({ |
| 1156 | */ | 1169 | */ |
| 1157 | const transformAreaData = (areaList) => { | 1170 | const transformAreaData = (areaList) => { |
| 1158 | const { province_list, city_list, county_list } = areaList | 1171 | const { province_list, city_list, county_list } = areaList |
| 1159 | - | 1172 | + |
| 1160 | return Object.keys(province_list).map(provinceCode => { | 1173 | return Object.keys(province_list).map(provinceCode => { |
| 1161 | const provinceName = province_list[provinceCode] | 1174 | const provinceName = province_list[provinceCode] |
| 1162 | - | 1175 | + |
| 1163 | // 获取该省份下的所有城市 | 1176 | // 获取该省份下的所有城市 |
| 1164 | const cities = Object.keys(city_list) | 1177 | const cities = Object.keys(city_list) |
| 1165 | .filter(cityCode => cityCode.startsWith(provinceCode.substring(0, 2))) | 1178 | .filter(cityCode => cityCode.startsWith(provinceCode.substring(0, 2))) |
| 1166 | .map(cityCode => { | 1179 | .map(cityCode => { |
| 1167 | const cityName = city_list[cityCode] | 1180 | const cityName = city_list[cityCode] |
| 1168 | - | 1181 | + |
| 1169 | // 获取该城市下的所有区县 | 1182 | // 获取该城市下的所有区县 |
| 1170 | const counties = Object.keys(county_list) | 1183 | const counties = Object.keys(county_list) |
| 1171 | .filter(countyCode => countyCode.startsWith(cityCode.substring(0, 4))) | 1184 | .filter(countyCode => countyCode.startsWith(cityCode.substring(0, 4))) |
| ... | @@ -1173,14 +1186,14 @@ const transformAreaData = (areaList) => { | ... | @@ -1173,14 +1186,14 @@ const transformAreaData = (areaList) => { |
| 1173 | value: countyCode, | 1186 | value: countyCode, |
| 1174 | text: county_list[countyCode] | 1187 | text: county_list[countyCode] |
| 1175 | })) | 1188 | })) |
| 1176 | - | 1189 | + |
| 1177 | return { | 1190 | return { |
| 1178 | value: cityCode, | 1191 | value: cityCode, |
| 1179 | text: cityName, | 1192 | text: cityName, |
| 1180 | children: counties.length > 0 ? counties : undefined | 1193 | children: counties.length > 0 ? counties : undefined |
| 1181 | } | 1194 | } |
| 1182 | }) | 1195 | }) |
| 1183 | - | 1196 | + |
| 1184 | return { | 1197 | return { |
| 1185 | value: provinceCode, | 1198 | value: provinceCode, |
| 1186 | text: provinceName, | 1199 | text: provinceName, |
| ... | @@ -1204,19 +1217,19 @@ const areaData = ref(transformAreaData(areaList)) | ... | @@ -1204,19 +1217,19 @@ const areaData = ref(transformAreaData(areaList)) |
| 1204 | const getAreaTextFromCodes = (provinceCode, cityCode, countyCode) => { | 1217 | const getAreaTextFromCodes = (provinceCode, cityCode, countyCode) => { |
| 1205 | const { province_list, city_list, county_list } = areaList | 1218 | const { province_list, city_list, county_list } = areaList |
| 1206 | const result = { province: '', city: '', county: '' } | 1219 | const result = { province: '', city: '', county: '' } |
| 1207 | - | 1220 | + |
| 1208 | if (provinceCode && province_list[provinceCode]) { | 1221 | if (provinceCode && province_list[provinceCode]) { |
| 1209 | result.province = province_list[provinceCode] | 1222 | result.province = province_list[provinceCode] |
| 1210 | } | 1223 | } |
| 1211 | - | 1224 | + |
| 1212 | if (cityCode && city_list[cityCode]) { | 1225 | if (cityCode && city_list[cityCode]) { |
| 1213 | result.city = city_list[cityCode] | 1226 | result.city = city_list[cityCode] |
| 1214 | } | 1227 | } |
| 1215 | - | 1228 | + |
| 1216 | if (countyCode && county_list[countyCode]) { | 1229 | if (countyCode && county_list[countyCode]) { |
| 1217 | result.county = county_list[countyCode] | 1230 | result.county = county_list[countyCode] |
| 1218 | } | 1231 | } |
| 1219 | - | 1232 | + |
| 1220 | return result | 1233 | return result |
| 1221 | } | 1234 | } |
| 1222 | 1235 | ... | ... |
-
Please register or login to post a comment