mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 10:29:19 +08:00
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:
parent
eaf5217c4a
commit
69905fcbe6
@ -1,7 +1,8 @@
|
||||
import React from 'react';
|
||||
import {PanelProps} from '../../plugin';
|
||||
import {autobind} from '../../util';
|
||||
import {autobind, DiffChange} from '../../util';
|
||||
import AMisCodeEditor from './AMisCodeEditor';
|
||||
import type {BaseSchema} from 'amis';
|
||||
|
||||
export default class CodeEditorPanel extends React.Component<PanelProps> {
|
||||
@autobind
|
||||
@ -23,10 +24,10 @@ export default class CodeEditorPanel extends React.Component<PanelProps> {
|
||||
}
|
||||
|
||||
@autobind
|
||||
onChange(...rest: any) {
|
||||
onChange(value: BaseSchema, diff?: Array<DiffChange>) {
|
||||
const {store} = this.props;
|
||||
store.patchCodeEdit(true);
|
||||
this.props.onChange(rest);
|
||||
this.props.onChange(value, diff);
|
||||
store.patchCodeEdit(false);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
*/
|
||||
@ -947,6 +965,11 @@ function applyChange(target: any, source: any, change: DiffChange) {
|
||||
path.pop();
|
||||
}
|
||||
|
||||
// pc 响应式页面,纯h5页面不处理
|
||||
if (change.kind === 'E' || change.kind === 'N') {
|
||||
addMobileAttribute(path);
|
||||
}
|
||||
|
||||
path.reduce(
|
||||
({target, source}, key) => {
|
||||
const nextSource = source[key];
|
||||
@ -969,15 +992,9 @@ function applyChange(target: any, source: any, change: DiffChange) {
|
||||
source
|
||||
}
|
||||
);
|
||||
const editorStore = (window as any)?.editorStore;
|
||||
// pc 响应式页面,纯h5页面不处理
|
||||
if (
|
||||
editorStore.isMobileAloneEdit &&
|
||||
editorStore.isMobile &&
|
||||
!editorStore.isCodeEditing
|
||||
) {
|
||||
change.path.unshift('mobile');
|
||||
}
|
||||
|
||||
// 一定要要再添加一遍
|
||||
addMobileAttribute(change.path);
|
||||
DeepDiff.applyChange(target, source, change);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user