From d19c7af137de9e1e6612a3931bf05477746eadf8 Mon Sep 17 00:00:00 2001 From: qkiroc <30946345+qkiroc@users.noreply.github.com> Date: Wed, 25 Sep 2024 19:28:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=84=E4=BB=B6id=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E5=90=8E,=E9=87=8D=E6=96=B0=E8=B5=8B=E5=80=BC=20(#10965)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com> --- packages/amis-editor-core/src/manager.ts | 10 ++++++++-- packages/amis-editor-core/src/store/node.ts | 8 +++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/amis-editor-core/src/manager.ts b/packages/amis-editor-core/src/manager.ts index 5a918aa35..d232476a9 100644 --- a/packages/amis-editor-core/src/manager.ts +++ b/packages/amis-editor-core/src/manager.ts @@ -1879,6 +1879,7 @@ export class EditorManager { this.patching = true; this.patchingInvalid = false; const batch: Array<{id: string; value: any}> = []; + const ids = new Map(); let patchList = (list: Array) => { // 深度优先 list.forEach((node: EditorNodeType) => { @@ -1887,9 +1888,14 @@ export class EditorManager { } if (isAlive(node) && !node.isRegion) { - node.patch(this.store, force, (id, value) => - batch.unshift({id, value}) + const schema = node.schema; + node.patch( + this.store, + force, + (id, value) => batch.unshift({id, value}), + ids ); + ids.set(schema.id, node.schemaPath); } }); }; diff --git a/packages/amis-editor-core/src/store/node.ts b/packages/amis-editor-core/src/store/node.ts index 74323cdfe..9df78a1f7 100644 --- a/packages/amis-editor-core/src/store/node.ts +++ b/packages/amis-editor-core/src/store/node.ts @@ -698,7 +698,8 @@ export const EditorNode = types patch( store: any, force = false, - setPatchInfo?: (id: string, value: any) => void + setPatchInfo?: (id: string, value: any) => void, + ids?: Map ) { // 避免重复 patch if (self.patched && !force) { @@ -720,6 +721,11 @@ export const EditorNode = types patched = {...patched, id: 'u:' + guid()}; } + // id重复了,重新生成一个 + if (ids?.has(patched.id) && ids?.get(patched.id) !== self.schemaPath) { + patched = {...patched, id: 'u:' + guid()}; + } + if ( (Array.isArray(info.regions) && info.regions.length) || Array.isArray(info.patchContainers)