import { ArrayService } from '@delon/util' ; import { Component , OnInit , Injector } from '@angular/core' ; import { NzTreeNode } from 'ng-zorro-antd/tree' ; import { AppComponentBase } from '@shared/common/app-component-base' ; import { PermissionTreeEditModel } from '@app/admin/shared/permission-tree/permission-tree-edit.model' ; @ Component ( { selector : 'permission-tree' , templateUrl : './permission-tree.component.html' , } ) export class PermissionTreeComponent extends AppComponentBase implements OnInit { private _editData : PermissionTreeEditModel ; checkStrictly = true ; loading = false ; set editData ( val ) { this . _editData = val ; this . arrToTreeNode ( ) ; } filterText : string ; _treeData : NzTreeNode [ ] = [ ] ; ngOnInit ( ) { } constructor ( injector , private _arrayService ) { super ( injector ) ; } arrToTreeNode ( ) { this . loading = true ; this . _treeData = this . _arrayService . arrToTreeNode ( this . _editData . permissions , { idMapName : 'name' , parentIdMapName : 'parentName' , titleMapName : 'displayName' , cb : ( item ) => { item . expanded = true ; item . checked = item . isLeaf == true && this . _editData . grantedPermissionNames . indexOf ( item . name ) != - 1 ? true : false ; } } ) ; setTimeout ( ( ) => { this . checkStrictly = false ; this . loading = false ; } , 500 ) ; } reload ( ) { this . checkStrictly = true ; this . arrToTreeNode ( ) ; this . filterText = '' ; } getGrantedPermissionNames ( ) { const permissionNames = this . _arrayService . getKeysByTreeNode ( this . _treeData ) ; return permissionNames ; } filterTextEmptyChange ( ) { if ( ! this . filterText ) { this . reload ( ) ; } } }