From 1a66dbebd8f1bc80ad631b609d32e813d5293fc8 Mon Sep 17 00:00:00 2001 From: wibetter <365533093@qq.com> Date: Thu, 30 Jun 2022 11:23:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=86=E8=8A=82=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Iadfd13ad374b01345b6a8c1427517981bc979937 --- packages/amis-editor-core/src/manager.ts | 19 ++++++++++++------- packages/amis-editor-core/src/util.ts | 11 +++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/packages/amis-editor-core/src/manager.ts b/packages/amis-editor-core/src/manager.ts index d7cf96df0..5436ab34b 100644 --- a/packages/amis-editor-core/src/manager.ts +++ b/packages/amis-editor-core/src/manager.ts @@ -44,7 +44,8 @@ import { reactionWithOldValue, reGenerateID, isString, - isObject + isObject, + isLayoutPlugin } from './util'; import {reaction} from 'mobx'; import {hackIn, makeSchemaFormRender, makeWrapper} from './component/factory'; @@ -748,7 +749,7 @@ export class EditorManager { toast.warning('请先选择一个元素作为插入的位置。'); return; } - const regionNode = node.parent as EditorNodeType; // 父级节点 + const parentNode = node.parent as EditorNodeType; // 父级节点 // 插入新元素需要的字段 let nextId = null; @@ -766,16 +767,20 @@ export class EditorManager { // 当前节点是容器节点 regionNodeId = id; regionNodeRegion = 'body'; - } else if (regionNode) { + } else if (node.schema.items && isLayoutPlugin(node.schema)) { + // 当前节点是布局类容器节点 + regionNodeId = id; + regionNodeRegion = 'items'; + } else if (parentNode) { // 存在父节点 - regionNodeId = regionNode.id; - regionNodeRegion = regionNode.region; + regionNodeId = parentNode.id; + regionNodeRegion = parentNode.region; // 考虑特殊情况,比如「表单项容器」 - if (!regionNode.region && regionNode.schema.body) { + if (!parentNode.region && parentNode.schema.body) { // 默认插入到父节点的body中 regionNodeRegion = 'body'; - } else if (!regionNode.region && !regionNode.schema.body) { + } else if (!parentNode.region && !parentNode.schema.body) { // 其他特殊情况暂时不考虑,给予提示 toast.warning('当前节点不允许追加新组件。'); return; diff --git a/packages/amis-editor-core/src/util.ts b/packages/amis-editor-core/src/util.ts index 677d7c9eb..fcdf69787 100644 --- a/packages/amis-editor-core/src/util.ts +++ b/packages/amis-editor-core/src/util.ts @@ -875,3 +875,14 @@ export function jsonToJsonSchema(json: any = {}) { export function isHasPluginIcon(plugin: any) { return plugin.pluginIcon && hasIcon(plugin.pluginIcon); } + +/** + * 判断是否是布局容器类组件 + * 备注:当前只有一个flex布局容器 + */ +export function isLayoutPlugin(plugin: any) { + if (plugin && plugin.type === 'flex') { + return true; + } + return false; +} \ No newline at end of file