From 0d00fa1dfe4fe82e69e38617370af47dc74813bb Mon Sep 17 00:00:00 2001 From: wibetter <365533093@qq.com> Date: Thu, 16 Mar 2023 20:52:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(amis-saas-10174):=20=E6=82=AC=E6=B5=AE?= =?UTF-8?q?=E5=92=8C=E5=90=B8=E9=99=84=E5=AE=B9=E5=99=A8=E7=82=B9=E9=80=89?= =?UTF-8?q?=E6=8F=92=E5=85=A5=E9=A1=B5=E9=9D=A2=E6=97=B6=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=8F=92=E5=85=A5=E9=A1=B5=E9=9D=A2=E6=A0=B9=E7=BB=93=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Idc15457b978ecd77a0a9ab0f2b32d8a3e5f43257 --- packages/amis-editor-core/src/manager.ts | 49 +++++++++++++++++------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/packages/amis-editor-core/src/manager.ts b/packages/amis-editor-core/src/manager.ts index ad95850b7..d49f1a3df 100644 --- a/packages/amis-editor-core/src/manager.ts +++ b/packages/amis-editor-core/src/manager.ts @@ -805,33 +805,42 @@ export class EditorManager { const store = this.store; let subRenderer; + let curActiveId = store.activeId; + let node = store.getNodeById(curActiveId)!; // 默认插入当前选中节点 if (rendererId) { // 当有 rendererId 时,获取渲染器信息 subRenderer = store.getSubRendererById(rendererId); + + // 点击添加悬浮容器,则直接插入当前页面根节点 + const curElemStyle = subRenderer?.scaffold?.style || {}; + if (curElemStyle.position === 'fixed') { + curActiveId = store.getRootId(); + node = store.getNodeById(curActiveId)!; // 默认插入当前选中节点 + } } if (!subRenderer && !schemaData) { // 当渲染器信息和 schemaData 都为空时,则不作任何处理 return; } - - const id = store.activeId; - const node = store.getNodeById(id)!; // 当前选中节点 + if (!node) { toast.warning('请先选择一个元素作为插入的位置。'); return; } + const curElemSchema = schemaData || subRenderer?.scaffold; + const isSpecialLayout = this.isSpecialLayout(curElemSchema); if ( (node.type === 'wrapper' || node.type === 'container') && node.schema?.body?.length === 0 && - (schemaData?.type === 'flex' || subRenderer?.rendererName === 'flex') && - !node.schema?.isFreeContainer + curElemSchema?.type === 'flex' && + !node.schema?.isFreeContainer && + !isSpecialLayout ) { - const newSchemaData = schemaData || subRenderer?.scaffold; // 布局能力提升: 点击插入新元素,当wrapper为空插入布局容器时,自动改为置换,避免过多层级 - this.replaceChild(id, newSchemaData); + this.replaceChild(curActiveId, curElemSchema); return; } @@ -843,19 +852,19 @@ export class EditorManager { let regionNodeRegion = null; if (store.activeRegion) { - regionNodeId = id; + regionNodeId = curActiveId; regionNodeRegion = store.activeRegion; } else if (node.schema.columns && node.type !== 'grid') { // crud 和 table 等表格类容器 - regionNodeId = id; + regionNodeId = curActiveId; regionNodeRegion = 'columns'; } else if (node.schema.items && isLayoutPlugin(node.schema)) { // 当前节点是布局类容器节点 - regionNodeId = id; + regionNodeId = curActiveId; regionNodeRegion = 'items'; } else if (node.schema.body) { // 当前节点是容器节点 - regionNodeId = id; + regionNodeId = curActiveId; regionNodeRegion = 'body'; } else if (parentNode) { // 存在父节点 @@ -878,11 +887,11 @@ export class EditorManager { return; } - const parent = store.getSchemaParentById(id); // 获取父节点 + const parent = store.getSchemaParentById(curActiveId); // 获取父节点 let beforeId = -1; parent.some((item: any, index: number) => { let result = false; - if (item.$$id === id) { + if (item.$$id === curActiveId) { beforeId = index; result = true; } @@ -891,7 +900,7 @@ export class EditorManager { nextId = parent[beforeId + 1]?.$$id; // 下一个节点的ID(追加时需要) } else { // 当前选中的是根节点,默认插入到body中 - regionNodeId = id; + regionNodeId = curActiveId; regionNodeRegion = 'body'; } @@ -1086,6 +1095,18 @@ export class EditorManager { return this.store.isFlexColumnItem(id); } + // 判断是否为特殊布局元素:绝对布局 or 固定布局 + isSpecialLayout(curSchema: any) { + const curSchemaStyle = curSchema?.style || {}; + if ( + curSchemaStyle?.position === 'fixed' || + curSchemaStyle?.position === 'absolute' + ) { + return true; + } + return false; + } + /** * 判断当前元素是否为特殊布局元素(fixed、absolute) * 备注: 以便支持拖拽位置