edit
This commit is contained in:
		@ -1,9 +1,9 @@
 | 
				
			|||||||
<nz-card [nzLoading]="loadingInfo" [nzBordered]="false">
 | 
					<nz-card [nzLoading]="loadingInfo" [nzBordered]="false">
 | 
				
			||||||
    <se-container se-container="1">
 | 
					    <se-container se-container="1">
 | 
				
			||||||
        <se label="接口权限" required [labelWidth]="120">
 | 
					        <se label="接口权限" required [labelWidth]="120">
 | 
				
			||||||
            <app-menu-tree #menu (changeData)="getData($event)" [type]="'edit'"
 | 
					            <app-menu-tree #menu (changeData)="getData($event)" [appId]="params.appId"
 | 
				
			||||||
                [roleId]="params.id" [appId]="params.appId" [isAuthorityIdDTOList]="roleInfoData.authority || []"
 | 
					                [isAuthorityIdDTOList]="roleInfoData.authority || []"
 | 
				
			||||||
                [authorityAssistId]="roleInfoData.authorityAssistId || []" (changeIF)="changeIF($event)">
 | 
					                [authorityAssistId]="roleInfoData.authorityAssistId || []">
 | 
				
			||||||
            </app-menu-tree>
 | 
					            </app-menu-tree>
 | 
				
			||||||
        </se>
 | 
					        </se>
 | 
				
			||||||
    </se-container>
 | 
					    </se-container>
 | 
				
			||||||
 | 
				
			|||||||
