From 9180df9dcd789d4117a5c5ec94894eb6c751dfa4 Mon Sep 17 00:00:00 2001 From: qkiroc <30946345+qkiroc@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:00:57 +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(#10943)?= 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..16d892fdf 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, true); } }); }; diff --git a/packages/amis-editor-core/src/store/node.ts b/packages/amis-editor-core/src/store/node.ts index 74323cdfe..9367b6821 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)) { + patched = {...patched, id: 'u:' + guid()}; + } + if ( (Array.isArray(info.regions) && info.regions.length) || Array.isArray(info.patchContainers)