From 656cfa50c65d283f11a4d9863c06807505c2522f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Thu, 26 Dec 2024 19:19:16 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E5=A4=9A=E4=B8=AA=E8=8A=82=E7=82=B9=E7=84=B6=E5=90=8E?= =?UTF-8?q?=E8=BF=9E=E7=BB=AD=E7=B2=98=E8=B4=B4=E4=BC=9A=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E5=B8=83=E5=B1=80=E6=B7=B7=E4=B9=B1=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/core/render/Render.js | 22 +++++++++++++++++----- simple-mind-map/src/utils/index.js | 1 - 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/simple-mind-map/src/core/render/Render.js b/simple-mind-map/src/core/render/Render.js index b04384b7..43561942 100644 --- a/simple-mind-map/src/core/render/Render.js +++ b/simple-mind-map/src/core/render/Render.js @@ -748,10 +748,12 @@ class Render { // 动态指定的子节点数据也需要添加相关属性 appointChildren = addDataToAppointNodes(appointChildren, params) const alreadyIsRichText = appointData && appointData.richText + let createNewId = false list.forEach(node => { if (node.isGeneralization || node.isRoot) { return } + appointChildren = simpleDeepClone(appointChildren) const parent = node.parent const isOneLayer = node.layerIndex === 1 // 新插入节点的默认文本 @@ -772,8 +774,9 @@ class Render { uid: createUid(), ...(appointData || {}) }, - children: [...createUidForAppointNodes(appointChildren)] + children: [...createUidForAppointNodes(appointChildren, createNewId)] } + createNewId = true parent.nodeData.children.splice(index + 1, 0, newNodeData) }) // 如果同时对多个节点插入子节点,需要清除原来激活的节点 @@ -801,14 +804,17 @@ class Render { } if (isRichText) params.resetRichText = true nodeList = addDataToAppointNodes(nodeList, params) + let createNewId = false list.forEach(node => { if (node.isGeneralization || node.isRoot) { return } + nodeList = simpleDeepClone(nodeList) const parent = node.parent // 计算插入位置 const index = getNodeDataIndex(node) - const newNodeList = createUidForAppointNodes(simpleDeepClone(nodeList)) + const newNodeList = createUidForAppointNodes(nodeList, createNewId) + createNewId = true parent.nodeData.children.splice(index + 1, 0, ...newNodeList) }) if (focusNewNode) { @@ -849,10 +855,12 @@ class Render { // 动态指定的子节点数据也需要添加相关属性 appointChildren = addDataToAppointNodes(appointChildren, params) const alreadyIsRichText = appointData && appointData.richText + let createNewId = false list.forEach(node => { if (node.isGeneralization) { return } + appointChildren = simpleDeepClone(appointChildren) if (!node.nodeData.children) { node.nodeData.children = [] } @@ -871,8 +879,9 @@ class Render { ...params, ...(appointData || {}) }, - children: [...createUidForAppointNodes(appointChildren)] + children: [...createUidForAppointNodes(appointChildren, createNewId)] } + createNewId = true node.nodeData.children.push(newNode) // 插入子节点时自动展开子节点 node.setData({ @@ -904,14 +913,18 @@ class Render { } if (isRichText) params.resetRichText = true childList = addDataToAppointNodes(childList, params) + let createNewId = false list.forEach(node => { if (node.isGeneralization) { return } + childList = simpleDeepClone(childList) if (!node.nodeData.children) { node.nodeData.children = [] } - childList = createUidForAppointNodes(childList) + childList = createUidForAppointNodes(childList, createNewId) + // 第一个引用不需要重新创建uid,后面的需要重新创建,否则id会重复 + createNewId = true node.nodeData.children.push(...childList) // 插入子节点时自动展开子节点 node.setData({ @@ -1526,7 +1539,6 @@ class Render { // 粘贴节点到节点 pasteNode(data) { - data = simpleDeepClone(data) data = formatDataToArray(data) this.mindMap.execCommand('INSERT_MULTI_CHILD_NODE', [], data) } diff --git a/simple-mind-map/src/utils/index.js b/simple-mind-map/src/utils/index.js index 019b1955..0ed836c0 100644 --- a/simple-mind-map/src/utils/index.js +++ b/simple-mind-map/src/utils/index.js @@ -1006,7 +1006,6 @@ export const createUidForAppointNodes = ( createNewId = false, handle = null ) => { - console.log(appointNodes) const walk = list => { list.forEach(node => { if (!node.data) {