Feat:创建节点、复制节点时给新节点数据创建uid

This commit is contained in:
wanglin2 2023-09-27 13:38:15 +08:00
parent a4f6006efd
commit 8c3d66eb3c
2 changed files with 19 additions and 10 deletions

View File

@ -18,7 +18,8 @@ import {
addDataToAppointNodes,
createUidForAppointNodes,
formatDataToArray,
getNodeIndex
getNodeIndex,
createUid
} from '../../utils'
import { shapeList } from './node/Shape'
import { lineStyleProps } from '../../themes/default'
@ -494,15 +495,17 @@ class Render {
const index = parent.nodeData.children.findIndex(item => {
return item.data.uid === node.uid
})
parent.nodeData.children.splice(index + 1, 0, {
const newNodeData = {
inserting: handleMultiNodes ? false : openEdit, // 如果同时对多个节点插入子节点,那么无需进入编辑模式,
data: {
text: text,
...params,
uid: createUid(),
...(appointData || {})
},
children: [...appointChildren]
})
children: [...createUidForAppointNodes(appointChildren)]
}
parent.nodeData.children.splice(index + 1, 0, newNodeData)
})
Object.keys(needDestroyNodeList).forEach(key => {
needDestroyNodeList[key].destroy()
@ -546,10 +549,11 @@ class Render {
const index = parent.nodeData.children.findIndex(item => {
return item.data.uid === node.uid
})
const newNodeList = createUidForAppointNodes(simpleDeepClone(nodeList))
parent.nodeData.children.splice(
index + 1,
0,
...createUidForAppointNodes(simpleDeepClone(nodeList))
...newNodeList
)
})
Object.keys(needDestroyNodeList).forEach(key => {
@ -598,15 +602,17 @@ class Render {
const text = node.isRoot
? defaultInsertSecondLevelNodeText
: defaultInsertBelowSecondLevelNodeText
node.nodeData.children.push({
const newNode = {
inserting: handleMultiNodes ? false : openEdit, // 如果同时对多个节点插入子节点,那么无需进入编辑模式
data: {
text: text,
uid: createUid(),
...params,
...(appointData || {})
},
children: [...appointChildren]
})
children: [...createUidForAppointNodes(appointChildren)]
}
node.nodeData.children.push(newNode)
// 插入子节点时自动展开子节点
node.nodeData.data.expand = true
if (node.isRoot) {
@ -644,6 +650,7 @@ class Render {
if (!node.nodeData.children) {
node.nodeData.children = []
}
childList = createUidForAppointNodes(childList)
node.nodeData.children.push(...childList)
// 插入子节点时自动展开子节点
node.nodeData.data.expand = true

View File

@ -170,8 +170,10 @@ export const copyNodeTree = (
keepId = false
) => {
tree.data = simpleDeepClone(root.nodeData ? root.nodeData.data : root.data)
// 去除节点uid因为节点uid不能重复
if (tree.data.uid && !keepId) delete tree.data.uid
// 重新创建节点uid因为节点uid不能重复
if (!keepId) {
tree.data.uid = createUid()
}
if (removeActiveState) {
tree.data.isActive = false
}