fix: 修复编辑器预览模式弹窗的上下文信息会丢失的问题

This commit is contained in:
lvxiaojiao 2024-07-09 21:53:21 +08:00
parent f16b3ad1d8
commit 2f0918e746
4 changed files with 16 additions and 4 deletions

View File

@ -166,7 +166,6 @@ export default class Editor extends Component<EditorProps> {
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<EditorProps> {
},
config
);
this.store.setCtx(props.ctx);
this.store.setSchema(value);
if (showCustomRenderersPanel !== undefined) {
this.store.setShowCustomRenderersPanel(showCustomRenderersPanel);

View File

@ -114,7 +114,8 @@ export default class IFramePreview extends React.Component<IFramePreviewProps> {
...rest,
key: editable ? 'edit-mode' : 'preview-mode',
theme: env.theme,
data: data ?? store.ctx,
data: data,
context: store.ctx,
locale: appLocale,
editorDialogMountNode: this.getDialogMountRef
},

View File

@ -686,7 +686,8 @@ class SmartPreview extends React.Component<SmartPreviewProps> {
...rest,
key: editable ? 'edit-mode' : 'preview-mode',
theme: env.theme,
data: data ?? store.ctx,
data: data,
context: store.ctx,
locale: appLocale,
editorDialogMountNode: this.getDialogMountRef
},

View File

@ -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;
},