diff --git a/advanced_ui_component/treeview/interfaces/treeview.js b/advanced_ui_component/treeview/interfaces/treeview.js index 6746a8fd2ae..e6e88b48ba8 100644 --- a/advanced_ui_component/treeview/interfaces/treeview.js +++ b/advanced_ui_component/treeview/interfaces/treeview.js @@ -1154,8 +1154,9 @@ export class TreeView extends ViewPU { }); this.listNodeDataSource.w7[this.viewLastIndex].fontColor = this.treeViewTheme.a4; this.listNodeDataSource.w7[this.viewLastIndex].r6(false); - this.listNodeDataSource.w7[this.viewLastIndex].j4 = this.listNodeDataSource.w7[this.viewLastIndex].k6() - .v3?.source; + this.listNodeDataSource.w7[this.viewLastIndex].j4 = + this.listNodeDataSource.w7[this.viewLastIndex].k6() + .v3?.source; } setImageSources(index, f17) { @@ -2054,105 +2055,6 @@ class h3 extends g3 { this.d13(this.w7, 0, 1); } - h13(b13, c13) { - let d13 = []; - if (b13.length === 0) { - return; - } - let startIndex = undefined; - for (let g13 = 0; g13 < b13.length; g13++) { - if (this.b11.has(b13[g13])) { - let i13 = this.b11.get(b13[g13]); - d13.push(i13); - } - if (startIndex === undefined && this.c11.has(b13[g13])) { - startIndex = this.c11.get(b13[g13]); - } - if (startIndex !== undefined) { - let h13 = this.w7.splice(startIndex, 1); - h13 = null; - } - if (this.a11.has(b13[g13])) { - this.a11.delete(b13[g13]); - } - } - d13.forEach((value) => { - this.p10(value); - this.g9(value); - }); - if (c13.k6().x3 === null) { - if (this.c11.has(c13.e6())) { - let f13 = this.c11.get(c13.e6()); - this.w7[f13]?.z5(false); - } - this.a11.delete(c13.e6()); - this.g9(this.b11.get(c13.e6())); - } - let callbackParam = { - currentNodeId: c13.e6(), - parentNodeId: c13.f6(), - }; - this.v12(); - this.appEventBus.emit(TreeListenType.NODE_DELETE, callbackParam); - } - - i13(y12) { - let z12 = new f3(new j3(d3), d3); - if (this.v10.has(y12[0])) { - let node = this.v10.get(y12[0]); - z12 = new f3(node, this.w10.get(y12[0])); - z12.m5(node.o6().a13); - } - z12.h7(true); - let index = 0; - for (let a13 = 0; a13 < this.w7.length; a13++) { - if (this.w7[a13].e6() === z12.f6()) { - index = a13; - if (this.w7[a13].k6().x3 === null) { - this.w7[a13].z5(true); - this.g9(index); - } else if (this.a11.get(this.w7[a13].e6()) === z2.COLLAPSE) { - this.w12(index); - } - this.w7.splice(a13 + 1, 0, z12); - this.w7[a13 + 1].y5(true); - this.w7[a13 + 1].i6(true); - this.w7[a13 + 1].c6(i1); - this.c11.set(y12[0], a13 + 1); - this.i8(a13 + 1, a3.EDIT); - this.j13 = t2.ADD_NODE; - this.o10(a13 + 1); - this.k13(a13 + 1, this.j13); - break; - } - } - this.y10 = index + 1; - this.h9(index); - this.lastIndex = index; - this.a11.set(z12.f6(), z2.EXPAND); - this.z12(index, true); - } - - g10(operation, parentNodeId, v12) { - let w12 = new f3(new j3(d3), d3); - if (this.v10.has(parentNodeId)) { - let x12 = this.v10.get(parentNodeId); - w12 = new f3(x12, this.w10.get(parentNodeId)); - w12.m5(x12.o6().a13); - } - if (operation === t2.REMOVE_NODE) { - this.x11.set(parentNodeId, this.z11); - this.g9(this.b11.get(parentNodeId)); - this.h13(v12, w12); - } - if (operation === t2.ADD_NODE) { - this.d12 = v12[0]; - this.x11.set(this.c10(), this.z11); - this.x11.set(v12[0], this.a12); - this.i13(v12); - } - } - h9(index) { this.x10 = index; } @@ -3135,6 +3037,137 @@ class h3 extends g3 { return current.parentNodeId; } + h13(b13, c13) { + let d13 = []; + if (b13.length === 0) { + return; + } + let startIndex = undefined; + for (let g13 = 0; g13 < b13.length; g13++) { + if (this.b11.has(b13[g13])) { + let i13 = this.b11.get(b13[g13]); + d13.push(i13); + } + if (startIndex === undefined && this.c11.has(b13[g13])) { + startIndex = this.c11.get(b13[g13]); + } + if (startIndex !== undefined) { + let h13 = this.w7.splice(startIndex, 1); + h13 = null; + } + if (this.a11.has(b13[g13])) { + this.a11.delete(b13[g13]); + } + } + d13.forEach((value) => { + this.p10(value); + this.g9(value); + }); + if (c13.k6().x3 === null) { + if (this.c11.has(c13.e6())) { + let f13 = this.c11.get(c13.e6()); + this.w7[f13]?.z5(false); + } + this.a11.delete(c13.e6()); + this.g9(this.b11.get(c13.e6())); + } + let callbackParam = { + currentNodeId: c13.e6(), + parentNodeId: c13.f6(), + }; + this.v12(); + this.appEventBus.emit(TreeListenType.NODE_DELETE, callbackParam); + } + + i13(y12) { + let z12 = new f3(new j3(d3), d3); + if (this.v10.has(y12[0])) { + let node = this.v10.get(y12[0]); + z12 = new f3(node, this.w10.get(y12[0])); + z12.m5(node.o6().a13); + } + z12.h7(true); + let index = 0; + for (let a13 = 0; a13 < this.w7.length; a13++) { + if (this.w7[a13].e6() === z12.f6()) { + index = a13; + if (this.w7[a13].k6().x3 === null) { + this.w7[a13].z5(true); + this.g9(index); + } else if (this.a11.get(this.w7[a13].e6()) === z2.COLLAPSE) { + this.w12(index); + } + this.w7.splice(a13 + 1, 0, z12); + this.w7[a13 + 1].y5(true); + this.w7[a13 + 1].i6(true); + this.w7[a13 + 1].c6(i1); + this.c11.set(y12[0], a13 + 1); + this.i8(a13 + 1, a3.EDIT); + this.j13 = t2.ADD_NODE; + this.o10(a13 + 1); + this.k13(a13 + 1, this.j13); + break; + } + } + this.y10 = index + 1; + this.h9(index); + this.lastIndex = index; + this.a11.set(z12.f6(), z2.EXPAND); + this.z12(index, true); + } + + g10(operation, parentNodeId, v12) { + let w12 = new f3(new j3(d3), d3); + if (this.v10.has(parentNodeId)) { + let x12 = this.v10.get(parentNodeId); + w12 = new f3(x12, this.w10.get(parentNodeId)); + w12.m5(x12.o6().a13); + } + if (operation === t2.REMOVE_NODE) { + this.x11.set(parentNodeId, this.z11); + this.g9(this.b11.get(parentNodeId)); + this.h13(v12, w12); + } + if (operation === t2.ADD_NODE) { + this.d12 = v12[0]; + this.x11.set(this.c10(), this.z11); + this.x11.set(v12[0], this.a12); + this.i13(v12); + } + } + + removeNode(currentNodeId, parentNodeId) { + if (this.v10.has(parentNodeId) && this.v10.has(currentNodeId)) { + let parent = this.v10.get(parentNodeId); + let current = this.v10.get(currentNodeId); + let f8 = []; + let index = current.y14; + let g8 = 0; + if (index < 0) { + hilog.error(j16, i16, 'node does not exist.'); + return []; + } else { + g8 = parent.children[index].o6().r10 + 1; + this.z14(parent.children[index], f8); + for (let j8 = index; j8 < parent.children.length; j8++) { + parent.children[j8].y14 -= 1; + } + let node = parent.children.splice(index, 1); + node = null; + this.d16(parentNodeId); + } + parent.o6().b13 = parent.children.length; + parent.o6().r10 -= (g8); + let h8 = []; + h8.push(parent.parentNodeId); + i(false, g8, this.v10, h8); + return f8; + } else { + hilog.error(j16, i16, 'parent does not exist.'); + return []; + } + } + addNode(parentNodeId, currentNodeId, data, p8) { if (this.s10 === null) { this.s10 = new j3(d3); @@ -3159,12 +3192,13 @@ class h3 extends g3 { parent.o6().a13 = true; parent.o6().b13 = parent.children.length; parent.o6().r10 += 1; + this.d16(parentNodeId); if (p8) { this.e12.push(parent.parentNodeId); } else { - let r8 = []; - r8.push(parent.parentNodeId); - i(true, 1, this.v10, r8); + let r2 = []; + r2.push(parent.parentNodeId); + i(true, 1, this.v10, r2); } this.w10.set(currentNodeId, data); this.v10.set(currentNodeId, q8); @@ -3175,6 +3209,18 @@ class h3 extends g3 { } } + d16(parentNodeId) { + let parent = this.v10.get(parentNodeId); + let k2 = this.c11.get(parentNodeId); + if (parent.children.length > 0) { + if (this.c11.has(parentNodeId)) { + this.w7[k2]?.m5(true); + } + } else { + this.w7[k2]?.m5(false); + } + } + z14(k8, l8) { let m8 = []; let callback = (node) => { @@ -3190,43 +3236,6 @@ class h3 extends g3 { }); } - removeNode(currentNodeId, parentNodeId) { - if (this.v10.has(parentNodeId) && this.v10.has(currentNodeId)) { - let parent = this.v10.get(parentNodeId); - let current = this.v10.get(currentNodeId); - let f8 = []; - let index = current.y14; - let g8 = 0; - if (index < 0) { - hilog.error(j16, i16, 'node does not exist.'); - return []; - } else { - g8 = parent.children[index].o6().r10 + 1; - this.z14(parent.children[index], f8); - for (let j8 = index; j8 < parent.children.length; j8++) { - parent.children[j8].y14 -= 1; - } - let node = parent.children.splice(index, 1); - node = null; - if (parent.children.length === 0) { - if (this.c11.has(parentNodeId)) { - let i8 = this.c11.get(parentNodeId); - this.w7[i8]?.m5(false); - } - } - } - parent.o6().b13 = parent.children.length; - parent.o6().r10 -= (g8); - let h8 = []; - h8.push(parent.parentNodeId); - i(false, g8, this.v10, h8); - return f8; - } else { - hilog.error(j16, i16, 'parent does not exist.'); - return []; - } - } - a15(e8) { if (e8?.currentNodeId === undefined) { hilog.error(j16, i16, 'getNodeInfoByNodeItem: currentId is undefined'); diff --git a/advanced_ui_component/treeview/source/treeview.ets b/advanced_ui_component/treeview/source/treeview.ets index 67826b8b32d..3fa19101d25 100644 --- a/advanced_ui_component/treeview/source/treeview.ets +++ b/advanced_ui_component/treeview/source/treeview.ets @@ -1763,8 +1763,11 @@ export class TreeController { if (!addNodeResult) { return; } - this.listNodeDataSource.refreshData(MenuOperation.ADD_NODE, clickNodeId, [newNodeId]); - + this.listNodeDataSource.refreshData( + MenuOperation.ADD_NODE, + clickNodeId, + [newNodeId], + ); this.listNodeDataSource.setPopUpInfo( PopUpType.WARNINGS, InputError.NONE, @@ -2346,110 +2349,6 @@ class ListNodeDataSource extends BasicDataSource { this.initHandler(this.listNode, 0, 1); } - private refreshRemoveNodeData(removeNodeIdList: number[], parentNodeInfo: NodeInfo): void { - let deleteIndexList: number[] = []; - if (removeNodeIdList.length === 0) { - return; - } - let startIndex: number | undefined = undefined; - for (let i: number = 0; i < removeNodeIdList.length; i++) { - if (this.loadedNodeIdAndIndexMap.has(removeNodeIdList[i])) { - let loadedIndex: number = this.loadedNodeIdAndIndexMap.get(removeNodeIdList[i]) as number; - deleteIndexList.push(loadedIndex); - } - if (startIndex === undefined && this.nodeIdAndNodeIndexMap.has(removeNodeIdList[i])) { - startIndex = this.nodeIdAndNodeIndexMap.get(removeNodeIdList[i]); - } - if (startIndex !== undefined) { - let deleteNode: NodeInfo[] | null = this.listNode.splice(startIndex, 1); - deleteNode = null; - } - if (this.expandAndCollapseInfo.has(removeNodeIdList[i])) { - this.expandAndCollapseInfo.delete(removeNodeIdList[i]); // delete deleteNode expandAndCollapseInfo. - } - } - deleteIndexList.forEach((value) => { - this.notifyDataDelete(value); // notifyDataDelete do not update data. - this.notifyDataChange(value); // call notifyDataChange to update data. - }) - if (parentNodeInfo.getNodeItem().imageCollapse === null) { - if (this.nodeIdAndNodeIndexMap.has(parentNodeInfo.getNodeCurrentNodeId())) { - let parentIndex: number = this.nodeIdAndNodeIndexMap.get(parentNodeInfo.getNodeCurrentNodeId()) as number; - this.listNode[parentIndex]?.handleImageCollapseAfterAddNode(false); - } - // delete deleteNode parentNode expandAndCollapseInfo. - this.expandAndCollapseInfo.delete(parentNodeInfo.getNodeCurrentNodeId()); - this.notifyDataChange(this.loadedNodeIdAndIndexMap.get(parentNodeInfo.getNodeCurrentNodeId())); - } - let callbackParam: CallbackParam = { - currentNodeId: parentNodeInfo.getNodeCurrentNodeId(), - parentNodeId: parentNodeInfo.getNodeParentNodeId(), - }; - this.loadedListNodeFunction(); - this.appEventBus.emit(TreeListenType.NODE_DELETE, callbackParam); - } - - private refreshAddNodeData(addNodeIdList: number[]): void { - let addNodeInfo: NodeInfo = new NodeInfo(new NodeItem(emptyNodeInfo), emptyNodeInfo); - if (this.nodeIdNodeItemMap.has(addNodeIdList[0])) { - let node: NodeItem = this.nodeIdNodeItemMap.get(addNodeIdList[0]) as NodeItem; - addNodeInfo = new NodeInfo(node, this.nodeIdNodeParamMap.get(addNodeIdList[0]) as NodeParam); - addNodeInfo.addImageCollapse(node.getChildNodeInfo().isHasChildNode); - } - addNodeInfo.setIsModify(true); - - let index: number = 0; - for (let i: number = 0; i < this.listNode.length; i++) { - if (this.listNode[i].getNodeCurrentNodeId() === addNodeInfo.getNodeParentNodeId()) { - index = i; - if (this.listNode[i].getNodeItem().imageCollapse === null) { - this.listNode[i].handleImageCollapseAfterAddNode(true); - this.notifyDataChange(index); - } else if (this.expandAndCollapseInfo.get(this.listNode[i].getNodeCurrentNodeId()) === NodeStatus.COLLAPSE) { - this.changeNodeStatus(index); - } - this.listNode.splice(i + 1, 0, addNodeInfo); - this.listNode[i + 1].setTitleAndInputTextStatus(true); - this.listNode[i + 1].setNodeIsShow(true); - this.listNode[i + 1].setListItemHeight(LIST_ITEM_HEIGHT); - this.nodeIdAndNodeIndexMap.set(addNodeIdList[0], i + 1); - this.setImageSource(i + 1, InteractionStatus.EDIT); - this.currentOperation = MenuOperation.ADD_NODE; - this.notifyDataAdd(i + 1); - this.notificationNodeInfo(i + 1, this.currentOperation); - break; - } - } - this.modifyNodeIndex = index + 1; - this.setClickIndex(index); - this.lastIndex = index; - this.expandAndCollapseInfo.set(addNodeInfo.getNodeParentNodeId(), NodeStatus.EXPAND); - this.handleExpandAndCollapse(index, true); - } - - public refreshData(operation: MenuOperation, - parentNodeId: number, changeNodeIdList: number[]): void { - let parentNodeInfo: NodeInfo = new NodeInfo(new NodeItem(emptyNodeInfo), emptyNodeInfo); - if (this.nodeIdNodeItemMap.has(parentNodeId)) { - let parentNode: NodeItem = this.nodeIdNodeItemMap.get(parentNodeId) as NodeItem; - parentNodeInfo = new NodeInfo(parentNode, this.nodeIdNodeParamMap.get(parentNodeId) as NodeParam); - parentNodeInfo.addImageCollapse(parentNode.getChildNodeInfo().isHasChildNode); - } - - if (operation === MenuOperation.REMOVE_NODE) { - this.nodeIdAndSubtitleMap.set(parentNodeId, this.selectedParentNodeSubtitle); - this.notifyDataChange(this.loadedNodeIdAndIndexMap.get(parentNodeId)); - this.refreshRemoveNodeData(changeNodeIdList, parentNodeInfo); - } - - if (operation === MenuOperation.ADD_NODE) { - this.addFocusNodeId = changeNodeIdList[0]; - this.nodeIdAndSubtitleMap.set(this.getClickNodeId(), this.selectedParentNodeSubtitle); - this.nodeIdAndSubtitleMap.set(changeNodeIdList[0], this.insertNodeSubtitle); - this.refreshAddNodeData(changeNodeIdList); - } - } - public setClickIndex(index: number): void { this.thisIndex = index; } @@ -3473,6 +3372,148 @@ class ListNodeDataSource extends BasicDataSource { return current.parentNodeId; } + private refreshRemoveNodeData(removeNodeIdList: number[], parentNodeInfo: NodeInfo): void { + let deleteIndexList: number[] = []; + if (removeNodeIdList.length === 0) { + return; + } + let startIndex: number | undefined = undefined; + for (let i: number = 0; i < removeNodeIdList.length; i++) { + if (this.loadedNodeIdAndIndexMap.has(removeNodeIdList[i])) { + let loadedIndex: number = this.loadedNodeIdAndIndexMap.get(removeNodeIdList[i]) as number; + deleteIndexList.push(loadedIndex); + } + if (startIndex === undefined && this.nodeIdAndNodeIndexMap.has(removeNodeIdList[i])) { + startIndex = this.nodeIdAndNodeIndexMap.get(removeNodeIdList[i]); + } + if (startIndex !== undefined) { + let deleteNode: NodeInfo[] | null = this.listNode.splice(startIndex, 1); + deleteNode = null; + } + if (this.expandAndCollapseInfo.has(removeNodeIdList[i])) { + this.expandAndCollapseInfo.delete(removeNodeIdList[i]); // delete deleteNode expandAndCollapseInfo. + } + } + deleteIndexList.forEach((value) => { + this.notifyDataDelete(value); // notifyDataDelete do not update data. + this.notifyDataChange(value); // call notifyDataChange to update data. + }) + if (parentNodeInfo.getNodeItem().imageCollapse === null) { + if (this.nodeIdAndNodeIndexMap.has(parentNodeInfo.getNodeCurrentNodeId())) { + let parentIndex: number = this.nodeIdAndNodeIndexMap.get(parentNodeInfo.getNodeCurrentNodeId()) as number; + this.listNode[parentIndex]?.handleImageCollapseAfterAddNode(false); + } + // delete deleteNode parentNode expandAndCollapseInfo. + this.expandAndCollapseInfo.delete(parentNodeInfo.getNodeCurrentNodeId()); + this.notifyDataChange(this.loadedNodeIdAndIndexMap.get(parentNodeInfo.getNodeCurrentNodeId())); + } + let callbackParam: CallbackParam = { + currentNodeId: parentNodeInfo.getNodeCurrentNodeId(), + parentNodeId: parentNodeInfo.getNodeParentNodeId(), + }; + this.loadedListNodeFunction(); + this.appEventBus.emit(TreeListenType.NODE_DELETE, callbackParam); + } + + private refreshAddNodeData(addNodeIdList: number[]): void { + let addNodeInfo: NodeInfo = new NodeInfo(new NodeItem(emptyNodeInfo), emptyNodeInfo); + if (this.nodeIdNodeItemMap.has(addNodeIdList[0])) { + let node: NodeItem = this.nodeIdNodeItemMap.get(addNodeIdList[0]) as NodeItem; + addNodeInfo = new NodeInfo(node, this.nodeIdNodeParamMap.get(addNodeIdList[0]) as NodeParam); + addNodeInfo.addImageCollapse(node.getChildNodeInfo().isHasChildNode); + } + addNodeInfo.setIsModify(true); + + let index: number = 0; + for (let i: number = 0; i < this.listNode.length; i++) { + if (this.listNode[i].getNodeCurrentNodeId() === addNodeInfo.getNodeParentNodeId()) { + index = i; + if (this.listNode[i].getNodeItem().imageCollapse === null) { + this.listNode[i].handleImageCollapseAfterAddNode(true); + this.notifyDataChange(index); + } else if (this.expandAndCollapseInfo.get(this.listNode[i].getNodeCurrentNodeId()) === NodeStatus.COLLAPSE) { + this.changeNodeStatus(index); + } + this.listNode.splice(i + 1, 0, addNodeInfo); + this.listNode[i + 1].setTitleAndInputTextStatus(true); + this.listNode[i + 1].setNodeIsShow(true); + this.listNode[i + 1].setListItemHeight(LIST_ITEM_HEIGHT); + this.nodeIdAndNodeIndexMap.set(addNodeIdList[0], i + 1); + this.setImageSource(i + 1, InteractionStatus.EDIT); + this.currentOperation = MenuOperation.ADD_NODE; + this.notifyDataAdd(i + 1); + this.notificationNodeInfo(i + 1, this.currentOperation); + break; + } + } + this.modifyNodeIndex = index + 1; + this.setClickIndex(index); + this.lastIndex = index; + this.expandAndCollapseInfo.set(addNodeInfo.getNodeParentNodeId(), NodeStatus.EXPAND); + this.handleExpandAndCollapse(index, true); + } + + public refreshData(operation: MenuOperation, parentNodeId: number, changeNodeIdList: number[]): void { + let parentNodeInfo: NodeInfo = new NodeInfo(new NodeItem(emptyNodeInfo), emptyNodeInfo); + if (this.nodeIdNodeItemMap.has(parentNodeId)) { + let parentNode: NodeItem = this.nodeIdNodeItemMap.get(parentNodeId) as NodeItem; + parentNodeInfo = new NodeInfo(parentNode, this.nodeIdNodeParamMap.get(parentNodeId) as NodeParam); + parentNodeInfo.addImageCollapse(parentNode.getChildNodeInfo().isHasChildNode); + } + + if (operation === MenuOperation.REMOVE_NODE) { + this.nodeIdAndSubtitleMap.set(parentNodeId, this.selectedParentNodeSubtitle); + this.notifyDataChange(this.loadedNodeIdAndIndexMap.get(parentNodeId)); + this.refreshRemoveNodeData(changeNodeIdList, parentNodeInfo); + } + + if (operation === MenuOperation.ADD_NODE) { + this.addFocusNodeId = changeNodeIdList[0]; + this.nodeIdAndSubtitleMap.set(this.getClickNodeId(), this.selectedParentNodeSubtitle); + this.nodeIdAndSubtitleMap.set(changeNodeIdList[0], this.insertNodeSubtitle); + this.refreshAddNodeData(changeNodeIdList); + } + } + + /** + * remove node + * + * @param currentNodeId current node id + * @param parentNodeId parent node id + * @returns node id list which is removed + */ + public removeNode(currentNodeId: number, parentNodeId: number): number[] { + if (this.nodeIdNodeItemMap.has(parentNodeId) && this.nodeIdNodeItemMap.has(currentNodeId)) { + let parent: NodeItem = this.nodeIdNodeItemMap.get(parentNodeId) as NodeItem; + let current: NodeItem = this.nodeIdNodeItemMap.get(currentNodeId) as NodeItem; + let removeNodeIdList: number[] = []; + let index: number = current.indexOfParent; + let deleteNodeAllChildNum: number = 0; + if (index < 0) { + hilog.error(LOG_CODE, TAG, 'node does not exist.'); + return []; + } else { + deleteNodeAllChildNum = parent.children[index].getChildNodeInfo().allChildNum + 1; + this.freeNodeMemory(parent.children[index], removeNodeIdList); + for (let i: number = index; i < parent.children.length; i++) { + parent.children[i].indexOfParent -= 1; + } + let node: NodeItem[] | null = parent.children.splice(index, 1); + node = null; + this.judgeImageCollapse(parentNodeId); + } + parent.getChildNodeInfo().childNum = parent.children.length; + parent.getChildNodeInfo().allChildNum -= (deleteNodeAllChildNum); + let updateNodeIdList: number[] = []; + updateNodeIdList.push(parent.parentNodeId); + delayUpdateParentChildNum(false, deleteNodeAllChildNum, this.nodeIdNodeItemMap, updateNodeIdList); + return removeNodeIdList; + } else { + hilog.error(LOG_CODE, TAG, 'parent does not exist.'); + return []; + } + } + /** * add nodeItem in params * @@ -3507,6 +3548,7 @@ class ListNodeDataSource extends BasicDataSource { parent.getChildNodeInfo().isHasChildNode = true; parent.getChildNodeInfo().childNum = parent.children.length; parent.getChildNodeInfo().allChildNum += 1; + this.judgeImageCollapse(parentNodeId); if (initBuild) { this.updateNodeIdList.push(parent.parentNodeId); } else { @@ -3523,6 +3565,18 @@ class ListNodeDataSource extends BasicDataSource { } } + private judgeImageCollapse(parentNodeId: number): void { + let parent: NodeItem = this.nodeIdNodeItemMap.get(parentNodeId) as NodeItem; + let parentIndex: number = this.nodeIdAndNodeIndexMap.get(parentNodeId) as number; + if (parent.children.length > 0) { + if (this.nodeIdAndNodeIndexMap.has(parentNodeId)) { + this.listNode[parentIndex]?.addImageCollapse(true); + } + } else { + this.listNode[parentIndex]?.addImageCollapse(false); + } + } + private freeNodeMemory(rootNode: NodeItem, removeNodeIdList: number[]): void { let deleteNode: NodeItem[] = []; let callback = (node: NodeItem): boolean => { @@ -3538,50 +3592,6 @@ class ListNodeDataSource extends BasicDataSource { }) } - /** - * remove node - * - * @param currentNodeId current node id - * @param parentNodeId parent node id - * @returns node id list which is removed - */ - public removeNode(currentNodeId: number, parentNodeId: number): number[] { - if (this.nodeIdNodeItemMap.has(parentNodeId) && this.nodeIdNodeItemMap.has(currentNodeId)) { - let parent: NodeItem = this.nodeIdNodeItemMap.get(parentNodeId) as NodeItem; - let current: NodeItem = this.nodeIdNodeItemMap.get(currentNodeId) as NodeItem; - let removeNodeIdList: number[] = []; - let index: number = current.indexOfParent; - let deleteNodeAllChildNum: number = 0; - if (index < 0) { - hilog.error(LOG_CODE, TAG, 'node does not exist.'); - return []; - } else { - deleteNodeAllChildNum = parent.children[index].getChildNodeInfo().allChildNum + 1; - this.freeNodeMemory(parent.children[index], removeNodeIdList); - for (let i: number = index; i < parent.children.length; i++) { - parent.children[i].indexOfParent -= 1; - } - let node: NodeItem[] | null = parent.children.splice(index, 1); - node = null; - if (parent.children.length === 0) { - if (this.nodeIdAndNodeIndexMap.has(parentNodeId)) { - let parentIndex: number = this.nodeIdAndNodeIndexMap.get(parentNodeId) as number; - this.listNode[parentIndex]?.addImageCollapse(false); - } - } - } - parent.getChildNodeInfo().childNum = parent.children.length; - parent.getChildNodeInfo().allChildNum -= (deleteNodeAllChildNum); - let updateNodeIdList: number[] = []; - updateNodeIdList.push(parent.parentNodeId); - delayUpdateParentChildNum(false, deleteNodeAllChildNum, this.nodeIdNodeItemMap, updateNodeIdList); - return removeNodeIdList; - } else { - hilog.error(LOG_CODE, TAG, 'parent does not exist.'); - return []; - } - } - private getNodeInfoByNodeItem(nodeItem: NodeItem): NodeInfo { if (nodeItem?.currentNodeId === undefined) { hilog.error(LOG_CODE, TAG, 'getNodeInfoByNodeItem: currentId is undefined'); @@ -3840,8 +3850,9 @@ export struct TreeViewInner { left: $r('sys.float.padding_level0'), right: $r('sys.float.padding_level0'), top: $r('sys.float.padding_level0'), - bottom: $r('sys.float.padding_level0') }; - private inputFontSize: number = resourceManager.getSystemResourceManager().getNumberByName('ohos_id_text_size_body1'); + bottom: $r('sys.float.padding_level0'), + }; + private inputFontSize: number = resourceManager.getSystemResourceManager().getNumberByName('ohos_id_text_size_body1'); aboutToAppear(): void { if (this.item.getNodeItem().imageNode) {