Commit 5acc4e68 by pangchong

fix(editor): 修复添加节点弹窗表单初始化问题

- 在弹窗打开时初始化表单数据,避免关闭过渡动画期间视图闪烁
- 编辑模式下恢复表单数据
- 新增模式下重置表单为空,等待用户选择
- 移除无用空行,优化代码结构
parent ad103e82
import type { FormInst } from 'naive-ui' import type { FormInst } from 'naive-ui'
import { useEditorStore } from '@/store/editor' import { useEditorStore } from '@/store/editor'
import { useAppStore } from '@/store/app' import { useAppStore } from '@/store/app'
import type { XmlNode, DtdAttribute } from '@/types/xmlNode' import type { XmlNode, DtdAttribute } from '@/types/xmlNode'
...@@ -111,7 +110,7 @@ export function useAddNodeModal(formRef: Ref<FormInst | null>) { ...@@ -111,7 +110,7 @@ export function useAddNodeModal(formRef: Ref<FormInst | null>) {
form.attrs = { ...defaults } form.attrs = { ...defaults }
} }
// 重置表单,在弹窗关闭后自动被 v-model 关联或事件重置 // 在弹窗打开时初始化表单数据,避免在关闭过渡动画期间清空表单导致视图闪烁/提前销毁
watch(addNodeVisible, (visible) => { watch(addNodeVisible, (visible) => {
if (visible) { if (visible) {
if (addNodeMode.value === 'edit') { if (addNodeMode.value === 'edit') {
...@@ -163,12 +162,13 @@ export function useAddNodeModal(formRef: Ref<FormInst | null>) { ...@@ -163,12 +162,13 @@ export function useAddNodeModal(formRef: Ref<FormInst | null>) {
} }
form.attrs = attrs form.attrs = attrs
} }
}
} else { } else {
// 新增模式:重置为空,等待用户在下拉列表中主动选择
form.tagName = null form.tagName = null
form.attrs = {} form.attrs = {}
form.textContent = '' form.textContent = ''
} }
}
}) })
// 确认编辑/插入 // 确认编辑/插入
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment