Feat:将节点唯一标识由id全部改为uid

This commit is contained in:
wanglin2 2023-09-22 08:57:00 +08:00
parent 7a2605fdad
commit 443465eb86
5 changed files with 17 additions and 18 deletions

View File

@ -14,7 +14,7 @@ class Node {
constructor(opt = {}) {
// 节点数据
this.nodeData = this.handleData(opt.data || {})
// id
// uid
this.uid = opt.uid
// 控制实例
this.mindMap = opt.mindMap

View File

@ -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]
}
})

View File

@ -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] || ''
}
// 渲染关联线文字

View File

@ -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
})
}

View File

@ -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
}