From e4b82b4b2654ff479bf4d2de2f534b9a83e68c50 Mon Sep 17 00:00:00 2001 From: hwj Date: Mon, 19 Jan 2026 14:25:24 +0800 Subject: [PATCH] =?UTF-8?q?style=EF=BC=9A=E7=BB=B4=E4=BF=AE=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE-=E6=96=B0=E5=A2=9E/=E7=BC=96=E8=BE=91-=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E7=B1=BB=E5=9E=8B=E5=88=87=E6=8D=A2=E6=97=B6=E9=87=8D?= =?UTF-8?q?=E7=BD=AE=E8=AE=BE=E5=A4=87=E4=B8=8B=E6=8B=89=E6=A1=86=E5=86=85?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/mes/repairItems/RepairItemsForm.vue | 46 +++++++++++++------ 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/src/views/mes/repairItems/RepairItemsForm.vue b/src/views/mes/repairItems/RepairItemsForm.vue index 3c990f83..dac9bfe0 100644 --- a/src/views/mes/repairItems/RepairItemsForm.vue +++ b/src/views/mes/repairItems/RepairItemsForm.vue @@ -95,6 +95,9 @@ const formLoading = ref(false) const formType = ref('') const formRef = ref() +const isInitializing = ref(false) +const isSwitchingDeviceType = ref(false) + const formData = ref({ id: undefined as number | undefined, subjectCode: undefined as string | undefined, @@ -163,15 +166,16 @@ const loadComponentOptionsByDeviceId = async (deviceId: number) => { watch( () => formData.value.deviceType, - (val) => { - if (val === 1) { - formData.value.componentId = undefined - componentOptions.value = [] - } else if (val !== 2) { - formData.value.deviceId = undefined - formData.value.componentId = undefined - componentOptions.value = [] - } + async () => { + if (isInitializing.value) return + isSwitchingDeviceType.value = true + formData.value.deviceId = undefined + deviceOptions.value = [] + formData.value.componentId = undefined + componentOptions.value = [] + await nextTick() + formRef.value?.clearValidate?.(['deviceId', 'componentId']) + isSwitchingDeviceType.value = false } ) @@ -187,6 +191,10 @@ watch( ) const validateDeviceId = (_: any, value: any, callback: any) => { + if (isSwitchingDeviceType.value) { + callback() + return + } const dt = formData.value.deviceType if ((dt === 1 || dt === 2) && (value === undefined || value === null || value === '')) { callback(new Error('设备不能为空')) @@ -196,6 +204,10 @@ const validateDeviceId = (_: any, value: any, callback: any) => { } const validateComponentId = (_: any, value: any, callback: any) => { + if (isSwitchingDeviceType.value) { + callback() + return + } const dt = formData.value.deviceType if (dt === 2 && (value === undefined || value === null || value === '')) { callback(new Error('关键件不能为空')) @@ -205,18 +217,19 @@ const validateComponentId = (_: any, value: any, callback: any) => { } const formRules = reactive({ - subjectCode: [{ required: true, message: '项目编码不能为空', trigger: 'blur' }], - subjectName: [{ required: true, message: '项目名称不能为空', trigger: 'blur' }], - deviceType: [{ required: true, message: '设备类型不能为空', trigger: 'change' }], - deviceId: [{ validator: validateDeviceId, trigger: 'change' }], - componentId: [{ validator: validateComponentId, trigger: 'change' }], - isEnable: [{ required: true, message: '是否启用不能为空', trigger: 'change' }] + subjectCode: [{ required: true, message: '项目编码不能为空' }], + subjectName: [{ required: true, message: '项目名称不能为空' }], + deviceType: [{ required: true, message: '设备类型不能为空' }], + deviceId: [{ validator: validateDeviceId }], + componentId: [{ validator: validateComponentId }], + isEnable: [{ required: true, message: '是否启用不能为空' }] }) const open = async (type: string, row?: any) => { dialogVisible.value = true dialogTitle.value = t('action.' + type) formType.value = type + isInitializing.value = true resetForm() if (!dictReady.value) { await dictStore.setDictMap() @@ -249,6 +262,9 @@ const open = async (type: string, row?: any) => { } } } + await nextTick() + formRef.value?.clearValidate?.() + isInitializing.value = false } defineExpose({ open })