diff --git a/src/app/system-management/role/editrole/editrole.component.ts b/src/app/system-management/role/editrole/editrole.component.ts index 474dc53..8213119 100644 --- a/src/app/system-management/role/editrole/editrole.component.ts +++ b/src/app/system-management/role/editrole/editrole.component.ts @@ -10,26 +10,30 @@ import { HttpClient } from '@angular/common/http'; export class EditroleComponent implements OnInit { @Input() data?: any; + @Input() optionList?: any; + validateForm!: FormGroup; constructor(private modal: NzModalRef, private fb: FormBuilder, private http: HttpClient) { } - multipleValue:any + multipleValue: any ngOnInit(): void { this.multipleValue = this.data.grantedPermissions - this.loadMore(); this.validateForm = this.fb.group({ name: [null, [Validators.required]], power: [null, [Validators.required]] }); + if (this.optionList.length == 0) { + this.loadMore() + } } destroyModal(): void { this.modal.destroy({ data: 'this the result data' }); } - - optionList = []; + + // optionList = []; //获取权限列表 loadMore() { - this.http.get('/api/services/app/Role/GetAllPermissions').subscribe((data:any) => { + this.http.get('/api/services/app/Role/GetAllPermissions').subscribe((data: any) => { this.optionList = data.result.items this.modal.containerInstance.config.nzOkLoading = false // console.log('所有权限',data) diff --git a/src/app/system-management/role/role.component.ts b/src/app/system-management/role/role.component.ts index 35a6e10..39ae8ee 100644 --- a/src/app/system-management/role/role.component.ts +++ b/src/app/system-management/role/role.component.ts @@ -17,6 +17,8 @@ export class RoleComponent implements OnInit { ngOnInit(): void { this.getAllRoles() + + this.loadMore() } listOfData: any[] = []; @@ -68,7 +70,15 @@ export class RoleComponent implements OnInit { // Return a result when closed modal.afterClose.subscribe(result => console.log('[afterClose] The result is:', result)); } - + optionList = []; + //获取权限列表 + loadMore() { + this.http.get('/api/services/app/Role/GetAllPermissions').subscribe((data: any) => { + this.optionList = data.result.items + // this.modal.containerInstance.config.nzOkLoading = false + // console.log('所有权限',data) + }) + } edit(item) { const modal = this.modal.create({ @@ -76,9 +86,10 @@ export class RoleComponent implements OnInit { nzContent: EditroleComponent, nzViewContainerRef: this.viewContainerRef, nzWidth: 325, - nzOkLoading: true, + // nzOkLoading: true, nzComponentParams: { - data: item + data: item, + optionList: this.optionList }, nzOnOk: async () => { if (instance.validateForm.valid) { diff --git a/src/app/system-management/user/edituser/edituser.component.ts b/src/app/system-management/user/edituser/edituser.component.ts index 02a736c..3b03612 100644 --- a/src/app/system-management/user/edituser/edituser.component.ts +++ b/src/app/system-management/user/edituser/edituser.component.ts @@ -12,6 +12,8 @@ import { TreeService } from 'src/app/service/tree.service'; export class EdituserComponent implements OnInit { @Input() data?: any; + @Input() listOfData?: any; + @Input() nodes?: any; validateForm!: FormGroup; constructor(private modal: NzModalRef, private fb: FormBuilder, private http: HttpClient, private toTree: TreeService) { } @@ -23,15 +25,20 @@ export class EdituserComponent implements OnInit { role: [null, [Validators.required]], phonenum: [null, [Validators.required]] }); - Promise.all([this.getAllRoles(), this.getAllOrganization()]).then(()=>{ - this.modal.containerInstance.config.nzOkLoading = false - }) + // Promise.all([this.getAllRoles(), this.getAllOrganization()]).then(()=>{ + // this.modal.containerInstance.config.nzOkLoading = false + // }) + if(this.listOfData.length == 0){ + this.getAllRoles() + } + if(this.nodes.length == 0){ + this.getAllOrganization() + } } destroyModal(): void { this.modal.destroy({ data: 'this the result data' }); } - listOfData: any[] = []; //获取角色列表 async getAllRoles() { @@ -43,7 +50,7 @@ export class EdituserComponent implements OnInit { }) } //获取所有组织机构 - nodes: any = [] + async getAllOrganization() { let OrganizationUnitId = sessionStorage.getItem('isGasStation') == 'true' ? JSON.parse(sessionStorage.getItem('userdataOfgasstation')).organization.id : JSON.parse(sessionStorage.getItem('userdata')).organization.id let params = { diff --git a/src/app/system-management/user/user.component.ts b/src/app/system-management/user/user.component.ts index f18c41b..b19ef58 100644 --- a/src/app/system-management/user/user.component.ts +++ b/src/app/system-management/user/user.component.ts @@ -5,6 +5,7 @@ import { AdduserComponent } from './adduser/adduser.component'; import { NzMessageService } from 'ng-zorro-antd/message'; import { HttpClient } from '@angular/common/http'; import { EdituserComponent } from './edituser/edituser.component'; +import { TreeService } from 'src/app/service/tree.service'; @Component({ selector: 'app-user', templateUrl: './user.component.html', @@ -12,13 +13,16 @@ import { EdituserComponent } from './edituser/edituser.component'; }) export class UserComponent implements OnInit { validateForm!: FormGroup; - constructor(private fb: FormBuilder, private modal: NzModalService, private viewContainerRef: ViewContainerRef, private message: NzMessageService, private http: HttpClient) { } + constructor(private fb: FormBuilder, private modal: NzModalService, private viewContainerRef: ViewContainerRef, private message: NzMessageService, private http: HttpClient, private toTree: TreeService) { } ngOnInit(): void { this.validateForm = this.fb.group({ search: [null] }); this.getAllUsers() + + this.getAllRoles() + this.getAllOrganization() } @@ -48,6 +52,37 @@ export class UserComponent implements OnInit { this.getAllUsers() } + listOfData:any = [] + //获取角色列表 + async getAllRoles() { + await new Promise((resolve, reject) => { + this.http.get('/api/services/app/Role/GetAll').subscribe((data: any) => { + resolve(data) + this.listOfData = data.result.items + }) + }) + } + //获取所有组织机构 + nodes: any = [] + async getAllOrganization() { + let OrganizationUnitId = sessionStorage.getItem('isGasStation') == 'true' ? JSON.parse(sessionStorage.getItem('userdataOfgasstation')).organization.id : JSON.parse(sessionStorage.getItem('userdata')).organization.id + let params = { + OrganizationUnitId: OrganizationUnitId, + IsContainsChildren: "true" + } + await new Promise((resolve, reject) => { + this.http.get('/api/services/app/Organization/GetAll', { + params: params + }).subscribe((data: any) => { + data.result.items.forEach(element => { + element.key = element.id + element.title = element.displayName + }); + this.nodes = [...this.toTree.toTree(data.result.items)] + resolve(data) + }) + }) + } //搜索框提交 @@ -115,12 +150,13 @@ export class UserComponent implements OnInit { nzContent: EdituserComponent, nzViewContainerRef: this.viewContainerRef, nzWidth: 288, - nzOkLoading: true, + // nzOkLoading: true, nzComponentParams: { data: data, + listOfData:this.listOfData, + nodes:this.nodes }, nzOnOk: async () => { - console.log('hhhhhhh', instance.validateForm) if (instance.validateForm.valid) { await new Promise(resolve => { let body = {