@ -47,9 +47,7 @@ export class ApiAuthModalComponent implements OnInit {
 | 
				
			|||||||
  close() {
 | 
					  close() {
 | 
				
			||||||
    this.modal.destroy();
 | 
					    this.modal.destroy();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  changeIF(value: any) {
 | 
					  
 | 
				
			||||||
    this.changeValue = true;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  sure() {
 | 
					  sure() {
 | 
				
			||||||
    const auths = this.menu?.washTree();
 | 
					    const auths = this.menu?.washTree();
 | 
				
			||||||
    if (auths.authorityAssistId.length === 0) {
 | 
					    if (auths.authorityAssistId.length === 0) {
 | 
				
			||||||
 | 
				
			|||||||
@ -11,7 +11,8 @@
 | 
				
			|||||||
                <div *ngIf="origin.buttonInfoList && origin.buttonInfoList.length">
 | 
					                <div *ngIf="origin.buttonInfoList && origin.buttonInfoList.length">
 | 
				
			||||||
                    <label style="width: 100%" nz-checkbox [ngModel]="_apiAuthSet.has(item.functionButtonId)"
 | 
					                    <label style="width: 100%" nz-checkbox [ngModel]="_apiAuthSet.has(item.functionButtonId)"
 | 
				
			||||||
                        *ngFor="let item of origin.buttonInfoList"
 | 
					                        *ngFor="let item of origin.buttonInfoList"
 | 
				
			||||||
                        (ngModelChange)="addAuthority($event,origin,node,  item)" [disabled]="source === 'onlyAuth'">{{
 | 
					                        (ngModelChange)="butCheckedAction($event,origin,node,  item)"
 | 
				
			||||||
 | 
					                        [disabled]="source === 'onlyAuth'">{{
 | 
				
			||||||
                        item.permissionsName }}</label>
 | 
					                        item.permissionsName }}</label>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
                <nz-empty nzNotFoundImage="simple" *ngIf="!origin.buttonInfoList || origin.buttonInfoList.length === 0">
 | 
					                <nz-empty nzNotFoundImage="simple" *ngIf="!origin.buttonInfoList || origin.buttonInfoList.length === 0">
 | 
				
			||||||
 | 
				
			|||||||
@ -12,24 +12,20 @@ export class MenuTreeComponent implements OnInit, OnChanges {
 | 
				
			|||||||
  @ViewChild('nzTreeComponent', { static: false }) nzTreeComponent!: NzTreeComponent;
 | 
					  @ViewChild('nzTreeComponent', { static: false }) nzTreeComponent!: NzTreeComponent;
 | 
				
			||||||
  origin: any = { buttonInfoList: [], dictList: [] };
 | 
					  origin: any = { buttonInfoList: [], dictList: [] };
 | 
				
			||||||
  node!: NzTreeNode;
 | 
					  node!: NzTreeNode;
 | 
				
			||||||
  authority: any[] = [];
 | 
					 | 
				
			||||||
  functionList: any[] = [];
 | 
					  functionList: any[] = [];
 | 
				
			||||||
  @Input() type = 'edit';
 | 
					 | 
				
			||||||
  @Input() source = '';
 | 
					  @Input() source = '';
 | 
				
			||||||
  @Input() appId = this.envSrv.env.appId;
 | 
					  @Input() appId = this.envSrv.env.appId;
 | 
				
			||||||
  @Input() isAuthorityIdDTOList: any[] = [];
 | 
					  @Input() isAuthorityIdDTOList: AuthorityIdVO[] = [];
 | 
				
			||||||
  @Input() authorityAssistId: any[] = [];
 | 
					  @Input() authorityAssistId: string[] = [];
 | 
				
			||||||
  @Input() roleId: any;
 | 
					 | 
				
			||||||
  @Output() changeData = new EventEmitter<any>();
 | 
					  @Output() changeData = new EventEmitter<any>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  _apiAuthSet = new Set<string>();
 | 
					  _apiAuthSet = new Set<string>(); // 操作权限全数据源
 | 
				
			||||||
  _NodeAuthMap = new Map<string, { authorityId: string; buttonAuthorityIds: string[]; isUpdateAuthority: 0 | 1 }>();
 | 
					  _NodeAuthMap = new Map<string, AuthorityIdVO>(); // 树权限数据源
 | 
				
			||||||
  constructor(public service: SystemService, private cdr: ChangeDetectorRef, private envSrv: EAEnvironmentService) {}
 | 
					  constructor(public service: SystemService, private cdr: ChangeDetectorRef, private envSrv: EAEnvironmentService) {}
 | 
				
			||||||
  ngOnChanges(changes: SimpleChanges): void {
 | 
					  ngOnChanges(changes: SimpleChanges): void {
 | 
				
			||||||
    if (changes.isAuthorityIdDTOList) {
 | 
					    if (changes.isAuthorityIdDTOList) {
 | 
				
			||||||
      if (this.type === 'edit') {
 | 
					      // 遍历初始化树节点权限数据源  初始化操作权限数据源
 | 
				
			||||||
        this.authority = this.isAuthorityIdDTOList || [];
 | 
					      this.isAuthorityIdDTOList?.forEach(auth => {
 | 
				
			||||||
        this.authority.forEach(auth => {
 | 
					 | 
				
			||||||
        this._NodeAuthMap.set(auth.authorityId, auth);
 | 
					        this._NodeAuthMap.set(auth.authorityId, auth);
 | 
				
			||||||
        if (auth.buttonAuthorityIds) {
 | 
					        if (auth.buttonAuthorityIds) {
 | 
				
			||||||
          auth.buttonAuthorityIds.forEach((buttonId: string) => this._apiAuthSet.add(buttonId));
 | 
					          auth.buttonAuthorityIds.forEach((buttonId: string) => this._apiAuthSet.add(buttonId));
 | 
				
			||||||
@ -37,7 +33,6 @@ export class MenuTreeComponent implements OnInit, OnChanges {
 | 
				
			|||||||
      });
 | 
					      });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ngOnInit() {
 | 
					  ngOnInit() {
 | 
				
			||||||
    this.getAllFunction();
 | 
					    this.getAllFunction();
 | 
				
			||||||
@ -54,11 +49,11 @@ export class MenuTreeComponent implements OnInit, OnChanges {
 | 
				
			|||||||
      });
 | 
					      });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  addAuthority(
 | 
					  butCheckedAction(
 | 
				
			||||||
    status: boolean,
 | 
					    status: boolean,
 | 
				
			||||||
    origin: { buttonInfoList: any[]; [key: string]: any },
 | 
					    origin: { buttonInfoList: any[]; [key: string]: any },
 | 
				
			||||||
    node: NzTreeNode,
 | 
					    node: NzTreeNode,
 | 
				
			||||||
    item: { checked: any; functionButtonId: string }
 | 
					    item: { functionButtonId: string }
 | 
				
			||||||
  ) {
 | 
					  ) {
 | 
				
			||||||
    // 更新完整操作权限数据
 | 
					    // 更新完整操作权限数据
 | 
				
			||||||
    if (status) {
 | 
					    if (status) {
 | 
				
			||||||
@ -103,7 +98,6 @@ export class MenuTreeComponent implements OnInit, OnChanges {
 | 
				
			|||||||
  clickTreeNodeAction(event: any): void {
 | 
					  clickTreeNodeAction(event: any): void {
 | 
				
			||||||
    this.origin = event.node.origin;
 | 
					    this.origin = event.node.origin;
 | 
				
			||||||
    this.node = event.node;
 | 
					    this.node = event.node;
 | 
				
			||||||
    console.log(this.node);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // 叶子节点获取操作权限, 非叶子节点则展开
 | 
					    // 叶子节点获取操作权限, 非叶子节点则展开
 | 
				
			||||||
    if (event.node.origin.isLeaf) {
 | 
					    if (event.node.origin.isLeaf) {
 | 
				
			||||||
@ -142,40 +136,8 @@ export class MenuTreeComponent implements OnInit, OnChanges {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private recursionSetNodeAuth(origin: any) {
 | 
					 | 
				
			||||||
    this._NodeAuthMap.set(origin.id, { authorityId: origin.id, buttonAuthorityIds: [], isUpdateAuthority: 1 });
 | 
					 | 
				
			||||||
    let auths = [...this.authorityAssistId];
 | 
					 | 
				
			||||||
    origin.children?.forEach((node: any) => {
 | 
					 | 
				
			||||||
      auths.push(node.id);
 | 
					 | 
				
			||||||
      node._selected = true;
 | 
					 | 
				
			||||||
      const _auth = this._NodeAuthMap.get(node.id);
 | 
					 | 
				
			||||||
      this._NodeAuthMap.set(node.id, {
 | 
					 | 
				
			||||||
        authorityId: node.id,
 | 
					 | 
				
			||||||
        buttonAuthorityIds: _auth?.buttonAuthorityIds || [],
 | 
					 | 
				
			||||||
        isUpdateAuthority: 1
 | 
					 | 
				
			||||||
      });
 | 
					 | 
				
			||||||
      if (node?.children?.length > 0) {
 | 
					 | 
				
			||||||
        this.recursionSetNodeAuth(node);
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    auths = [...auths, ...this.authorityAssistId];
 | 
					 | 
				
			||||||
    const authsSet = new Set<string>(auths);
 | 
					 | 
				
			||||||
    this.authorityAssistId = [...Array.from(authsSet)];
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  private recursionDeleteNodeAuth(origin: any) {
 | 
					 | 
				
			||||||
    this._NodeAuthMap.delete(origin.id);
 | 
					 | 
				
			||||||
    this.authorityAssistId = this.authorityAssistId.filter(auth => auth !== origin.id);
 | 
					 | 
				
			||||||
    origin.children?.forEach((node: any) => {
 | 
					 | 
				
			||||||
      this.authorityAssistId = this.authorityAssistId.filter(auth => auth !== node.id);
 | 
					 | 
				
			||||||
      this._NodeAuthMap.delete(node.id);
 | 
					 | 
				
			||||||
      if (node?.children?.length > 0) {
 | 
					 | 
				
			||||||
        this.recursionDeleteNodeAuth(node);
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
 | 
					   * TODO
 | 
				
			||||||
   * 根据树勾选状态更新数据源
 | 
					   * 根据树勾选状态更新数据源
 | 
				
			||||||
   * 1.更新操作权限点数据源 _apiAuthSet
 | 
					   * 1.更新操作权限点数据源 _apiAuthSet
 | 
				
			||||||
   * 2.更新菜单权限数据源 _NodeAuthMap
 | 
					   * 2.更新菜单权限数据源 _NodeAuthMap
 | 
				
			||||||
@ -205,8 +167,6 @@ export class MenuTreeComponent implements OnInit, OnChanges {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  washTree() {
 | 
					  washTree() {
 | 
				
			||||||
    // const checkedNode: any = this.nzTreeComponent.getCheckedNodeList();
 | 
					 | 
				
			||||||
    // const halfCheckedNode: any = this.nzTreeComponent.getHalfCheckedNodeList();
 | 
					 | 
				
			||||||
    const authority: any[] = [];
 | 
					    const authority: any[] = [];
 | 
				
			||||||
    this._NodeAuthMap.forEach(nodeAuth => authority.push(nodeAuth));
 | 
					    this._NodeAuthMap.forEach(nodeAuth => authority.push(nodeAuth));
 | 
				
			||||||
    const result = {
 | 
					    const result = {
 | 
				
			||||||
@ -235,6 +195,45 @@ export class MenuTreeComponent implements OnInit, OnChanges {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * 向下递归添加子节点到树权限数据源
 | 
				
			||||||
 | 
					   *
 | 
				
			||||||
 | 
					   * @param origin
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  private recursionSetNodeAuth(origin: any) {
 | 
				
			||||||
 | 
					    this._NodeAuthMap.set(origin.id, { authorityId: origin.id, buttonAuthorityIds: [], isUpdateAuthority: 1 });
 | 
				
			||||||
 | 
					    let auths = [...this.authorityAssistId];
 | 
				
			||||||
 | 
					    origin.children?.forEach((node: any) => {
 | 
				
			||||||
 | 
					      auths.push(node.id);
 | 
				
			||||||
 | 
					      // 标记为 通过父级勾选关联导致勾选。防止父级勾选导致更新了源数据
 | 
				
			||||||
 | 
					      node._selected = true;
 | 
				
			||||||
 | 
					      const _auth = this._NodeAuthMap.get(node.id);
 | 
				
			||||||
 | 
					      this._NodeAuthMap.set(node.id, {
 | 
				
			||||||
 | 
					        authorityId: node.id,
 | 
				
			||||||
 | 
					        buttonAuthorityIds: _auth?.buttonAuthorityIds || [],
 | 
				
			||||||
 | 
					        isUpdateAuthority: 1
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					      if (node?.children?.length > 0) {
 | 
				
			||||||
 | 
					        this.recursionSetNodeAuth(node);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    auths = [...auths, ...this.authorityAssistId];
 | 
				
			||||||
 | 
					    const authsSet = new Set<string>(auths);
 | 
				
			||||||
 | 
					    this.authorityAssistId = [...Array.from(authsSet)];
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private recursionDeleteNodeAuth(origin: any) {
 | 
				
			||||||
 | 
					    this._NodeAuthMap.delete(origin.id);
 | 
				
			||||||
 | 
					    this.authorityAssistId = this.authorityAssistId.filter(auth => auth !== origin.id);
 | 
				
			||||||
 | 
					    origin.children?.forEach((node: any) => {
 | 
				
			||||||
 | 
					      this.authorityAssistId = this.authorityAssistId.filter(auth => auth !== node.id);
 | 
				
			||||||
 | 
					      this._NodeAuthMap.delete(node.id);
 | 
				
			||||||
 | 
					      if (node?.children?.length > 0) {
 | 
				
			||||||
 | 
					        this.recursionDeleteNodeAuth(node);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * 向上递归取消父节点勾选
 | 
					   * 向上递归取消父节点勾选
 | 
				
			||||||
   * 清理勾选数据
 | 
					   * 清理勾选数据
 | 
				
			||||||
@ -248,3 +247,10 @@ export class MenuTreeComponent implements OnInit, OnChanges {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface AuthorityIdVO {
 | 
				
			||||||
 | 
					  authorityId: string;
 | 
				
			||||||
 | 
					  buttonAuthorityIds: string[];
 | 
				
			||||||
 | 
					  dataAuthority?: { dictId: number; dictItemId: number; itemKey: string }[];
 | 
				
			||||||
 | 
					  isUpdateAuthority?: 0 | 1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user