优化代码:使用getNodeDataIndex工具函数去除render类重复逻辑

This commit is contained in:
wanglin2 2023-10-13 13:57:07 +08:00
parent 0a36555343
commit c17e5430ed

View File

@ -520,9 +520,7 @@ class Render {
? defaultInsertSecondLevelNodeText
: defaultInsertBelowSecondLevelNodeText
// 计算插入位置
const index = parent.nodeData.children.findIndex(item => {
return item.data.uid === node.uid
})
const index = getNodeDataIndex(node)
const newNodeData = {
inserting: handleMultiNodes ? false : openEdit, // 如果同时对多个节点插入子节点,那么无需进入编辑模式,
data: {
@ -565,9 +563,7 @@ class Render {
}
const parent = node.parent
// 计算插入位置
const index = parent.nodeData.children.findIndex(item => {
return item.data.uid === node.uid
})
const index = getNodeDataIndex(node)
const newNodeList = createUidForAppointNodes(
simpleDeepClone(nodeList),
true
@ -711,9 +707,7 @@ class Render {
}
const parent = node.parent
// 获取当前节点所在位置
const index = parent.nodeData.children.findIndex(item => {
return item.data.uid === node.uid
})
const index = getNodeDataIndex(node)
parent.nodeData.children.splice(index, 1, newNode)
})
// 如果同时对多个节点插入子节点,需要清除原来激活的节点