From 759d4534d9ddbe7bc2758c3ffb07c0679e084461 Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2betop.cn@gmail.com> Date: Wed, 24 Apr 2024 21:42:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A0=E6=B3=95=E5=88=A0=E9=99=A4=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E7=9A=84=E9=97=AE=E9=A2=98=20(#10102)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-editor-core/src/store/editor.ts | 87 ++++++++++++------ packages/amis-editor-core/src/util.ts | 52 ++++++----- .../event-control/DialogActionPanel.tsx | 91 ++++++++++++------- 3 files changed, 147 insertions(+), 83 deletions(-) diff --git a/packages/amis-editor-core/src/store/editor.ts b/packages/amis-editor-core/src/store/editor.ts index db01dda07..3af09017d 100644 --- a/packages/amis-editor-core/src/store/editor.ts +++ b/packages/amis-editor-core/src/store/editor.ts @@ -553,18 +553,27 @@ export const MainStore = types } const isSubEditor = self.isSubEditor; + const isHiddenProps = getEnv(self).isHiddenProps; return JSONPipeOut( JSONGetById(self.schema, self.activeId), - getEnv(self).isHiddenProps || - ((key, props) => - // 如果是子弹窗,不显示 definitions,要是通过代码模式改了,就麻烦了 - (isSubEditor && key === 'definitions') || + (key, props) => { + if (isSubEditor && key === 'definitions') { + return true; + } + + if (typeof isHiddenProps === 'function') { + return isHiddenProps(key, props); + } + + return ( (key.substring(0, 2) === '$$' && key !== '$$comments' && key !== '$$commonSchema') || typeof props === 'function' || // pipeIn 和 pipeOut - key.substring(0, 2) === '__') + key.substring(0, 2) === '__' + ); + } ); }, @@ -1812,7 +1821,7 @@ export const MainStore = types ? 'drawer' : 'dialog'; - schema = JSONUpdate(schema, id, modal); + schema = JSONUpdate(schema, id, modal, true); // 如果编辑的是公共弹窗 if (!parent.actionType) { @@ -1829,25 +1838,35 @@ export const MainStore = types modalKey && newHostKey !== (value === 'drawer' ? 'drawer' : 'dialog') ) { - schema = JSONUpdate(schema, host.$$id, { - actionType: (modal as any).actionType || modal.type, - args: undefined, - dialog: undefined, - drawer: undefined, - [newHostKey]: host[value === 'drawer' ? 'drawer' : 'dialog'] - }); + schema = JSONUpdate( + schema, + host.$$id, + { + actionType: (modal as any).actionType || modal.type, + args: undefined, + dialog: undefined, + drawer: undefined, + [newHostKey]: host[value === 'drawer' ? 'drawer' : 'dialog'] + }, + true + ); } return value; }); } else { // 内嵌弹窗只用改自己就行了 - schema = JSONUpdate(schema, parent.$$id, { - actionType: (modal as any).actionType || modal.type, - args: undefined, - dialog: undefined, - drawer: undefined, - [newHostKey]: modal - }); + schema = JSONUpdate( + schema, + parent.$$id, + { + actionType: (modal as any).actionType || modal.type, + args: undefined, + dialog: undefined, + drawer: undefined, + [newHostKey]: modal + }, + true + ); } // 如果弹窗里面又弹窗指向自己,那么也要更新 @@ -1860,16 +1879,26 @@ export const MainStore = types if (refIds.length) { let refKey = ''; [schema, refKey] = addModal(schema, modal); - schema = JSONUpdate(schema, parent.$$id, { - [newHostKey]: JSONPipeIn({ - $ref: refKey - }) - }); + schema = JSONUpdate( + schema, + parent.$$id, + { + [newHostKey]: JSONPipeIn({ + $ref: refKey + }) + }, + true + ); refIds.forEach(refId => { - schema = JSONUpdate(schema, refId, { - $ref: refKey, - $$originId: undefined - }); + schema = JSONUpdate( + schema, + refId, + { + $ref: refKey, + $$originId: undefined + }, + true + ); }); } diff --git a/packages/amis-editor-core/src/util.ts b/packages/amis-editor-core/src/util.ts index 4724e2569..36551414d 100644 --- a/packages/amis-editor-core/src/util.ts +++ b/packages/amis-editor-core/src/util.ts @@ -1519,7 +1519,7 @@ export function mergeDefinitions( // 当前更新弹窗里面用到了需要转成 ref if (refs.includes(key)) { if (schema.$$id === $$originId) { - schema = JSONUpdate(schema, $$originId, JSONPipeIn(def)); + schema = JSONUpdate(schema, $$originId, JSONPipeIn(def), true); return; } @@ -1528,17 +1528,22 @@ export function mergeDefinitions( } 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 = JSONUpdate( + schema, + parent.$$id, + { + ...parent, + __actionModals: undefined, + args: undefined, + dialog: undefined, + drawer: undefined, + actionType: def.actionType ?? modalType, + [modalType]: JSONPipeIn({ + $ref: key + }) + }, + true + ); schema.definitions[key] = JSONPipeIn(def); } else if (parent) { // 没用到,可能修改了弹窗的内容为引用其他弹窗,同样需要更新,但是不会提取为 definitions @@ -1550,15 +1555,20 @@ export function mergeDefinitions( if (changes) { const newModal = patchDiff(origin, changes); delete newModal.$$originId; - schema = JSONUpdate(schema, parent.$$id, { - ...parent, - __actionModals: undefined, - args: undefined, - dialog: undefined, - drawer: undefined, - actionType: def.actionType ?? modalType, - [modalType]: newModal - }); + schema = JSONUpdate( + schema, + parent.$$id, + { + ...parent, + __actionModals: undefined, + args: undefined, + dialog: undefined, + drawer: undefined, + actionType: def.actionType ?? modalType, + [modalType]: newModal + }, + true + ); } } } else if (refs.includes(key)) { diff --git a/packages/amis-editor/src/renderer/event-control/DialogActionPanel.tsx b/packages/amis-editor/src/renderer/event-control/DialogActionPanel.tsx index 7643d595b..36aa81e60 100644 --- a/packages/amis-editor/src/renderer/event-control/DialogActionPanel.tsx +++ b/packages/amis-editor/src/renderer/event-control/DialogActionPanel.tsx @@ -132,32 +132,42 @@ function DialogActionPanel({ const newModal = patchDiff(origin, changes); delete newModal.$$originId; delete newModal.$$ref; - schema = JSONUpdate(schema, parent.$$id, { - ...parent, - __actionModals: undefined, - args: undefined, - dialog: undefined, - drawer: undefined, - actionType: def.actionType ?? modalType, - [modalType]: newModal - }); + schema = JSONUpdate( + schema, + parent.$$id, + { + ...parent, + __actionModals: undefined, + args: undefined, + dialog: undefined, + drawer: undefined, + actionType: def.actionType ?? modalType, + [modalType]: newModal + }, + true + ); } // 不要写下面的 defintions 了 return; } else { 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: modal.$$ref! - }) - }); + schema = JSONUpdate( + schema, + parent.$$id, + { + ...parent, + __actionModals: undefined, + args: undefined, + dialog: undefined, + drawer: undefined, + actionType: def.actionType ?? modalType, + [modalType]: JSONPipeIn({ + $ref: modal.$$ref! + }) + }, + true + ); } } schema.definitions[modal.$$ref!] = JSONPipeIn(def); @@ -261,10 +271,15 @@ function DialogActionPanel({ const definition = schema.definitions[key]; const exits = JSONGetById(definition, id); if (exits) { - schema.definitions[key] = JSONUpdate(schema.definitions[key], id, { - ...schema, - definitions: undefined - }); + schema.definitions[key] = JSONUpdate( + schema.definitions[key], + id, + { + ...schema, + definitions: undefined + }, + true + ); } }); } @@ -280,16 +295,26 @@ function DialogActionPanel({ if (refIds.length) { let refKey = ''; [schema, refKey] = addModal(schema, currentModal.modal); - schema = JSONUpdate(schema, actionSchema.$$id, { - [modalType]: JSONPipeIn({ - $ref: refKey - }) - }); + schema = JSONUpdate( + schema, + actionSchema.$$id, + { + [modalType]: JSONPipeIn({ + $ref: refKey + }) + }, + true + ); refIds.forEach(refId => { - schema = JSONUpdate(schema, refId, { - $ref: refKey, - $$originId: undefined - }); + schema = JSONUpdate( + schema, + refId, + { + $ref: refKey, + $$originId: undefined + }, + true + ); }); }