|
|
@@ -173,7 +173,7 @@ export class Tree<T = any> {
|
|
|
return null;
|
|
|
}
|
|
|
const nodes = this.parentMap[node.parentID];
|
|
|
- const nodeIndex = nodes.indexOf(node);
|
|
|
+ const nodeIndex = nodes.findIndex(item => item.ID === node.ID);
|
|
|
if (nodeIndex < 0) {
|
|
|
return null;
|
|
|
}
|
|
|
@@ -187,7 +187,7 @@ export class Tree<T = any> {
|
|
|
return null;
|
|
|
}
|
|
|
const nodes = this.parentMap[node.parentID];
|
|
|
- const nodeIndex = nodes.indexOf(node);
|
|
|
+ const nodeIndex = nodes.findIndex(item => item.ID === node.ID);
|
|
|
if (nodeIndex < 0) {
|
|
|
return null;
|
|
|
}
|
|
|
@@ -339,12 +339,14 @@ export class Tree<T = any> {
|
|
|
delete this.parentMap[node.ID];
|
|
|
const nodesInParentMap = this.parentMap[node.parentID];
|
|
|
if (nodesInParentMap && nodesInParentMap.length) {
|
|
|
- const nIndex = nodesInParentMap.indexOf(node);
|
|
|
+ const nIndex = nodesInParentMap.findIndex(
|
|
|
+ item => item.ID === node.ID
|
|
|
+ );
|
|
|
if (nIndex >= 0) {
|
|
|
toDels.push({ nodes: nodesInParentMap, delNode: node });
|
|
|
}
|
|
|
}
|
|
|
- const index = this.rawData.indexOf(node);
|
|
|
+ const index = this.rawData.findIndex(item => item.ID === node.ID);
|
|
|
if (index >= 0) {
|
|
|
this.rawData.splice(index, 1);
|
|
|
}
|
|
|
@@ -354,7 +356,9 @@ export class Tree<T = any> {
|
|
|
});
|
|
|
// 删除parentMap的数据
|
|
|
toDels.forEach(delItem => {
|
|
|
- const delIndex = delItem.nodes.indexOf(delItem.delNode);
|
|
|
+ const delIndex = delItem.nodes.findIndex(
|
|
|
+ item => item.ID === delItem.delNode.ID
|
|
|
+ );
|
|
|
if (delIndex >= 0) {
|
|
|
delItem.nodes.splice(delIndex, 1);
|
|
|
}
|
|
|
@@ -467,10 +471,10 @@ export class Tree<T = any> {
|
|
|
});
|
|
|
});
|
|
|
const parentNextBrothers = parent.getCtx().nextBrothers();
|
|
|
- // 因为seq可能是不连号的,如果上移的最末节点seq,小于下一节点的seq,那就不更新所有下兄弟节点的seq,减少更新的数据量
|
|
|
+ // 因为seq可能是不连号的,如果升级块的最末节点seq,小于下一节点的seq,那就不更新所有下兄弟节点的seq,减少更新的数据量
|
|
|
const lastNodeCurSeq = updateData[updateData.length - 1].update.seq;
|
|
|
- const firstBrohter = parentNextBrothers[0];
|
|
|
- if (lastNodeCurSeq && lastNodeCurSeq >= firstBrohter.seq) {
|
|
|
+ const firstBrother = parentNextBrothers[0];
|
|
|
+ if (lastNodeCurSeq && firstBrother && lastNodeCurSeq >= firstBrother.seq) {
|
|
|
parentNextBrothers.forEach((node, index) => {
|
|
|
updateData.push({
|
|
|
ID: node.ID,
|
|
|
@@ -500,10 +504,8 @@ export class Tree<T = any> {
|
|
|
const orgParentID = firstNode.parentID;
|
|
|
const orgBrothers = this.parentMap[orgParentID];
|
|
|
const lastNodeNextBrothers = lastNode.getCtx().nextBrothers();
|
|
|
- orgBrothers.splice(
|
|
|
- orgBrothers.indexOf(firstNode),
|
|
|
- nodes.length + lastNodeNextBrothers.length
|
|
|
- );
|
|
|
+ const index = orgBrothers.findIndex(item => item.ID === firstNode.ID);
|
|
|
+ orgBrothers.splice(index, nodes.length + lastNodeNextBrothers.length);
|
|
|
(this.parentMap[lastNode.ID] || (this.parentMap[lastNode.ID] = [])).push(
|
|
|
...lastNodeNextBrothers
|
|
|
);
|
|
|
@@ -545,7 +547,8 @@ export class Tree<T = any> {
|
|
|
return;
|
|
|
}
|
|
|
const orgBrothers = this.parentMap[firstNode.parentID];
|
|
|
- orgBrothers.splice(orgBrothers.indexOf(firstNode), nodes.length);
|
|
|
+ const index = orgBrothers.findIndex(item => item.ID === firstNode.ID);
|
|
|
+ orgBrothers.splice(index, nodes.length);
|
|
|
(this.parentMap[prevNode.ID] || (this.parentMap[prevNode.ID] = [])).push(
|
|
|
...nodes
|
|
|
);
|
|
|
@@ -606,7 +609,8 @@ export class Tree<T = any> {
|
|
|
const newParentID = parent ? parent.ID : this.rootID;
|
|
|
const orgParentID = firstNode.parentID;
|
|
|
const orgBrothers = this.parentMap[orgParentID];
|
|
|
- orgBrothers.splice(orgBrothers.indexOf(firstNode), nodes.length);
|
|
|
+ const index = orgBrothers.findIndex(item => item.ID === firstNode.ID);
|
|
|
+ orgBrothers.splice(index, nodes.length);
|
|
|
(this.parentMap[newParentID] || (this.parentMap[newParentID] = [])).push(
|
|
|
...nodes
|
|
|
);
|