From d039cee9136e7e892161dafe25ff34ee95bce958 Mon Sep 17 00:00:00 2001 From: roymondchen Date: Tue, 9 Dec 2025 16:18:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(tmagic-form):=20runtime=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E5=AF=BC=E8=87=B4root=E4=B8=A2=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/tmagic-form/package.json | 2 +- runtime/tmagic-form/src/App.vue | 2 +- runtime/tmagic-form/src/useFormConfig.ts | 24 ++++++++++++++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/runtime/tmagic-form/package.json b/runtime/tmagic-form/package.json index e4665425..4748c825 100644 --- a/runtime/tmagic-form/package.json +++ b/runtime/tmagic-form/package.json @@ -1,5 +1,5 @@ { - "version": "1.1.3", + "version": "1.1.4", "name": "@tmagic/tmagic-form-runtime", "type": "module", "main": "dist/tmagic-form-runtime.umd.cjs", diff --git a/runtime/tmagic-form/src/App.vue b/runtime/tmagic-form/src/App.vue index 293b771c..7155077f 100644 --- a/runtime/tmagic-form/src/App.vue +++ b/runtime/tmagic-form/src/App.vue @@ -12,7 +12,7 @@ import { useFormConfig } from './useFormConfig'; const props = defineProps(); -const { mForm, formConfig, config, values } = useFormConfig(props); +const { formConfig, config, values } = useFormConfig(props); watch(formConfig, async () => { setTimeout(() => { diff --git a/runtime/tmagic-form/src/useFormConfig.ts b/runtime/tmagic-form/src/useFormConfig.ts index c51a541d..353948c2 100644 --- a/runtime/tmagic-form/src/useFormConfig.ts +++ b/runtime/tmagic-form/src/useFormConfig.ts @@ -73,8 +73,15 @@ export const useFormConfig = (props: AppProps) => { return nextTick().then(() => getElById()(document, `${id}`) as HTMLElement); }, - add({ config, parentId }: UpdateData) { - if (!root.value) throw new Error('error'); + add({ config, parentId, root: appConfig }: UpdateData) { + if (!root.value) { + if (appConfig) { + root.value = appConfig; + resetValues(); + return; + } + throw new Error('error'); + } if (!selectedId.value) throw new Error('error'); if (!parentId) throw new Error('error'); @@ -97,8 +104,17 @@ export const useFormConfig = (props: AppProps) => { resetValues(); }, - update({ config, parentId }: UpdateData) { - if (!root.value || !app) throw new Error('error'); + update({ config, parentId, root: appConfig }: UpdateData) { + if (!root.value) { + if (appConfig) { + root.value = appConfig; + resetValues(); + return; + } + throw new Error('error'); + } + + if (!app) throw new Error('error'); const newNode = app.dataSourceManager?.compiledNode(config) || config; replaceChildNode(reactive(newNode), [root.value], parentId);