fix(地区选择): 修复地区选择无效值时默认使用第一个区域
当selectedValue[0]为0或无效时,使用第一个区域作为默认值并确保转换为数字类型
Showing
2 changed files
with
24 additions
and
6 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2025-08-27 17:44:53 | 2 | * @Date: 2025-08-27 17:44:53 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-09-02 21:40:15 | 4 | + * @LastEditTime: 2025-09-03 22:01:38 |
| 5 | * @FilePath: /lls_program/src/pages/CreateFamily/index.vue | 5 | * @FilePath: /lls_program/src/pages/CreateFamily/index.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| ... | @@ -229,8 +229,17 @@ const isFormValid = computed(() => { | ... | @@ -229,8 +229,17 @@ const isFormValid = computed(() => { |
| 229 | * @param {object} param0 - 包含 selectedValue 和 selectedOptions 的对象 | 229 | * @param {object} param0 - 包含 selectedValue 和 selectedOptions 的对象 |
| 230 | */ | 230 | */ |
| 231 | const onDistrictConfirm = ({ selectedValue, selectedOptions }) => { | 231 | const onDistrictConfirm = ({ selectedValue, selectedOptions }) => { |
| 232 | - selectedDistrict.value = selectedValue[0]; | 232 | + // 如果selectedValue[0]为0或无效,使用第一个区域作为默认值 |
| 233 | - selectedDistrictText.value = selectedOptions.map((option) => option.text).join(''); | 233 | + if (!selectedValue[0] || selectedValue[0] === 0) { |
| 234 | + const firstDistrict = districtColumns.value[0]; | ||
| 235 | + selectedDistrict.value = firstDistrict.value; | ||
| 236 | + selectedDistrictText.value = firstDistrict.text; | ||
| 237 | + districtValue.value = [firstDistrict.value]; // 同步更新picker的值 | ||
| 238 | + } else { | ||
| 239 | + selectedDistrict.value = +selectedValue[0]; // 确保转换为数字类型 | ||
| 240 | + selectedDistrictText.value = selectedOptions.map((option) => option.text).join(''); | ||
| 241 | + } | ||
| 242 | + | ||
| 234 | showDistrictPicker.value = false; | 243 | showDistrictPicker.value = false; |
| 235 | }; | 244 | }; |
| 236 | 245 | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2025-08-27 17:44:53 | 2 | * @Date: 2025-08-27 17:44:53 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-09-03 20:31:29 | 4 | + * @LastEditTime: 2025-09-03 21:59:36 |
| 5 | * @FilePath: /lls_program/src/pages/EditFamily/index.vue | 5 | * @FilePath: /lls_program/src/pages/EditFamily/index.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| ... | @@ -237,8 +237,17 @@ onMounted(async () => { | ... | @@ -237,8 +237,17 @@ onMounted(async () => { |
| 237 | * @param {object} param0 - 包含 selectedValue 和 selectedOptions 的对象 | 237 | * @param {object} param0 - 包含 selectedValue 和 selectedOptions 的对象 |
| 238 | */ | 238 | */ |
| 239 | const onDistrictConfirm = ({ selectedValue, selectedOptions }) => { | 239 | const onDistrictConfirm = ({ selectedValue, selectedOptions }) => { |
| 240 | - selectedDistrict.value = selectedValue[0]; | 240 | + // 如果selectedValue[0]为0或无效,使用第一个区域作为默认值 |
| 241 | - selectedDistrictText.value = selectedOptions.map((option) => option.text).join(''); | 241 | + if (!selectedValue[0] || selectedValue[0] === 0) { |
| 242 | + const firstDistrict = districtColumns.value[0]; | ||
| 243 | + selectedDistrict.value = firstDistrict.value; | ||
| 244 | + selectedDistrictText.value = firstDistrict.text; | ||
| 245 | + districtValue.value = [firstDistrict.value]; // 同步更新picker的值 | ||
| 246 | + } else { | ||
| 247 | + selectedDistrict.value = +selectedValue[0]; // 确保转换为数字类型 | ||
| 248 | + selectedDistrictText.value = selectedOptions.map((option) => option.text).join(''); | ||
| 249 | + } | ||
| 250 | + | ||
| 242 | showDistrictPicker.value = false; | 251 | showDistrictPicker.value = false; |
| 243 | }; | 252 | }; |
| 244 | 253 | ... | ... |
-
Please register or login to post a comment