From 96fe876e331d91f36989e9660b86f72b223dc5a4 Mon Sep 17 00:00:00 2001 From: rainke Date: Fri, 13 Oct 2023 16:57:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=8D=E5=88=B6=E6=97=B6=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=20ref=20=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/designer/src/component-actions.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/designer/src/component-actions.ts b/packages/designer/src/component-actions.ts index 76ead7d9a..57ad30bf2 100644 --- a/packages/designer/src/component-actions.ts +++ b/packages/designer/src/component-actions.ts @@ -10,6 +10,14 @@ import { } from './icons'; import { componentDefaults, legacyIssues } from './transducers'; +function deduplicateRef(node: IPublicModelNode | null | undefined) { + const currentRef = node?.getPropValue('ref'); + if (currentRef) { + node?.setPropValue('ref', `${node.componentName.toLowerCase()}-${Math.random().toString(36).slice(2, 9)}`); + } + node?.children?.forEach(deduplicateRef); +} + export class ComponentActions { private metadataTransducers: IPublicTypeMetadataTransducer[] = []; @@ -53,6 +61,7 @@ export class ComponentActions { const { document: doc, parent, index } = node; if (parent) { const newNode = doc?.insertNode(parent, node, (index ?? 0) + 1, true); + deduplicateRef(newNode); newNode?.select(); const { isRGL, rglNode } = node?.getRGL(); if (isRGL) {