From a9d794dc19f80d760459c8cf6b4636f48016c258 Mon Sep 17 00:00:00 2001 From: roymondchen Date: Mon, 11 Dec 2023 20:19:17 +0800 Subject: [PATCH] =?UTF-8?q?feat(editor):=20propsService.setNewItemId?= =?UTF-8?q?=E6=96=B0=E5=A2=9Eforce=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/editor/src/services/props.ts | 7 ++++--- packages/editor/src/utils/operator.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/editor/src/services/props.ts b/packages/editor/src/services/props.ts index 8d4ede08..627c2ce7 100644 --- a/packages/editor/src/services/props.ts +++ b/packages/editor/src/services/props.ts @@ -139,12 +139,13 @@ class Props extends BaseService { /** * 将组件与组件的子元素配置中的id都设置成一个新的ID - * 如果没有相同ID则保持不变 + * 如果没有相同ID并且force为false则保持不变 * @param {Object} config 组件配置 + * @param {Boolean} force 是否强制设置新的ID */ /* eslint no-param-reassign: ["error", { "props": false }] */ - public async setNewItemId(config: MNode) { - if (editorService.getNodeById(config.id)) { + public async setNewItemId(config: MNode, force = true) { + if (force || editorService.getNodeById(config.id)) { const newId = await this.createId(config.type || 'component'); this.setRelateId(config.id, newId); config.id = newId; diff --git a/packages/editor/src/utils/operator.ts b/packages/editor/src/utils/operator.ts index d255f79e..d73d9636 100644 --- a/packages/editor/src/utils/operator.ts +++ b/packages/editor/src/utils/operator.ts @@ -40,7 +40,7 @@ export const beforePaste = async (position: PastePosition, config: MNode[]): Pro if (pastePosition.top && configItem.style?.top) { pastePosition.top = configItem.style?.top - referenceTop + pastePosition.top; } - const pasteConfig = await propsService.setNewItemId(configItem); + const pasteConfig = await propsService.setNewItemId(configItem, false); if (pasteConfig.style) { const { left, top } = pasteConfig.style;