import { RhOrganizationUnitQueryDto, RhOrganizationUnitDto, RhTreeNode } from 'rh-base/model'; import { RhAacService } from './../../aac.service'; import { ObjectHelper, RhTreeHelper, MsgHelper } from 'rh-base/core'; import { Component, OnInit, Output, EventEmitter, Input, ViewChild } from '@angular/core'; import { NzTreeNode, NzTreeComponent, NzTreeService, NzFormatEmitEvent } from 'ng-zorro-antd/tree'; @Component({ selector: 'rh-user-group-tree-snippet', templateUrl: './user-group-tree-snippet.component.html', styleUrls: ['./user-group-tree-snippet.component.less'] }) export class UserGroupTreeSnippetComponent implements OnInit { @Input() rootNode!: RhOrganizationUnitDto; @Input() validOrganizationDataset!: RhOrganizationUnitDto[]; @Output() selectedTreeNodeChange = new EventEmitter(); @Input() selectedTreeNode: NzTreeNode | null = null; @ViewChild('organizationUnitTree', { static: false }) organizationUnitTree!: NzTreeComponent; treeNodes: NzTreeNode[] = []; constructor(public operator: RhAacService, public treeSer: NzTreeService) {} ngOnInit() { this.initTreeNodes(); } // ************************用户组************************ initTreeNodes(): void { this.operator.GetOrganizationUnitTreeNodes(RhOrganizationUnitQueryDto.create()).subscribe((result) => { if (result.Success) { const node = RhTreeNode.create(); ObjectHelper.MapT(result.Attach, node); this.treeNodes = RhTreeHelper.ToNzTreeNodes(node, this.treeSer); this.rootNode = node.nodeData as RhOrganizationUnitDto; this.setValidOrganizationDatas(); } else if (!result.Success || !result.Attach) { MsgHelper.ShowInfoMessage('查询无用户组数据'); } }); } onSelectTreeNode($event: NzFormatEmitEvent) { const treeNode = $event.node; if (treeNode?.isSelected) { this.selectedTreeNode = treeNode; } else { this.selectedTreeNode = null; } this.selectedTreeNodeChange.emit(this.selectedTreeNode as NzTreeNode); } private setValidOrganizationDatas() { if (this.validOrganizationDataset && this.validOrganizationDataset.length) { this.setValidTreeNode(this.treeNodes[0], this.validOrganizationDataset); } } private setValidTreeNode(treeNode: NzTreeNode, organizationDatas: RhOrganizationUnitDto[]) { const organizationData = treeNode.origin['customData'] as RhOrganizationUnitDto; const tempIndex = organizationDatas.findIndex((ele) => ele.Name === organizationData.Name); if (tempIndex !== -1) { treeNode.isDisabled = false; } else { treeNode.isDisabled = true; } if (treeNode.children && treeNode.children.length) { treeNode.isExpanded = true; treeNode.children.forEach((ele) => { this.setValidTreeNode(ele, organizationDatas); }); } } }