diff --git a/packages/editor/src/services/editor.ts b/packages/editor/src/services/editor.ts index 457511c3..7acbab17 100644 --- a/packages/editor/src/services/editor.ts +++ b/packages/editor/src/services/editor.ts @@ -297,8 +297,13 @@ class Editor extends BaseService { throw new Error('app下不能添加组件'); } - // 新增节点添加到配置中 - parent?.items?.push(node); + if (parent.id !== curNode.id) { + const index = parent.items.indexOf(curNode); + parent?.items?.splice(index + 1, 0, node); + } else { + // 新增节点添加到配置中 + parent?.items?.push(node); + } const layout = await this.getLayout(toRaw(parent), node as MNode); node.style = getInitPositionStyle(node.style, layout); diff --git a/runtime/vue2/playground/App.vue b/runtime/vue2/playground/App.vue index dc65380e..5653c6de 100644 --- a/runtime/vue2/playground/App.vue +++ b/runtime/vue2/playground/App.vue @@ -71,7 +71,13 @@ export default defineComponent({ if (!selectedId.value) throw new Error('error'); const parent = getNodePath(parentId, [root.value]).pop(); if (!parent) throw new Error('未找到父节点'); - parent.items?.push(config); + if (parent.id !== selectedId.value) { + const index = parent.items?.findIndex((child: MNode) => child.id === selectedId.value); + parent.items?.splice(index + 1, 0, config); + } else { + // 新增节点添加到配置中 + parent.items?.push(config); + } }, update({ config, parentId }: UpdateData) { diff --git a/runtime/vue3/playground/App.vue b/runtime/vue3/playground/App.vue index 0c7d6691..eb97f819 100644 --- a/runtime/vue3/playground/App.vue +++ b/runtime/vue3/playground/App.vue @@ -71,7 +71,13 @@ export default defineComponent({ if (!selectedId.value) throw new Error('error'); const parent = getNodePath(parentId, [root.value]).pop(); if (!parent) throw new Error('未找到父节点'); - parent.items?.push(config); + if (parent.id !== selectedId.value) { + const index = parent.items?.findIndex((child: MNode) => child.id === selectedId.value); + parent.items?.splice(index + 1, 0, config); + } else { + // 新增节点添加到配置中 + parent.items?.push(config); + } }, update({ config, parentId }: UpdateData) {