edit
This commit is contained in:
		| @ -1,10 +1,10 @@ | |||||||
| <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-cuc-menu #menu (changeData)="getData($event)" [type]="'edit'" |             <app-menu-tree #menu (changeData)="getData($event)" [type]="'edit'" | ||||||
|                 [roleId]="params.id" [appId]="params.appId" [isAuthorityIdDTOList]="roleInfoData.authority || []" |                 [roleId]="params.id" [appId]="params.appId" [isAuthorityIdDTOList]="roleInfoData.authority || []" | ||||||
|                 [authorityAssistId]="roleInfoData.authorityAssistId || []" (changeIF)="changeIF($event)"> |                 [authorityAssistId]="roleInfoData.authorityAssistId || []" (changeIF)="changeIF($event)"> | ||||||
|             </app-cuc-menu> |             </app-menu-tree> | ||||||
|         </se> |         </se> | ||||||
|     </se-container> |     </se-container> | ||||||
| </nz-card> | </nz-card> | ||||||
|  | |||||||
| @ -0,0 +1,23 @@ | |||||||
|  | <div class="treeWrap"> | ||||||
|  |     <div class="leftBox"> | ||||||
|  |         <nz-tree #nzTreeComponent [nzData]="functionList" (nzClick)="nzEvent($event)" nzCheckable | ||||||
|  |             [nzCheckedKeys]="authorityAssistId" [nzExpandedKeys]="defaultExpandedKeys" style="max-height: 600px; | ||||||
|  |         overflow: auto;"> | ||||||
|  |         </nz-tree> | ||||||
|  |     </div> | ||||||
|  |     <div class="rightBox"> | ||||||
|  |         <nz-tabset [nzSize]="'small'"> | ||||||
|  |             <nz-tab nzTitle="操作权限"> | ||||||
|  |                 <div *ngIf="origin.buttonInfoList && origin.buttonInfoList.length"> | ||||||
|  |                     <label style="width: 100%" nz-checkbox [(ngModel)]="item.checked" | ||||||
|  |                         *ngFor="let item of origin.buttonInfoList" (ngModelChange)="addAuthority(origin, node, item)" | ||||||
|  |                         [disabled]="source === 'onlyAuth'">{{ | ||||||
|  |                         item.permissionsName }}</label> | ||||||
|  |                 </div> | ||||||
|  |                 <nz-empty nzNotFoundImage="simple" *ngIf="origin.buttonInfoList && origin.buttonInfoList.length === 0"> | ||||||
|  |                 </nz-empty> | ||||||
|  |             </nz-tab> | ||||||
|  |         </nz-tabset> | ||||||
|  |     </div> | ||||||
|  | </div> | ||||||
|  | <nz-empty nzNotFoundImage="simple" *ngIf="functionList.length === 0"></nz-empty> | ||||||
| @ -0,0 +1,211 @@ | |||||||
|  | :host { | ||||||
|  |     .toolbar-btn { | ||||||
|  |         padding-left: 0; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     ::ng-deep { | ||||||
|  |         .ant-checkbox-wrapper+.ant-checkbox-wrapper { | ||||||
|  |             margin: 0; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         .listDiv { | ||||||
|  |             cdk-virtual-scroll-viewport { | ||||||
|  |                 border: 1px solid rgba(242, 242, 240, 1); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             .selectedItem { | ||||||
|  |                 background: #e6f7ff; | ||||||
|  |  | ||||||
|  |                 span { | ||||||
|  |                     a { | ||||||
|  |                         color: rgba(212, 72, 86, 1); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 ul>li>a>i { | ||||||
|  |                     color: rgba(212, 72, 86, 1); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             .listBottom { | ||||||
|  |                 height          : 2.5rem; | ||||||
|  |                 overflow        : hidden; | ||||||
|  |                 text-align      : center; | ||||||
|  |                 background-color: rgba(245, 245, 245, 0.7); | ||||||
|  |  | ||||||
|  |                 &:hover { | ||||||
|  |                     background-color: rgba(245, 245, 245, 1); | ||||||
|  |                     transition      : all 1s; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         .ant-tabs-nav { | ||||||
|  |             width : 100%; | ||||||
|  |             margin: 0 !important; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         .buttons { | ||||||
|  |             padding: 0; | ||||||
|  |  | ||||||
|  |             button { | ||||||
|  |                 display  : block; | ||||||
|  |                 max-width: 10rem; | ||||||
|  |                 margin   : 0.3rem 0.5rem 0 0; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             .ant-btn+.ant-btn:not(.ant-btn-link), | ||||||
|  |             .ant-btn+nz-popconfirm, | ||||||
|  |             nz-popconfirm+.ant-btn, | ||||||
|  |             nz-popconfirm+nz-popconfirm, | ||||||
|  |             .ant-btn+nz-button-group, | ||||||
|  |             nz-button-group+.ant-btn, | ||||||
|  |             .ant-btn+nz-dropdown, | ||||||
|  |             nz-dropdown+.ant-btn, | ||||||
|  |             nz-popconfirm+nz-button-group, | ||||||
|  |             nz-button-group+nz-popconfirm { | ||||||
|  |                 margin-left: 0; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         .ant-tabs-bar { | ||||||
|  |             margin: 0; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // .ant-tree-node-selected { | ||||||
|  |         //   background: none !important; | ||||||
|  |         // } | ||||||
|  |         // .ant-tree-node-content-wrapper:hover { | ||||||
|  |         //   background: none; | ||||||
|  |         // } | ||||||
|  |         .ant-tree-node-content-wrapper { | ||||||
|  |             width: 100%; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         .ant-tabs .ant-tabs-tabpane { | ||||||
|  |             padding      : 10px 10px 2px 10px; | ||||||
|  |             background   : #fdfdfd; | ||||||
|  |             border-right : solid 1px #eee; | ||||||
|  |             border-bottom: solid 1px #eee; | ||||||
|  |             border-left  : solid 1px #eee; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // .ant-tabs-tab { | ||||||
|  |         //   width: 50%; | ||||||
|  |         //   text-align: center; | ||||||
|  |         // } | ||||||
|  |         // .ant-tabs-tab-arrow-show { | ||||||
|  |         //   display: none; | ||||||
|  |         // } | ||||||
|  |         ul { | ||||||
|  |             margin : 0; | ||||||
|  |             padding: 0; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .firstStepBox { | ||||||
|  |     width      : 100%; | ||||||
|  |     line-height: 50px; | ||||||
|  |     text-align : center; | ||||||
|  |     background : #f7f7f7; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .itemBox { | ||||||
|  |     width      : 100%; | ||||||
|  |     height     : 50px; | ||||||
|  |     padding    : 0 0 0 60px; | ||||||
|  |     color      : #5f5f5f; | ||||||
|  |     line-height: 50px; | ||||||
|  |     cursor     : pointer; | ||||||
|  |  | ||||||
|  |     &:hover { | ||||||
|  |         background: #e6f7ff; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .twoStepBox { | ||||||
|  |     width      : 100%; | ||||||
|  |     line-height: 50px; | ||||||
|  |     text-align : center; | ||||||
|  |     background : #f7f7f7; | ||||||
|  |  | ||||||
|  |     span { | ||||||
|  |         display: inline-block; | ||||||
|  |         margin : 0 auto; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     >i { | ||||||
|  |         float : right; | ||||||
|  |         margin: 20px 20px 0 0; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     button { | ||||||
|  |         float : right; | ||||||
|  |         margin: 8px 20px 0 0; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     .blueFont { | ||||||
|  |         color: #1890ff; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .folder-desc i { | ||||||
|  |     margin: 0 5px; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .flexBox { | ||||||
|  |     .titleBox { | ||||||
|  |         display        : flex; | ||||||
|  |         justify-content: space-between; | ||||||
|  |  | ||||||
|  |         i { | ||||||
|  |             margin: 0 8px; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | ul { | ||||||
|  |     display: block; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | li { | ||||||
|  |     line-height: 30px; | ||||||
|  |     list-style : none; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .dictData { | ||||||
|  |     dl { | ||||||
|  |         margin : 0; | ||||||
|  |         padding: 0; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     dt { | ||||||
|  |         margin       : 0 0 5px 0; | ||||||
|  |         padding      : 3px 0; | ||||||
|  |         color        : #999; | ||||||
|  |         font-weight  : normal; | ||||||
|  |         font-size    : 13px; | ||||||
|  |         border-bottom: solid 1px #eee; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | label { | ||||||
|  |     color    : #666; | ||||||
|  |     font-size: 13px; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .treeWrap { | ||||||
|  |     display: flex; | ||||||
|  |     width  : 700px; | ||||||
|  |  | ||||||
|  |     .leftBox { | ||||||
|  |         width          : 40%; | ||||||
|  |         // border-right: solid 1px #eee; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     .rightBox { | ||||||
|  |         width  : 60%; | ||||||
|  |         padding: 0 0 0 20px; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,413 @@ | |||||||
|  | import { ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild } from '@angular/core'; | ||||||
|  | import { EAEnvironmentService } from '@shared'; | ||||||
|  | import { NzTreeComponent } from 'ng-zorro-antd/tree'; | ||||||
|  | import { SystemService } from '../../../services/system.service'; | ||||||
|  |  | ||||||
|  | @Component({ | ||||||
|  |   selector: 'app-menu-tree', | ||||||
|  |   templateUrl: './menu-tree.component.html', | ||||||
|  |   styleUrls: ['./menu-tree.component.less'] | ||||||
|  | }) | ||||||
|  | export class MenuTreeComponent implements OnInit, OnChanges { | ||||||
|  |   @ViewChild('nzTreeComponent', { static: false }) nzTreeComponent!: NzTreeComponent; | ||||||
|  |   origin: any = { buttonInfoList: [], dictList: [] }; | ||||||
|  |   node: any = {}; | ||||||
|  |   authority: any[] = []; | ||||||
|  |   defaultSelectedKeys: any[] = []; | ||||||
|  |   defaultExpandedKeys: any[] = []; | ||||||
|  |   defaultCheckedKeys: any[] = []; | ||||||
|  |   functionList: any[] = []; | ||||||
|  |   allChecked = false; | ||||||
|  |   indeterminate = true; | ||||||
|  |   @Input() type = 'edit'; | ||||||
|  |   @Input() source = ''; | ||||||
|  |   @Input() appId = this.envSrv.env.appId; | ||||||
|  |   @Input() isAuthorityIdDTOList: any[] = []; | ||||||
|  |   @Input() authorityAssistId: any[] = []; | ||||||
|  |   @Input() roleId: any; | ||||||
|  |   @Output() changeData = new EventEmitter<any>(); | ||||||
|  |   constructor(public service: SystemService, private cdr: ChangeDetectorRef, private envSrv: EAEnvironmentService) {} | ||||||
|  |   ngOnChanges(changes: SimpleChanges): void { | ||||||
|  |     if (changes.isAuthorityIdDTOList) { | ||||||
|  |       if (this.type === 'edit') { | ||||||
|  |         this.authority = this.isAuthorityIdDTOList || []; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   ngOnInit() { | ||||||
|  |     this.getAllFunction(); | ||||||
|  |   } | ||||||
|  |   getAllFunction() { | ||||||
|  |     this.service | ||||||
|  |       .request(this.service.$api_getAllFunctionInfoByAppId, { appId: this.appId || this.envSrv.env.appId }, 'POST', true, 'FORM') | ||||||
|  |       .subscribe(res => { | ||||||
|  |         this.functionList = res; | ||||||
|  |         this.authorityAssistId = [...this.authorityAssistId]; | ||||||
|  |         this.cdr.detectChanges(); | ||||||
|  |       }); | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   addAuthority(origin: { id: any; all: any }, node: { buttonInfoList: any[] }, item?: { checked: any; functionButtonId: any }) { | ||||||
|  |     console.log(origin, node); | ||||||
|  |  | ||||||
|  |     if (this.authority?.length && this.authority.filter(authItem => authItem.authorityId === origin.id).length) { | ||||||
|  |       // 判断此菜单权限是否已经存在权限列表中 | ||||||
|  |       // 当前操作菜单id存在权限列表里 | ||||||
|  |       this.authority.forEach(menuItem => { | ||||||
|  |         console.log(menuItem); | ||||||
|  |         console.log(item); | ||||||
|  |  | ||||||
|  |         if (menuItem.authorityId === origin.id) { | ||||||
|  |           menuItem.buttonAuthorityIds = menuItem.buttonAuthorityIds || []; // 防止属性不存在,给属性指定数据类型 | ||||||
|  |           if (item) { | ||||||
|  |             // 单选 | ||||||
|  |             if (item.checked) { | ||||||
|  |               if (menuItem.buttonAuthorityIds.indexOf(item.functionButtonId) === -1) { | ||||||
|  |                 // 如果该按钮在数据权限数组中不存在 | ||||||
|  |                 menuItem.buttonAuthorityIds.push(item.functionButtonId); | ||||||
|  |               } | ||||||
|  |             } else { | ||||||
|  |               if (menuItem.buttonAuthorityIds && menuItem.buttonAuthorityIds.length) { | ||||||
|  |                 menuItem.buttonAuthorityIds.forEach((btnItem: any, index: any) => { | ||||||
|  |                   if (btnItem === item.functionButtonId) { | ||||||
|  |                     menuItem.buttonAuthorityIds.splice(index, 1); | ||||||
|  |                   } | ||||||
|  |                 }); | ||||||
|  |               } | ||||||
|  |             } | ||||||
|  |           } else { | ||||||
|  |             // 全选 | ||||||
|  |             if (origin.all) { | ||||||
|  |               node.buttonInfoList.forEach((nodeItem: { id: any; checked: boolean }) => { | ||||||
|  |                 if (menuItem.buttonAuthorityIds.indexOf(nodeItem.id) === -1) { | ||||||
|  |                   menuItem.buttonAuthorityIds.push(nodeItem.id); | ||||||
|  |                   nodeItem.checked = true; | ||||||
|  |                 } | ||||||
|  |               }); | ||||||
|  |             } else { | ||||||
|  |               if (menuItem.buttonAuthorityIds && menuItem.buttonAuthorityIds.length) { | ||||||
|  |                 menuItem.buttonAuthorityIds = []; | ||||||
|  |                 node.buttonInfoList.forEach((nodeItem: { checked: boolean }) => { | ||||||
|  |                   nodeItem.checked = false; | ||||||
|  |                 }); | ||||||
|  |               } | ||||||
|  |             } | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |       }); | ||||||
|  |     } else { | ||||||
|  |       // 数组为空的时候 | ||||||
|  |       const buttonAuthorityIds = []; | ||||||
|  |       if (item) { | ||||||
|  |         // 全选 | ||||||
|  |         buttonAuthorityIds.push(item.functionButtonId); | ||||||
|  |       } else { | ||||||
|  |         node.buttonInfoList.forEach((nodeItem: { id: any; checked: boolean; _isHalfChecked: boolean }) => { | ||||||
|  |           if (origin.all) { | ||||||
|  |             buttonAuthorityIds.push(nodeItem.id); | ||||||
|  |             nodeItem.checked = true; | ||||||
|  |           } | ||||||
|  |         }); | ||||||
|  |       } | ||||||
|  |       const obj: any = { | ||||||
|  |         authorityId: origin.id, | ||||||
|  |         buttonAuthorityIds | ||||||
|  |       }; | ||||||
|  |       this.authority.push(obj); | ||||||
|  |     } | ||||||
|  |     this.checkTreeNode(node, origin); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   addDict(item: { checked: any; itemId: any; itemKey: any }, dictItem: { dictId: any }, origin: { id: any }, node: any) { | ||||||
|  |     if (this.authority.length) { | ||||||
|  |       // 判断此菜单权限是否已经存在权限列表中 | ||||||
|  |       if (this.authority.filter(authItem => authItem.authorityId === origin.id).length) { | ||||||
|  |         // 当前操作菜单id存在权限列表里 | ||||||
|  |         this.authority.forEach((menuItem, menuIndex) => { | ||||||
|  |           if (menuItem.authorityId === origin.id) { | ||||||
|  |             menuItem.dataAuthority = menuItem.dataAuthority || []; // 防止属性不存在,给属性指定数据类型 | ||||||
|  |             if (item.checked) { | ||||||
|  |               if (menuItem.dataAuthority.filter((ele: { dictItemId: any }) => ele.dictItemId === item.itemId).length === 0) { | ||||||
|  |                 // 如果该按钮在数据权限数组中不存在 | ||||||
|  |                 menuItem.dataAuthority.push({ dictItemId: item.itemId, itemKey: item.itemKey, dictId: dictItem.dictId }); | ||||||
|  |               } | ||||||
|  |             } else { | ||||||
|  |               if (menuItem.dataAuthority && menuItem.dataAuthority.length) { | ||||||
|  |                 menuItem.dataAuthority.forEach((btnItem: { dictItemId: any }, index: any) => { | ||||||
|  |                   if (btnItem.dictItemId === item.itemId) { | ||||||
|  |                     menuItem.dataAuthority.splice(index, 1); | ||||||
|  |                   } | ||||||
|  |                 }); | ||||||
|  |               } | ||||||
|  |             } | ||||||
|  |           } | ||||||
|  |         }); | ||||||
|  |       } else { | ||||||
|  |         // 当前操作菜单id不存在权限列表里 | ||||||
|  |         const dataAuthority = []; | ||||||
|  |         dataAuthority.push({ dictItemId: item.itemId, itemKey: item.itemKey, dictId: dictItem.dictId }); | ||||||
|  |         const obj: any = { | ||||||
|  |           authorityId: origin.id, | ||||||
|  |           dataAuthority | ||||||
|  |         }; | ||||||
|  |         this.authority.push(obj); | ||||||
|  |       } | ||||||
|  |     } else { | ||||||
|  |       // 数组为空的时候 | ||||||
|  |       const dataAuthority = []; | ||||||
|  |       dataAuthority.push({ dictItemId: item.itemId, itemKey: item.itemKey, dictId: dictItem.dictId }); | ||||||
|  |       const obj: any = { | ||||||
|  |         authorityId: origin.id, | ||||||
|  |         dataAuthority | ||||||
|  |       }; | ||||||
|  |       this.authority.push(obj); | ||||||
|  |     } | ||||||
|  |     this.checkTreeNode(node, origin); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   checkTreeNode(node: any, origin: { id: any }) { | ||||||
|  |     const checkedNode: any = this.nzTreeComponent.getCheckedNodeList(); | ||||||
|  |     const allCheckedArr: any[] = []; | ||||||
|  |     this.overTree(checkedNode, allCheckedArr); | ||||||
|  |     this.authority.forEach(authItem => { | ||||||
|  |       if (authItem.authorityId === origin.id) { | ||||||
|  |         if ( | ||||||
|  |           (authItem.buttonAuthorityIds && authItem.buttonAuthorityIds.length) || | ||||||
|  |           (authItem.dataAuthority && authItem.dataAuthority.length) | ||||||
|  |         ) { | ||||||
|  |           if (allCheckedArr.indexOf(node.key) === -1) { | ||||||
|  |             allCheckedArr.push(node.key); | ||||||
|  |           } | ||||||
|  |         } else { | ||||||
|  |           if (allCheckedArr.indexOf(node.key) !== -1) { | ||||||
|  |             allCheckedArr.forEach((ele, index) => { | ||||||
|  |               if (ele === origin.id) { | ||||||
|  |                 allCheckedArr.splice(index, 1); | ||||||
|  |               } | ||||||
|  |             }); | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     }); | ||||||
|  |     this.defaultCheckedKeys = allCheckedArr; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   overTree(children: any[], a: any[]) { | ||||||
|  |     children.forEach(item => { | ||||||
|  |       a.push(item.key); | ||||||
|  |       if (item.isLeaf) { | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|  |       if (item.children && item.children.length) { | ||||||
|  |         this.overTree(item.children, a); | ||||||
|  |       } | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   addDisabledTree(arr: any[]) { | ||||||
|  |     arr.forEach((item: any) => { | ||||||
|  |       item.disableCheckbox = true; | ||||||
|  |       if (item.isLeaf) { | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|  |       if (item.children && item.children.length) { | ||||||
|  |         this.addDisabledTree(item.children); | ||||||
|  |       } | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  |   addDisabledLeafTree(arr: any[]) { | ||||||
|  |     arr.forEach((item: any) => { | ||||||
|  |       if (item.isLeaf) { | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|  |       item.disableCheckbox = true; | ||||||
|  |       if (item.children && item.children.length) { | ||||||
|  |         this.addDisabledLeafTree(item.children); | ||||||
|  |       } | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  |   nzEvent(event: any): void { | ||||||
|  |     this.origin = event.node.origin; | ||||||
|  |     this.node = event.node.origin; | ||||||
|  |     if (!event.node.origin.isLeaf) { | ||||||
|  |       event.node.isExpanded = !event.node.isExpanded; | ||||||
|  |     } else { | ||||||
|  |       this.initButtonList(event.node.key, event.node.origin); | ||||||
|  |       // this.initDictList(event.node.key, event.node.origin); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   washTree() { | ||||||
|  |     const authorityMenu: any[] = []; // this.authority | ||||||
|  |     const tempAuthorityIdDTOListMenu: any[] = []; | ||||||
|  |     const checkedNode: any = this.nzTreeComponent.getCheckedNodeList(); | ||||||
|  |     const halfCheckedNode: any = this.nzTreeComponent.getHalfCheckedNodeList(); | ||||||
|  |     this.authorityAssistId = []; | ||||||
|  |     halfCheckedNode.forEach((item: { key: any }) => { | ||||||
|  |       authorityMenu.push({ authorityId: item.key, isUpdateAuthority: 0 }); | ||||||
|  |       tempAuthorityIdDTOListMenu.push(item.key); | ||||||
|  |     }); | ||||||
|  |     this.overWashTree(checkedNode, tempAuthorityIdDTOListMenu, authorityMenu); | ||||||
|  |     if (this.authority && this.authority.length) { | ||||||
|  |       this.authority.forEach(item => { | ||||||
|  |         item.isUpdateAuthority = 1; | ||||||
|  |         if (tempAuthorityIdDTOListMenu.indexOf(item.authorityId) !== -1) { | ||||||
|  |           tempAuthorityIdDTOListMenu.forEach((oldItem, oldIndex) => { | ||||||
|  |             if (oldItem === item.authorityId) { | ||||||
|  |               authorityMenu[oldIndex] = item; | ||||||
|  |             } | ||||||
|  |           }); | ||||||
|  |         } | ||||||
|  |       }); | ||||||
|  |     } | ||||||
|  |     const result = { | ||||||
|  |       authority: authorityMenu, | ||||||
|  |       authorityAssistId: this.authorityAssistId | ||||||
|  |     }; | ||||||
|  |     this.changeData.emit(result); | ||||||
|  |     return result; | ||||||
|  |   } | ||||||
|  |   overWashTree(children: any[], tempAuthorityIdDTOListMenu: any[], authorityMenu: any[]) { | ||||||
|  |     children.forEach((item: any) => { | ||||||
|  |       this.authorityAssistId.push(item.key); | ||||||
|  |       tempAuthorityIdDTOListMenu.push(item.key); | ||||||
|  |       authorityMenu.push({ authorityId: item.key, isUpdateAuthority: 1 }); | ||||||
|  |       if (item.isLeaf) { | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|  |       if (item.children) { | ||||||
|  |         this.overWashTree(item.children, tempAuthorityIdDTOListMenu, authorityMenu); | ||||||
|  |       } | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   initButtonList(id: any, origin: any) { | ||||||
|  |     if (origin.expanded) { | ||||||
|  |       origin.children.forEach((item: any, index: number) => { | ||||||
|  |         if (item.selected) { | ||||||
|  |           if (origin.checked) { | ||||||
|  |             this.authority.splice(index, 1); | ||||||
|  |             const buttonAuthorityIds: any = []; | ||||||
|  |             item.buttonInfoList.forEach((btnItem: any) => { | ||||||
|  |               btnItem.checked = true; | ||||||
|  |               buttonAuthorityIds.push(btnItem.functionButtonId); | ||||||
|  |             }); | ||||||
|  |             this.authority.push({ authorityId: origin.key, buttonAuthorityIds, isUpdateAuthority: 1 }); | ||||||
|  |           } else { | ||||||
|  |             this.authority.splice(index, 1); | ||||||
|  |             item.buttonInfoList.forEach((btnItem: any) => { | ||||||
|  |               btnItem.checked = false; | ||||||
|  |             }); | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |       }); | ||||||
|  |     } | ||||||
|  |     const params = { | ||||||
|  |       id | ||||||
|  |     }; | ||||||
|  |     this.service.request(this.service.$api_getFunctionButtonInfo, params).subscribe(res => { | ||||||
|  |       if (res) { | ||||||
|  |         origin.buttonInfoList = res; | ||||||
|  |         origin.all = false; | ||||||
|  |         console.log(origin); | ||||||
|  |  | ||||||
|  |         // 判断此菜单下是否已有此按钮权限 | ||||||
|  |         this.againGetBtn(id, origin); | ||||||
|  |       } | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  |   // 再次请求,需要判断暂存权限数组是否已有此权限 | ||||||
|  |   againGetBtn(id: any, origin: any) { | ||||||
|  |     if (this.authority && this.authority.length === 0) { | ||||||
|  |       const buttonAuthorityIds: any = []; | ||||||
|  |       if (origin.checked) { | ||||||
|  |         origin.buttonInfoList.forEach((btnItem: { functionButtonId: any; checked: boolean }) => { | ||||||
|  |           btnItem.checked = true; | ||||||
|  |           buttonAuthorityIds.push(btnItem.functionButtonId); | ||||||
|  |         }); | ||||||
|  |         this.authority.push({ authorityId: origin.key, buttonAuthorityIds, isUpdateAuthority: 1 }); | ||||||
|  |       } | ||||||
|  |     } else { | ||||||
|  |       if (origin.checked) { | ||||||
|  |         //菜单勾选情况下 | ||||||
|  |         if (this.authority.some(item => item.authorityId === id)) { | ||||||
|  |           this.authority.forEach(item => { | ||||||
|  |             if (item.authorityId === id) { | ||||||
|  |               // 如果当前菜单Id存在权限列表里,并且等于暂存权限数组的Id | ||||||
|  |               if (item.buttonAuthorityIds && item.buttonAuthorityIds.length) { | ||||||
|  |                 // 如果当前菜单Id权限数组不为空 | ||||||
|  |                 origin.buttonInfoList.forEach((btnItem: { functionButtonId: any; checked: boolean }) => { | ||||||
|  |                   // 判断已有权限id是否存在 | ||||||
|  |                   if (item.buttonAuthorityIds.indexOf(btnItem.functionButtonId) !== -1) { | ||||||
|  |                     btnItem.checked = true; | ||||||
|  |                   } else { | ||||||
|  |                     btnItem.checked = false; | ||||||
|  |                   } | ||||||
|  |                 }); | ||||||
|  |               } | ||||||
|  |             } | ||||||
|  |           }); | ||||||
|  |         } else { | ||||||
|  |           this.authority.push({ authorityId: origin.key, buttonAuthorityIds: [], isUpdateAuthority: 1 }); | ||||||
|  |           this.authority.forEach(item => { | ||||||
|  |             origin.buttonInfoList.forEach((btnItem: { functionButtonId: any; checked: boolean }) => { | ||||||
|  |               btnItem.checked = true; | ||||||
|  |               item.buttonAuthorityIds.push(btnItem.functionButtonId); | ||||||
|  |             }); | ||||||
|  |           }); | ||||||
|  |         } | ||||||
|  |       } else { | ||||||
|  |         // 菜单未勾选,要删除权限 | ||||||
|  |         this.authority.forEach((item, index) => { | ||||||
|  |           if (item.authorityId === id) { | ||||||
|  |             // 如果当前菜单Id存在权限列表里,并且等于暂存权限数组的Id | ||||||
|  |             this.authority.splice(index, 1); | ||||||
|  |             origin.buttonInfoList.forEach((btnItem: { functionButtonId: any; checked: boolean }) => { | ||||||
|  |               btnItem.checked = false; | ||||||
|  |             }); | ||||||
|  |           } | ||||||
|  |         }); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   initDictList(id: any, origin: any) { | ||||||
|  |     const params = { | ||||||
|  |       id | ||||||
|  |     }; | ||||||
|  |     this.service.request(this.service.$api_getFunctionDataInfo, params).subscribe(res => { | ||||||
|  |       if (res) { | ||||||
|  |         origin.dictList = res; | ||||||
|  |         // 判断此菜单下是否已有此按钮权限 | ||||||
|  |         this.againGetDict(id, origin); | ||||||
|  |       } | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  |   // 再次请求,需要判断暂存权限数组是否已有此权限 | ||||||
|  |   againGetDict(id: any, origin: any) { | ||||||
|  |     if (this.authority.length === 0) { | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|  |     this.authority.forEach(item => { | ||||||
|  |       if (item.authorityId === id) { | ||||||
|  |         // 如果当前菜单Id等于暂存权限数组的Id | ||||||
|  |         if (item.dataAuthority && item.dataAuthority.length) { | ||||||
|  |           // 如果当前菜单Id权限数组不为空 | ||||||
|  |           origin.dictList.forEach((ele: { dictItem: any[] }) => { | ||||||
|  |             // 判断已有权限id是否存在 | ||||||
|  |             ele.dictItem.forEach((dictItem: { itemId: any; checked: boolean; cheked: boolean }) => { | ||||||
|  |               item.dataAuthority.forEach((dataItem: { dictItemId: any }) => { | ||||||
|  |                 if (dataItem.dictItemId === dictItem.itemId) { | ||||||
|  |                   dictItem.checked = true; | ||||||
|  |                 } else { | ||||||
|  |                   dictItem.cheked = false; | ||||||
|  |                 } | ||||||
|  |               }); | ||||||
|  |             }); | ||||||
|  |           }); | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  | } | ||||||
| @ -37,6 +37,7 @@ import { SmsTemplateComponent } from './components/sms-template/sms-template.com | |||||||
| import { OrganizationManagementComponent } from './components/organization-management/organization-management.component'; | import { OrganizationManagementComponent } from './components/organization-management/organization-management.component'; | ||||||
| import { OrganizationModalComponent } from './components/organization-management/organization-modal/organization-modal.component'; | import { OrganizationModalComponent } from './components/organization-management/organization-modal/organization-modal.component'; | ||||||
| import { ApiAuthModalComponent } from './components/organization-management/api-auth-modal/api-auth-modal.component'; | import { ApiAuthModalComponent } from './components/organization-management/api-auth-modal/api-auth-modal.component'; | ||||||
|  | import { MenuTreeComponent } from './components/organization-management/menu-tree/menu-tree.component'; | ||||||
|  |  | ||||||
| const COMPONENTS = [ | const COMPONENTS = [ | ||||||
|   StaffManagementComponent, |   StaffManagementComponent, | ||||||
| @ -66,10 +67,12 @@ const NOTROUTECOMPONENTS = [ | |||||||
|   CartConfigActionModalComponent, |   CartConfigActionModalComponent, | ||||||
|   SettingRoleEditComponent, |   SettingRoleEditComponent, | ||||||
|   SettingMenuComponent, |   SettingMenuComponent, | ||||||
|   OrganizationModalComponent |   OrganizationModalComponent, | ||||||
|  |   ApiAuthModalComponent, | ||||||
|  |   MenuTreeComponent | ||||||
| ]; | ]; | ||||||
| @NgModule({ | @NgModule({ | ||||||
|   declarations: [...COMPONENTS, ...NOTROUTECOMPONENTS, ApiAuthModalComponent], |   declarations: [...COMPONENTS, ...NOTROUTECOMPONENTS], | ||||||
|   imports: [CommonModule, SysSettingRoutingModule, SharedModule, DynamicSettingModule] |   imports: [CommonModule, SysSettingRoutingModule, SharedModule, DynamicSettingModule] | ||||||
| }) | }) | ||||||
| export class SysSettingModule {} | export class SysSettingModule {} | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user