From 69905fcbe61c06ead262ff6f5542fa8fbb459a1d Mon Sep 17 00:00:00 2001 From: ls <1769057083@qq.com> Date: Thu, 17 Oct 2024 20:56:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E5=8A=A8=E7=AB=AF=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=99=A8mobile=20=E5=AD=97=E6=AE=B5=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=20(#11072)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat:编辑器移动端支持单独编辑 * fix: ts报错 * fix: 移动端编辑器mobile 字段保存失败 --------- Co-authored-by: zhangxulong Co-authored-by: qkiroc <30946345+qkiroc@users.noreply.github.com> --- .../src/component/Panel/CodeEditorPanel.tsx | 7 ++-- packages/amis-editor-core/src/util.ts | 35 ++++++++++++++----- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/packages/amis-editor-core/src/component/Panel/CodeEditorPanel.tsx b/packages/amis-editor-core/src/component/Panel/CodeEditorPanel.tsx index d2b7f694184..ad33b8bfdea 100644 --- a/packages/amis-editor-core/src/component/Panel/CodeEditorPanel.tsx +++ b/packages/amis-editor-core/src/component/Panel/CodeEditorPanel.tsx @@ -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 { @autobind @@ -23,10 +24,10 @@ export default class CodeEditorPanel extends React.Component { } @autobind - onChange(...rest: any) { + onChange(value: BaseSchema, diff?: Array) { const {store} = this.props; store.patchCodeEdit(true); - this.props.onChange(rest); + this.props.onChange(value, diff); store.patchCodeEdit(false); } diff --git a/packages/amis-editor-core/src/util.ts b/packages/amis-editor-core/src/util.ts index 54815e97673..60b79925cd1 100644 --- a/packages/amis-editor-core/src/util.ts +++ b/packages/amis-editor-core/src/util.ts @@ -934,6 +934,24 @@ export function patchDiff(left: any, changes: Array | undefined) { ); } +/** + * 添加移动端单独编辑标识 + */ +function addMobileAttribute(path: Array) { + 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); }