hookehuyr

fix(地区选择): 修复地区选择无效值时默认使用第一个区域

当selectedValue[0]为0或无效时,使用第一个区域作为默认值并确保转换为数字类型
<!--
* @Date: 2025-08-27 17:44:53
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-09-02 21:40:15
* @LastEditTime: 2025-09-03 22:01:38
* @FilePath: /lls_program/src/pages/CreateFamily/index.vue
* @Description: 文件描述
-->
......@@ -229,8 +229,17 @@ const isFormValid = computed(() => {
* @param {object} param0 - 包含 selectedValue 和 selectedOptions 的对象
*/
const onDistrictConfirm = ({ selectedValue, selectedOptions }) => {
selectedDistrict.value = selectedValue[0];
selectedDistrictText.value = selectedOptions.map((option) => option.text).join('');
// 如果selectedValue[0]为0或无效,使用第一个区域作为默认值
if (!selectedValue[0] || selectedValue[0] === 0) {
const firstDistrict = districtColumns.value[0];
selectedDistrict.value = firstDistrict.value;
selectedDistrictText.value = firstDistrict.text;
districtValue.value = [firstDistrict.value]; // 同步更新picker的值
} else {
selectedDistrict.value = +selectedValue[0]; // 确保转换为数字类型
selectedDistrictText.value = selectedOptions.map((option) => option.text).join('');
}
showDistrictPicker.value = false;
};
......
<!--
* @Date: 2025-08-27 17:44:53
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-09-03 20:31:29
* @LastEditTime: 2025-09-03 21:59:36
* @FilePath: /lls_program/src/pages/EditFamily/index.vue
* @Description: 文件描述
-->
......@@ -237,8 +237,17 @@ onMounted(async () => {
* @param {object} param0 - 包含 selectedValue 和 selectedOptions 的对象
*/
const onDistrictConfirm = ({ selectedValue, selectedOptions }) => {
selectedDistrict.value = selectedValue[0];
selectedDistrictText.value = selectedOptions.map((option) => option.text).join('');
// 如果selectedValue[0]为0或无效,使用第一个区域作为默认值
if (!selectedValue[0] || selectedValue[0] === 0) {
const firstDistrict = districtColumns.value[0];
selectedDistrict.value = firstDistrict.value;
selectedDistrictText.value = firstDistrict.text;
districtValue.value = [firstDistrict.value]; // 同步更新picker的值
} else {
selectedDistrict.value = +selectedValue[0]; // 确保转换为数字类型
selectedDistrictText.value = selectedOptions.map((option) => option.text).join('');
}
showDistrictPicker.value = false;
};
......