From f3d198983296b3c992c18fc6c0ee51ad705ace8e Mon Sep 17 00:00:00 2001 From: puhui999 Date: Thu, 7 Aug 2025 17:49:20 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E3=80=90IoT=20=E7=89=A9=E8=81=94?= =?UTF-8?q?=E7=BD=91=E3=80=91=E5=9C=BA=E6=99=AF=E8=81=94=E5=8A=A8=20nextTi?= =?UTF-8?q?ck=20=E4=BC=98=E5=8C=96=E4=BD=BF=E7=94=A8=20await=20nextTick()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/rule/scene/form/RuleSceneForm.vue | 11 +++-------- .../scene/form/configs/DeviceTriggerConfig.vue | 11 +++++------ .../form/configs/SubConditionGroupConfig.vue | 11 +++++------ .../rule/scene/form/inputs/JsonParamsInput.vue | 18 ++++++++---------- 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/src/views/iot/rule/scene/form/RuleSceneForm.vue b/src/views/iot/rule/scene/form/RuleSceneForm.vue index 9abcb6981..0a96dce33 100644 --- a/src/views/iot/rule/scene/form/RuleSceneForm.vue +++ b/src/views/iot/rule/scene/form/RuleSceneForm.vue @@ -237,10 +237,6 @@ const handleSubmit = async () => { // 提交请求 submitLoading.value = true try { - // 数据结构已对齐,直接使用表单数据 - console.log('提交数据:', formData.value) - - // 调用API保存数据 if (isEdit.value) { // 更新场景联动规则 await RuleSceneApi.updateRuleScene(formData.value) @@ -299,13 +295,12 @@ const initFormData = () => { } // 监听抽屉显示 -watch(drawerVisible, (visible) => { +watch(drawerVisible, async (visible) => { if (visible) { initFormData() // 重置表单验证状态 - nextTick(() => { - formRef.value?.clearValidate() - }) + await nextTick() + formRef.value?.clearValidate() } }) diff --git a/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue b/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue index d38c6ec8b..c307578e2 100644 --- a/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue +++ b/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue @@ -200,7 +200,7 @@ const handleTriggerTypeChange = (type: number) => { } // 条件组相关方法 -const addSubGroup = () => { +const addSubGroup = async () => { if (!trigger.value.conditionGroups) { trigger.value.conditionGroups = [] } @@ -211,11 +211,10 @@ const addSubGroup = () => { } // 使用 nextTick 确保响应式更新完成后再添加新的子组 - nextTick(() => { - if (trigger.value.conditionGroups) { - trigger.value.conditionGroups.push([]) - } - }) + await nextTick() + if (trigger.value.conditionGroups) { + trigger.value.conditionGroups.push([]) + } } const removeSubGroup = (index: number) => { diff --git a/src/views/iot/rule/scene/form/configs/SubConditionGroupConfig.vue b/src/views/iot/rule/scene/form/configs/SubConditionGroupConfig.vue index 976870537..710af0004 100644 --- a/src/views/iot/rule/scene/form/configs/SubConditionGroupConfig.vue +++ b/src/views/iot/rule/scene/form/configs/SubConditionGroupConfig.vue @@ -107,7 +107,7 @@ const subGroup = useVModel(props, 'modelValue', emit) const maxConditions = computed(() => props.maxConditions || 3) // 事件处理 -const addCondition = () => { +const addCondition = async () => { // 确保 subGroup.value 是一个数组 if (!subGroup.value) { subGroup.value = [] @@ -128,11 +128,10 @@ const addCondition = () => { } // 使用 nextTick 确保响应式更新完成后再添加新条件 - nextTick(() => { - if (subGroup.value) { - subGroup.value.push(newCondition) - } - }) + await nextTick() + if (subGroup.value) { + subGroup.value.push(newCondition) + } } const removeCondition = (index: number) => { diff --git a/src/views/iot/rule/scene/form/inputs/JsonParamsInput.vue b/src/views/iot/rule/scene/form/inputs/JsonParamsInput.vue index 3dbb30428..3e821134d 100644 --- a/src/views/iot/rule/scene/form/inputs/JsonParamsInput.vue +++ b/src/views/iot/rule/scene/form/inputs/JsonParamsInput.vue @@ -462,25 +462,23 @@ const handleDataDisplay = (value: string) => { // 监听外部值变化(编辑模式数据回显) watch( () => localValue.value, - (newValue, oldValue) => { + async (newValue, oldValue) => { // 避免循环更新 if (newValue === oldValue) return // 使用 nextTick 确保在下一个 tick 中处理数据 - nextTick(() => { - handleDataDisplay(newValue || '') - }) + await nextTick() + handleDataDisplay(newValue || '') }, { immediate: true } ) // 组件挂载后也尝试处理一次数据回显 -onMounted(() => { - nextTick(() => { - if (localValue.value) { - handleDataDisplay(localValue.value) - } - }) +onMounted(async () => { + await nextTick() + if (localValue.value) { + handleDataDisplay(localValue.value) + } }) // 监听配置变化