Feat:创建节点、复制节点时给新节点数据创建uid
This commit is contained in:
parent
a4f6006efd
commit
8c3d66eb3c
@ -18,7 +18,8 @@ import {
|
|||||||
addDataToAppointNodes,
|
addDataToAppointNodes,
|
||||||
createUidForAppointNodes,
|
createUidForAppointNodes,
|
||||||
formatDataToArray,
|
formatDataToArray,
|
||||||
getNodeIndex
|
getNodeIndex,
|
||||||
|
createUid
|
||||||
} from '../../utils'
|
} from '../../utils'
|
||||||
import { shapeList } from './node/Shape'
|
import { shapeList } from './node/Shape'
|
||||||
import { lineStyleProps } from '../../themes/default'
|
import { lineStyleProps } from '../../themes/default'
|
||||||
@ -494,15 +495,17 @@ 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
|
||||||
})
|
})
|
||||||
parent.nodeData.children.splice(index + 1, 0, {
|
const newNodeData = {
|
||||||
inserting: handleMultiNodes ? false : openEdit, // 如果同时对多个节点插入子节点,那么无需进入编辑模式,
|
inserting: handleMultiNodes ? false : openEdit, // 如果同时对多个节点插入子节点,那么无需进入编辑模式,
|
||||||
data: {
|
data: {
|
||||||
text: text,
|
text: text,
|
||||||
...params,
|
...params,
|
||||||
|
uid: createUid(),
|
||||||
...(appointData || {})
|
...(appointData || {})
|
||||||
},
|
},
|
||||||
children: [...appointChildren]
|
children: [...createUidForAppointNodes(appointChildren)]
|
||||||
})
|
}
|
||||||
|
parent.nodeData.children.splice(index + 1, 0, newNodeData)
|
||||||
})
|
})
|
||||||
Object.keys(needDestroyNodeList).forEach(key => {
|
Object.keys(needDestroyNodeList).forEach(key => {
|
||||||
needDestroyNodeList[key].destroy()
|
needDestroyNodeList[key].destroy()
|
||||||
@ -546,10 +549,11 @@ 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))
|
||||||
parent.nodeData.children.splice(
|
parent.nodeData.children.splice(
|
||||||
index + 1,
|
index + 1,
|
||||||
0,
|
0,
|
||||||
...createUidForAppointNodes(simpleDeepClone(nodeList))
|
...newNodeList
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
Object.keys(needDestroyNodeList).forEach(key => {
|
Object.keys(needDestroyNodeList).forEach(key => {
|
||||||
@ -598,15 +602,17 @@ class Render {
|
|||||||
const text = node.isRoot
|
const text = node.isRoot
|
||||||
? defaultInsertSecondLevelNodeText
|
? defaultInsertSecondLevelNodeText
|
||||||
: defaultInsertBelowSecondLevelNodeText
|
: defaultInsertBelowSecondLevelNodeText
|
||||||
node.nodeData.children.push({
|
const newNode = {
|
||||||
inserting: handleMultiNodes ? false : openEdit, // 如果同时对多个节点插入子节点,那么无需进入编辑模式
|
inserting: handleMultiNodes ? false : openEdit, // 如果同时对多个节点插入子节点,那么无需进入编辑模式
|
||||||
data: {
|
data: {
|
||||||
text: text,
|
text: text,
|
||||||
|
uid: createUid(),
|
||||||
...params,
|
...params,
|
||||||
...(appointData || {})
|
...(appointData || {})
|
||||||
},
|
},
|
||||||
children: [...appointChildren]
|
children: [...createUidForAppointNodes(appointChildren)]
|
||||||
})
|
}
|
||||||
|
node.nodeData.children.push(newNode)
|
||||||
// 插入子节点时自动展开子节点
|
// 插入子节点时自动展开子节点
|
||||||
node.nodeData.data.expand = true
|
node.nodeData.data.expand = true
|
||||||
if (node.isRoot) {
|
if (node.isRoot) {
|
||||||
@ -644,6 +650,7 @@ class Render {
|
|||||||
if (!node.nodeData.children) {
|
if (!node.nodeData.children) {
|
||||||
node.nodeData.children = []
|
node.nodeData.children = []
|
||||||
}
|
}
|
||||||
|
childList = createUidForAppointNodes(childList)
|
||||||
node.nodeData.children.push(...childList)
|
node.nodeData.children.push(...childList)
|
||||||
// 插入子节点时自动展开子节点
|
// 插入子节点时自动展开子节点
|
||||||
node.nodeData.data.expand = true
|
node.nodeData.data.expand = true
|
||||||
|
|||||||
@ -170,8 +170,10 @@ export const copyNodeTree = (
|
|||||||
keepId = false
|
keepId = false
|
||||||
) => {
|
) => {
|
||||||
tree.data = simpleDeepClone(root.nodeData ? root.nodeData.data : root.data)
|
tree.data = simpleDeepClone(root.nodeData ? root.nodeData.data : root.data)
|
||||||
// 去除节点uid,因为节点uid不能重复
|
// 重新创建节点uid,因为节点uid不能重复
|
||||||
if (tree.data.uid && !keepId) delete tree.data.uid
|
if (!keepId) {
|
||||||
|
tree.data.uid = createUid()
|
||||||
|
}
|
||||||
if (removeActiveState) {
|
if (removeActiveState) {
|
||||||
tree.data.isActive = false
|
tree.data.isActive = false
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user