edit
This commit is contained in:
		| @ -1,6 +1,7 @@ | ||||
| import { AfterViewInit, ChangeDetectorRef, Component, OnChanges, OnInit, ViewChild } from '@angular/core'; | ||||
| import { SFComponent, SFSchema, SFSchemaEnumType, SFUISchema } from '@delon/form'; | ||||
| import { _HttpClient } from '@delon/theme'; | ||||
| import { EAEnvironmentService } from '@shared'; | ||||
| import { NzModalRef } from 'ng-zorro-antd/modal'; | ||||
| import { of } from 'rxjs'; | ||||
| import { delay, map } from 'rxjs/operators'; | ||||
| @ -26,16 +27,12 @@ export class SettingRoleEditComponent implements OnInit { | ||||
|   schema!: SFSchema; | ||||
|   authority: any[] = []; | ||||
|   roleTplData: any[] = []; | ||||
|   appId = ''; | ||||
|   ui!: SFUISchema; | ||||
|   constructor(private modal: NzModalRef, public service: SystemService, public http: _HttpClient, private cdr: ChangeDetectorRef) {} | ||||
|   constructor(private modal: NzModalRef, public service: SystemService, private envSrv: EAEnvironmentService) {} | ||||
|  | ||||
|   ngOnInit(): void { | ||||
|     console.log('i', this.i, this.source); | ||||
|     if (this.i.id) { | ||||
|       this.getRoleInfo(); | ||||
|     } else { | ||||
|       this.getTplList(); | ||||
|     } | ||||
|     if (this.source === '') { | ||||
|       this.initSF(); | ||||
| @ -97,9 +94,7 @@ export class SettingRoleEditComponent implements OnInit { | ||||
|       }) | ||||
|     ); | ||||
|   } | ||||
|   getTplList() { | ||||
|     // this.menu.getAllFunction(); | ||||
|   } | ||||
|  | ||||
|   getRoleInfo() { | ||||
|     const params = { | ||||
|       id: this.i.id | ||||
| @ -111,7 +106,6 @@ export class SettingRoleEditComponent implements OnInit { | ||||
|       if (this.source === '') { | ||||
|         this.initSF(); | ||||
|       } | ||||
|       this.getTplList(); | ||||
|     }); | ||||
|   } | ||||
|   getData(res: { authority: any[]; authorityAssistId: any[] }) { | ||||
| @ -122,30 +116,39 @@ export class SettingRoleEditComponent implements OnInit { | ||||
|     this.modal.destroy(); | ||||
|   } | ||||
|   sure() { | ||||
|     this.menu.washTree(); | ||||
|     if (this.authorityAssistId.length === 0) { | ||||
|       this.service.msgSrv.warning('请选择权限!'); | ||||
|       return; | ||||
|     } | ||||
|     // this.menu.washTree(); | ||||
|     // if (this.authorityAssistId.length === 0) { | ||||
|     //   this.service.msgSrv.warning('请选择权限!'); | ||||
|     //   return; | ||||
|     // } | ||||
|     console.log(this.menu.nzTreeComponent.getCheckedNodeList()); | ||||
|     const selectedFun = this.menu?.nzTreeComponent?.getCheckedNodeList()?.map(node => ({ authorityId: node.key })); | ||||
|     const authorityAssistId = selectedFun?.map(node => node.authorityId); | ||||
|     const params: any = { | ||||
|       id: this.i.id, | ||||
|       ...this.sf.value, | ||||
|       authority: this.authority, | ||||
|       authorityAssistId: this.authorityAssistId | ||||
|       authority: selectedFun, | ||||
|       authorityAssistId: authorityAssistId | ||||
|     }; | ||||
|     if (this.sf) { | ||||
|       this.appList.forEach(item => { | ||||
|         if (item.appId === this.sf.value.appId) { | ||||
|           params.tenantId = item.tenantId; | ||||
|         } | ||||
|       }); | ||||
|     } | ||||
|     delete params.tplId; | ||||
|     // if (this.sf) { | ||||
|     //   this.appList.forEach(item => { | ||||
|     //     if (item.appId === this.sf.value.appId) { | ||||
|     //       params.tenantId = item.tenantId; | ||||
|     //     } | ||||
|     //   }); | ||||
|     // } | ||||
|     // delete params.tplId; | ||||
|     if (this.i.id === 0) { | ||||
|       delete params.id; | ||||
|     } | ||||
|     this.service.request(this.service.$api_updateRoleInfo, params).subscribe(res => { | ||||
|       this.modal.close(true); | ||||
|     }); | ||||
|     if (this.i.id) { | ||||
|       this.service.request(this.service.$api_update_role, params).subscribe(res => { | ||||
|         this.modal.close(true); | ||||
|       }); | ||||
|     } else { | ||||
|       this.service.request(this.service.$api_save_role, params).subscribe(res => { | ||||
|         this.modal.close(true); | ||||
|       }); | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -1,5 +1,6 @@ | ||||
| import { ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, OnInit, Output, ViewChild } from '@angular/core'; | ||||
| import { ModalHelper, _HttpClient } from '@delon/theme'; | ||||
| import { EAEnvironmentService } from '@shared'; | ||||
| import { NzFormatEmitEvent, NzTreeNodeOptions } from 'ng-zorro-antd/core/tree'; | ||||
| import { NzTreeComponent } from 'ng-zorro-antd/tree'; | ||||
| import { SystemService } from '../../../services/system.service'; | ||||
| @ -18,7 +19,7 @@ export class SettingMenuComponent implements OnInit { | ||||
|   defaultSelectedKeys: any[] = []; | ||||
|   defaultExpandedKeys: any[] = []; | ||||
|   defaultCheckedKeys: any[] = []; | ||||
|   functionList: any[] = Funcs; | ||||
|   functionList: any[] = []; | ||||
|   selectProject: any = {}; | ||||
|   selectApp: any = {}; | ||||
|   @Input() type = 'edit'; | ||||
| @ -27,7 +28,9 @@ export class SettingMenuComponent implements OnInit { | ||||
|   @Input() authorityAssistId: any[] = []; | ||||
|   @Input() roleId: any; | ||||
|   @Output() changeData = new EventEmitter(); | ||||
|   constructor(public service: SystemService, private cdr: ChangeDetectorRef) {} | ||||
|   constructor(public service: SystemService, private cdr: ChangeDetectorRef, private envSrv: EAEnvironmentService) { | ||||
|     this.getAllFunction(); | ||||
|   } | ||||
|  | ||||
|   ngOnInit() { | ||||
|     if (this.type === 'edit') { | ||||
| @ -35,16 +38,18 @@ export class SettingMenuComponent implements OnInit { | ||||
|     } | ||||
|   } | ||||
|   getAllFunction() { | ||||
|     this.service.request(this.service.$api_getAllFunctionInfoByAppId, { appId: '' }, 'POST', true, 'FORM').subscribe(res => { | ||||
|       if (this.source === 'onlyRelationAuth') { | ||||
|         this.addDisabledTree(res); | ||||
|       } else { | ||||
|         // this.addDisabledLeafTree(res); | ||||
|       } | ||||
|       this.functionList = res; | ||||
|       this.defaultCheckedKeys = this.authorityAssistId; | ||||
|       this.cdr.detectChanges(); | ||||
|     }); | ||||
|     this.service | ||||
|       .request(this.service.$api_getAllFunctionInfoByAppId, { appId: this.envSrv.env.appId }, 'POST', true, 'FORM') | ||||
|       .subscribe(res => { | ||||
|         // if (this.source === 'onlyRelationAuth') { | ||||
|         //   this.addDisabledTree(res); | ||||
|         // } else { | ||||
|         //   // this.addDisabledLeafTree(res); | ||||
|         // } | ||||
|         this.functionList = res; | ||||
|         this.defaultCheckedKeys = this.authorityAssistId; | ||||
|         this.cdr.detectChanges(); | ||||
|       }); | ||||
|   } | ||||
|   addAuthority(origin: { id: any; all: any }, node: { buttonInfoList: any[] }, item?: { checked: any; id: any }) { | ||||
|     if (this.authority.length && this.authority.filter(authItem => authItem.authorityId === origin.id).length) { | ||||
| @ -245,32 +250,34 @@ export class SettingMenuComponent implements OnInit { | ||||
|   } | ||||
|  | ||||
|   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 }); | ||||
|       tempAuthorityIdDTOListMenu.push(item.key); | ||||
|     }); | ||||
|     this.overWashTree(checkedNode, tempAuthorityIdDTOListMenu, authorityMenu); | ||||
|     if (this.authority && this.authority.length) { | ||||
|       this.authority.forEach(item => { | ||||
|         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); | ||||
|     console.log(this.nzTreeComponent.getCheckedNodeList()); | ||||
|  | ||||
|     // 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 }); | ||||
|     //   tempAuthorityIdDTOListMenu.push(item.key); | ||||
|     // }); | ||||
|     // this.overWashTree(checkedNode, tempAuthorityIdDTOListMenu, authorityMenu); | ||||
|     // if (this.authority && this.authority.length) { | ||||
|     //   this.authority.forEach(item => { | ||||
|     //     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); | ||||
|   } | ||||
|   overWashTree(children: any[], tempAuthorityIdDTOListMenu: any[], authorityMenu: any[]) { | ||||
|     children.forEach((item: any) => { | ||||
|  | ||||
| @ -35,6 +35,7 @@ export class RoleManagementComponent implements OnInit { | ||||
|     { | ||||
|       title: '创建时间', | ||||
|       index: 'createTime', | ||||
|       className: 'text-left', | ||||
|       type: 'date', | ||||
|       sort: true | ||||
|     }, | ||||
| @ -89,12 +90,19 @@ export class RoleManagementComponent implements OnInit { | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   deleteAction(item?: any) { | ||||
|   deleteAction(item: any) { | ||||
|     this.nzModalService.error({ | ||||
|       nzTitle: '确认删除?', | ||||
|       nzClosable: false, | ||||
|       nzCancelText: '取消', | ||||
|       nzOnOk: () => {} | ||||
|       nzOnOk: () => { | ||||
|         this.service.request(this.service.$api_dalete_role, [item.id]).subscribe(res => { | ||||
|           if (res) { | ||||
|             this.service.msgSrv.success('删除角色成功'); | ||||
|             this.st.load(); | ||||
|           } | ||||
|         }); | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|  | ||||
| @ -26,6 +26,14 @@ export class SystemService extends BaseService { | ||||
|  | ||||
|   // 分页获取应用角色列表 | ||||
|   $api_get_role_page = '/api/mdc/cuc/roleInfo/getAppRoleInfoList'; | ||||
|   // 新增角色 | ||||
|   $api_save_role = '/api/mdc/cuc/roleInfo/saveRoleInfo'; | ||||
|   // 编辑角色 | ||||
|   $api_update_role = '/api/mdc/cuc/roleInfo/updateRoleInfo'; | ||||
|   // 删除角色(含多个) | ||||
|   $api_dalete_role = '/api/mdc/cuc/roleInfo/removeRoleInfo'; | ||||
|   // 获取角色详情 | ||||
|   $api_getRoleInfo = '/api/mdc/cuc/roleInfo/getRoleInfo'; | ||||
|  | ||||
|   // 查询字典选项列表 | ||||
|   $api_get_dict_page = '/api/mdc/pbc/dictItems/list/page'; | ||||
| @ -45,13 +53,13 @@ export class SystemService extends BaseService { | ||||
|   // 删除CRM客户信息表 | ||||
|   $api_deletebatch_crmCustomer = '/api/mdc/crmCustomer/deletebatch'; | ||||
|  | ||||
|   $api_getAllFunctionInfoByAppId: string = ''; | ||||
|   // 获取某个应用的所有菜单 | ||||
|   $api_getAllFunctionInfoByAppId: string = '/api/mdc/cuc/functionInfo/getAllFunctionInfoByAppId'; | ||||
|   $api_getRoleTemplateInfo: string = ''; | ||||
|   $api_getFunctionButtonInfo: string = ''; | ||||
|   $api_getFunctionDataInfo: string = ''; | ||||
|   $api_getAppList: string = ''; | ||||
|   $api_getRoleTemplateListByAppId: string = ''; | ||||
|   $api_getRoleInfo: string = ''; | ||||
|   $api_updateRoleInfo: string = ''; | ||||
|   constructor(public injector: Injector) { | ||||
|     super(injector); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user