From c3bcbf2a70ca7f18a75420c8c75c6a2c2eead83f Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2betop.cn@gmail.com> Date: Mon, 22 Apr 2024 17:28:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E9=97=AE=E9=A2=98=20(#10083)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-editor-core/src/util.ts | 67 +++++++++++++++++---------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/packages/amis-editor-core/src/util.ts b/packages/amis-editor-core/src/util.ts index fb94f936a..725c0c18b 100644 --- a/packages/amis-editor-core/src/util.ts +++ b/packages/amis-editor-core/src/util.ts @@ -1506,11 +1506,6 @@ export function mergeDefinitions( let schema = originSchema; Object.keys(definitions).forEach(key => { - // 弹窗里面用到了才更新 - if (!refs.includes(key)) { - return; - } - // 要修改就复制一份,避免污染原始数据 if (schema === originSchema) { schema = {...schema, definitions: {...schema.definitions}}; @@ -1518,28 +1513,50 @@ export function mergeDefinitions( const {$$originId, ...def} = definitions[key]; - if (schema.$$id === $$originId) { - schema = JSONUpdate(schema, $$originId, JSONPipeIn(def)); - } else if ($$originId) { + if ($$originId) { const parent = JSONGetParentById(schema, $$originId); - if (!parent) { - throw new Error('Can not find modal action.'); - } - const modalType = def.type === 'drawer' ? 'drawer' : 'dialog'; - schema = JSONUpdate(schema, parent.$$id, { - ...parent, - __actionModals: undefined, - args: undefined, - dialog: undefined, - drawer: undefined, - actionType: def.actionType ?? modalType, - [modalType]: JSONPipeIn({ - $ref: key - }) - }); - schema.definitions[key] = JSONPipeIn(def); - } else { + // 当前更新弹窗里面用到了需要转成 ref + if (refs.includes(key)) { + if (schema.$$id === $$originId) { + schema = JSONUpdate(schema, $$originId, JSONPipeIn(def)); + return; + } + + if (!parent) { + throw new Error('Can not find modal action.'); + } + + const modalType = def.type === 'drawer' ? 'drawer' : 'dialog'; + schema = JSONUpdate(schema, parent.$$id, { + ...parent, + __actionModals: undefined, + args: undefined, + dialog: undefined, + drawer: undefined, + actionType: def.actionType ?? modalType, + [modalType]: JSONPipeIn({ + $ref: key + }) + }); + schema.definitions[key] = JSONPipeIn(def); + } else if (parent) { + // 没用到,可能修改了弹窗的内容为引用其他弹窗,同样需要更新,但是不会提取为 definitions + const modalType = def.type === 'drawer' ? 'drawer' : 'dialog'; + schema = JSONUpdate(schema, parent.$$id, { + ...parent, + __actionModals: undefined, + args: undefined, + dialog: undefined, + drawer: undefined, + actionType: def.actionType ?? modalType, + [modalType]: JSONPipeIn({ + ...def, + $$originId: undefined + }) + }); + } + } else if (refs.includes(key)) { schema.definitions[key] = JSONPipeIn(def); } });