From 2f0918e746f26a198a669f640f4613bf37b946b0 Mon Sep 17 00:00:00 2001 From: lvxiaojiao Date: Tue, 9 Jul 2024 21:53:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8=E9=A2=84=E8=A7=88=E6=A8=A1=E5=BC=8F=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E7=9A=84=E4=B8=8A=E4=B8=8B=E6=96=87=E4=BF=A1=E6=81=AF=E4=BC=9A?= =?UTF-8?q?=E4=B8=A2=E5=A4=B1=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-editor-core/src/component/Editor.tsx | 2 +- .../amis-editor-core/src/component/IFramePreview.tsx | 3 ++- packages/amis-editor-core/src/component/Preview.tsx | 3 ++- packages/amis-editor-core/src/store/editor.ts | 12 +++++++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/amis-editor-core/src/component/Editor.tsx b/packages/amis-editor-core/src/component/Editor.tsx index 222d6d1bb..9c30d7ab2 100644 --- a/packages/amis-editor-core/src/component/Editor.tsx +++ b/packages/amis-editor-core/src/component/Editor.tsx @@ -166,7 +166,6 @@ export default class Editor extends Component { theme: props.theme, isSubEditor, amisDocHost: props.amisDocHost, - ctx: props.ctx, superEditorData, appLocale: props.appLocale, appCorpusData: props?.amisEnv?.replaceText, @@ -174,6 +173,7 @@ export default class Editor extends Component { }, config ); + this.store.setCtx(props.ctx); this.store.setSchema(value); if (showCustomRenderersPanel !== undefined) { this.store.setShowCustomRenderersPanel(showCustomRenderersPanel); diff --git a/packages/amis-editor-core/src/component/IFramePreview.tsx b/packages/amis-editor-core/src/component/IFramePreview.tsx index 9f4e6790b..72e420863 100644 --- a/packages/amis-editor-core/src/component/IFramePreview.tsx +++ b/packages/amis-editor-core/src/component/IFramePreview.tsx @@ -114,7 +114,8 @@ export default class IFramePreview extends React.Component { ...rest, key: editable ? 'edit-mode' : 'preview-mode', theme: env.theme, - data: data ?? store.ctx, + data: data, + context: store.ctx, locale: appLocale, editorDialogMountNode: this.getDialogMountRef }, diff --git a/packages/amis-editor-core/src/component/Preview.tsx b/packages/amis-editor-core/src/component/Preview.tsx index c3bcc2453..e431ee15b 100644 --- a/packages/amis-editor-core/src/component/Preview.tsx +++ b/packages/amis-editor-core/src/component/Preview.tsx @@ -686,7 +686,8 @@ class SmartPreview extends React.Component { ...rest, key: editable ? 'edit-mode' : 'preview-mode', theme: env.theme, - data: data ?? store.ctx, + data: data, + context: store.ctx, locale: appLocale, editorDialogMountNode: this.getDialogMountRef }, diff --git a/packages/amis-editor-core/src/store/editor.ts b/packages/amis-editor-core/src/store/editor.ts index e7c182f6e..cbd4bad41 100644 --- a/packages/amis-editor-core/src/store/editor.ts +++ b/packages/amis-editor-core/src/store/editor.ts @@ -5,7 +5,8 @@ import { mapTree, eachTree, extendObject, - createObject + createObject, + extractObjectChain } from 'amis-core'; import {cast, getEnv, Instance, types} from 'mobx-state-tree'; import { @@ -1060,6 +1061,15 @@ export const MainStore = types }, setCtx(value: any) { + if (value?.__super) { + // context 不支持链式,如果这样下发了,需要转成普通对象。 + // 目前平台会下发这种数据,为了防止数据丢失做个处理 + value = extractObjectChain(value).reduce( + (obj, item) => Object.assign(obj, item), + {} + ); + } + self.ctx = value; },