fix: 移动端编辑器mobile 字段保存失败 (#11072)

* feat:编辑器移动端支持单独编辑

* fix: ts报错

* fix: 移动端编辑器mobile 字段保存失败

---------

Co-authored-by: zhangxulong <zhangxulong@baidu.com>
Co-authored-by: qkiroc <30946345+qkiroc@users.noreply.github.com>
This commit is contained in:
ls 2024-10-17 20:56:18 +08:00 committed by GitHub
parent eaf5217c4a
commit 69905fcbe6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 12 deletions

View File

@ -1,7 +1,8 @@
import React from 'react'; import React from 'react';
import {PanelProps} from '../../plugin'; import {PanelProps} from '../../plugin';
import {autobind} from '../../util'; import {autobind, DiffChange} from '../../util';
import AMisCodeEditor from './AMisCodeEditor'; import AMisCodeEditor from './AMisCodeEditor';
import type {BaseSchema} from 'amis';
export default class CodeEditorPanel extends React.Component<PanelProps> { export default class CodeEditorPanel extends React.Component<PanelProps> {
@autobind @autobind
@ -23,10 +24,10 @@ export default class CodeEditorPanel extends React.Component<PanelProps> {
} }
@autobind @autobind
onChange(...rest: any) { onChange(value: BaseSchema, diff?: Array<DiffChange>) {
const {store} = this.props; const {store} = this.props;
store.patchCodeEdit(true); store.patchCodeEdit(true);
this.props.onChange(rest); this.props.onChange(value, diff);
store.patchCodeEdit(false); store.patchCodeEdit(false);
} }

View File

@ -934,6 +934,24 @@ export function patchDiff(left: any, changes: Array<DiffChange> | undefined) {
); );
} }
/**
*
*/
function addMobileAttribute(path: Array<string>) {
const editorStore = (window as any)?.editorStore;
if (
editorStore.isMobileAloneEdit &&
editorStore.isMobile &&
!editorStore.isCodeEditing &&
!path.slice(-1)?.[0]?.startsWith?.('__') &&
path[0] !== 'body' &&
path[0] !== 'mobile'
) {
path.unshift('mobile');
}
}
/** /**
* copy DeepDiff.applyChange * copy DeepDiff.applyChange
*/ */
@ -947,6 +965,11 @@ function applyChange(target: any, source: any, change: DiffChange) {
path.pop(); path.pop();
} }
// pc 响应式页面纯h5页面不处理
if (change.kind === 'E' || change.kind === 'N') {
addMobileAttribute(path);
}
path.reduce( path.reduce(
({target, source}, key) => { ({target, source}, key) => {
const nextSource = source[key]; const nextSource = source[key];
@ -969,15 +992,9 @@ function applyChange(target: any, source: any, change: DiffChange) {
source source
} }
); );
const editorStore = (window as any)?.editorStore;
// pc 响应式页面纯h5页面不处理 // 一定要要再添加一遍
if ( addMobileAttribute(change.path);
editorStore.isMobileAloneEdit &&
editorStore.isMobile &&
!editorStore.isCodeEditing
) {
change.path.unshift('mobile');
}
DeepDiff.applyChange(target, source, change); DeepDiff.applyChange(target, source, change);
} }