From 6c0b92e80887f10c92ee9ecf450ebca4a0bc2fec Mon Sep 17 00:00:00 2001 From: i33 <78162524@qq.com> Date: Tue, 30 Aug 2022 12:45:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(editor):=20=E5=88=9B=E5=BB=BA=E6=96=B0?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=97=B6=E7=9A=84=E9=A1=BA=E5=BA=8F=20(#316)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(editor): 创建新组件时的顺序 点击面板组件创建新组件时,默认按照当所选组件(非容器)后面的顺序 * feat(editor): 追加vue2 runtime的修改 --- packages/editor/src/services/editor.ts | 9 +++++++-- runtime/vue2/playground/App.vue | 8 +++++++- runtime/vue3/playground/App.vue | 8 +++++++- 3 files changed, 21 insertions(+), 4 deletions(-) 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) {