Fix:修复多次粘贴节点时由于节点uid重复造成的渲染异常问题
This commit is contained in:
parent
83a5ef8e2e
commit
2c6b8294f4
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "simple-mind-map",
|
"name": "simple-mind-map",
|
||||||
"version": "0.7.3",
|
"version": "0.7.3-fix.1",
|
||||||
"description": "一个简单的web在线思维导图",
|
"description": "一个简单的web在线思维导图",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
|||||||
@ -512,7 +512,7 @@ class Render {
|
|||||||
uid: createUid(),
|
uid: createUid(),
|
||||||
...(appointData || {})
|
...(appointData || {})
|
||||||
},
|
},
|
||||||
children: [...createUidForAppointNodes(appointChildren)]
|
children: [...createUidForAppointNodes(appointChildren, true)]
|
||||||
}
|
}
|
||||||
parent.nodeData.children.splice(index + 1, 0, newNodeData)
|
parent.nodeData.children.splice(index + 1, 0, newNodeData)
|
||||||
})
|
})
|
||||||
@ -558,7 +558,7 @@ class Render {
|
|||||||
const index = parent.nodeData.children.findIndex(item => {
|
const index = parent.nodeData.children.findIndex(item => {
|
||||||
return item.data.uid === node.uid
|
return item.data.uid === node.uid
|
||||||
})
|
})
|
||||||
const newNodeList = createUidForAppointNodes(simpleDeepClone(nodeList))
|
const newNodeList = createUidForAppointNodes(simpleDeepClone(nodeList), true)
|
||||||
parent.nodeData.children.splice(
|
parent.nodeData.children.splice(
|
||||||
index + 1,
|
index + 1,
|
||||||
0,
|
0,
|
||||||
@ -619,7 +619,7 @@ class Render {
|
|||||||
...params,
|
...params,
|
||||||
...(appointData || {})
|
...(appointData || {})
|
||||||
},
|
},
|
||||||
children: [...createUidForAppointNodes(appointChildren)]
|
children: [...createUidForAppointNodes(appointChildren, true)]
|
||||||
}
|
}
|
||||||
node.nodeData.children.push(newNode)
|
node.nodeData.children.push(newNode)
|
||||||
// 插入子节点时自动展开子节点
|
// 插入子节点时自动展开子节点
|
||||||
@ -659,7 +659,7 @@ class Render {
|
|||||||
if (!node.nodeData.children) {
|
if (!node.nodeData.children) {
|
||||||
node.nodeData.children = []
|
node.nodeData.children = []
|
||||||
}
|
}
|
||||||
childList = createUidForAppointNodes(childList)
|
childList = createUidForAppointNodes(childList, true)
|
||||||
node.nodeData.children.push(...childList)
|
node.nodeData.children.push(...childList)
|
||||||
// 插入子节点时自动展开子节点
|
// 插入子节点时自动展开子节点
|
||||||
node.nodeData.data.expand = true
|
node.nodeData.data.expand = true
|
||||||
@ -1071,7 +1071,9 @@ class Render {
|
|||||||
this.activeNodeList.forEach(node => {
|
this.activeNodeList.forEach(node => {
|
||||||
node.nodeData.children.push(
|
node.nodeData.children.push(
|
||||||
...data.map(item => {
|
...data.map(item => {
|
||||||
return simpleDeepClone(item)
|
const newData = simpleDeepClone(item)
|
||||||
|
createUidForAppointNodes([newData], true)
|
||||||
|
return newData
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@ -167,11 +167,13 @@ export const copyNodeTree = (
|
|||||||
tree,
|
tree,
|
||||||
root,
|
root,
|
||||||
removeActiveState = false,
|
removeActiveState = false,
|
||||||
keepId = false
|
removeId = true
|
||||||
) => {
|
) => {
|
||||||
tree.data = simpleDeepClone(root.nodeData ? root.nodeData.data : root.data)
|
tree.data = simpleDeepClone(root.nodeData ? root.nodeData.data : root.data)
|
||||||
// 重新创建节点uid,因为节点uid不能重复
|
// 移除节点uid
|
||||||
if (!keepId) {
|
if (removeId) {
|
||||||
|
delete tree.data.uid
|
||||||
|
} else if (!tree.data.uid) {// 否则保留或生成
|
||||||
tree.data.uid = createUid()
|
tree.data.uid = createUid()
|
||||||
}
|
}
|
||||||
if (removeActiveState) {
|
if (removeActiveState) {
|
||||||
@ -180,7 +182,7 @@ export const copyNodeTree = (
|
|||||||
tree.children = []
|
tree.children = []
|
||||||
if (root.children && root.children.length > 0) {
|
if (root.children && root.children.length > 0) {
|
||||||
root.children.forEach((item, index) => {
|
root.children.forEach((item, index) => {
|
||||||
tree.children[index] = copyNodeTree({}, item, removeActiveState, keepId)
|
tree.children[index] = copyNodeTree({}, item, removeActiveState, removeId)
|
||||||
})
|
})
|
||||||
} else if (
|
} else if (
|
||||||
root.nodeData &&
|
root.nodeData &&
|
||||||
@ -188,7 +190,7 @@ export const copyNodeTree = (
|
|||||||
root.nodeData.children.length > 0
|
root.nodeData.children.length > 0
|
||||||
) {
|
) {
|
||||||
root.nodeData.children.forEach((item, index) => {
|
root.nodeData.children.forEach((item, index) => {
|
||||||
tree.children[index] = copyNodeTree({}, item, removeActiveState, keepId)
|
tree.children[index] = copyNodeTree({}, item, removeActiveState, removeId)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return tree
|
return tree
|
||||||
@ -766,14 +768,15 @@ export const addDataToAppointNodes = (appointNodes, data = {}) => {
|
|||||||
return appointNodes
|
return appointNodes
|
||||||
}
|
}
|
||||||
|
|
||||||
// 给指定的节点列表树数据添加uid,如果不存在的话,会修改原数据
|
// 给指定的节点列表树数据添加uid,会修改原数据
|
||||||
export const createUidForAppointNodes = appointNodes => {
|
// createNewId默认为false,即如果节点不存在uid的话,会创建新的uid。如果传true,那么无论节点数据原来是否存在uid,都会创建新的uid
|
||||||
|
export const createUidForAppointNodes = (appointNodes, createNewId = false) => {
|
||||||
const walk = list => {
|
const walk = list => {
|
||||||
list.forEach(node => {
|
list.forEach(node => {
|
||||||
if (!node.data) {
|
if (!node.data) {
|
||||||
node.data = {}
|
node.data = {}
|
||||||
}
|
}
|
||||||
if (isUndef(node.data.uid)) {
|
if (createNewId || isUndef(node.data.uid)) {
|
||||||
node.data.uid = createUid()
|
node.data.uid = createUid()
|
||||||
}
|
}
|
||||||
if (node.children && node.children.length > 0) {
|
if (node.children && node.children.length > 0) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user