From 443465eb8675f6a9676073f14a888e227bd96291 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Fri, 22 Sep 2023 08:57:00 +0800 Subject: [PATCH] =?UTF-8?q?Feat=EF=BC=9A=E5=B0=86=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E5=94=AF=E4=B8=80=E6=A0=87=E8=AF=86=E7=94=B1id=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E6=94=B9=E4=B8=BAuid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/core/render/node/Node.js | 2 +- .../src/plugins/AssociativeLine.js | 22 +++++++++---------- .../associativeLine/associativeLineText.js | 4 ++-- .../associativeLine/associativeLineUtils.js | 2 +- simple-mind-map/src/utils/index.js | 5 ++--- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/simple-mind-map/src/core/render/node/Node.js b/simple-mind-map/src/core/render/node/Node.js index 952812c0..d287755b 100644 --- a/simple-mind-map/src/core/render/node/Node.js +++ b/simple-mind-map/src/core/render/node/Node.js @@ -14,7 +14,7 @@ class Node { constructor(opt = {}) { // 节点数据 this.nodeData = this.handleData(opt.data || {}) - // id + // uid this.uid = opt.uid // 控制实例 this.mindMap = opt.mindMap diff --git a/simple-mind-map/src/plugins/AssociativeLine.js b/simple-mind-map/src/plugins/AssociativeLine.js index 0225d2ca..51fc51ee 100644 --- a/simple-mind-map/src/plugins/AssociativeLine.js +++ b/simple-mind-map/src/plugins/AssociativeLine.js @@ -149,8 +149,8 @@ class AssociativeLine { ) { nodeToIds.set(cur, data.associativeLineTargets) } - if (data.id) { - idToNode.set(data.id, cur) + if (data.uid) { + idToNode.set(data.uid, cur) } }, () => {}, @@ -158,8 +158,8 @@ class AssociativeLine { 0 ) nodeToIds.forEach((ids, node) => { - ids.forEach((id, index) => { - let toNode = idToNode.get(id) + ids.forEach((uid, index) => { + let toNode = idToNode.get(uid) if (!node || !toNode) return const associativeLinePoint = (node.nodeData.data.associativeLinePoint || [])[index] @@ -397,21 +397,21 @@ class AssociativeLine { addLine(fromNode, toNode) { if (!fromNode || !toNode) return // 目标节点如果没有id,则生成一个id - let id = toNode.nodeData.data.id - if (!id) { - id = uuid() + let uid = toNode.nodeData.data.uid + if (!uid) { + uid = uuid() this.mindMap.execCommand('SET_NODE_DATA', toNode, { - id + uid }) } // 将目标节点id保存起来 let list = fromNode.nodeData.data.associativeLineTargets || [] // 连线节点是否存在相同的id,存在则阻止添加关联线 - const sameLine = list.some(item => item === id) + const sameLine = list.some(item => item === uid) if (sameLine) { return } - list.push(id) + list.push(uid) // 保存控制点 let [startPoint, endPoint] = computeNodePoints(fromNode, toNode) let controlPoints = computeCubicBezierPathPoints( @@ -460,7 +460,7 @@ class AssociativeLine { let newAssociativeLineText = {} if (associativeLineText) { Object.keys(associativeLineText).forEach(item => { - if (item !== toNode.nodeData.data.id) { + if (item !== toNode.nodeData.data.uid) { newAssociativeLineText[item] = associativeLineText[item] } }) diff --git a/simple-mind-map/src/plugins/associativeLine/associativeLineText.js b/simple-mind-map/src/plugins/associativeLine/associativeLineText.js index 6d37a2c4..201077f0 100644 --- a/simple-mind-map/src/plugins/associativeLine/associativeLineText.js +++ b/simple-mind-map/src/plugins/associativeLine/associativeLineText.js @@ -111,7 +111,7 @@ function hideEditTextBox() { this.mindMap.execCommand('SET_NODE_DATA', node, { associativeLineText: { ...(node.nodeData.data.associativeLineText || {}), - [toNode.nodeData.data.id]: str + [toNode.nodeData.data.uid]: str } }) this.textEditNode.style.display = 'none' @@ -127,7 +127,7 @@ function getText(node, toNode) { if (!obj) { return '' } - return obj[toNode.nodeData.data.id] || '' + return obj[toNode.nodeData.data.uid] || '' } // 渲染关联线文字 diff --git a/simple-mind-map/src/plugins/associativeLine/associativeLineUtils.js b/simple-mind-map/src/plugins/associativeLine/associativeLineUtils.js index b68216e5..ca46b6f8 100644 --- a/simple-mind-map/src/plugins/associativeLine/associativeLineUtils.js +++ b/simple-mind-map/src/plugins/associativeLine/associativeLineUtils.js @@ -1,7 +1,7 @@ // 获取目标节点在起始节点的目标数组中的索引 export const getAssociativeLineTargetIndex = (node, toNode) => { return node.nodeData.data.associativeLineTargets.findIndex(item => { - return item === toNode.nodeData.data.id + return item === toNode.nodeData.data.uid }) } diff --git a/simple-mind-map/src/utils/index.js b/simple-mind-map/src/utils/index.js index 5d8c109c..c854eaaf 100644 --- a/simple-mind-map/src/utils/index.js +++ b/simple-mind-map/src/utils/index.js @@ -170,9 +170,8 @@ export const copyNodeTree = ( keepId = false ) => { tree.data = simpleDeepClone(root.nodeData ? root.nodeData.data : root.data) - // 去除节点id,因为节点id不能重复 - if (tree.data.id && !keepId) delete tree.data.id - if (tree.data.uid) delete tree.data.uid + // 去除节点uid,因为节点uid不能重复 + if (tree.data.uid && !keepId) delete tree.data.uid if (removeActiveState) { tree.data.isActive = false }