diff --git a/src/app/system-management/role/addrole/addrole.component.html b/src/app/system-management/role/addrole/addrole.component.html index a986b7b..94f160e 100644 --- a/src/app/system-management/role/addrole/addrole.component.html +++ b/src/app/system-management/role/addrole/addrole.component.html @@ -19,20 +19,21 @@ - + \ No newline at end of file diff --git a/src/app/system-management/role/addrole/addrole.component.ts b/src/app/system-management/role/addrole/addrole.component.ts index f2ff54e..e65d39c 100644 --- a/src/app/system-management/role/addrole/addrole.component.ts +++ b/src/app/system-management/role/addrole/addrole.component.ts @@ -1,18 +1,21 @@ -import { Component, OnInit, Input } from '@angular/core'; +import { Component, OnInit, Input,ViewChild } from '@angular/core'; import { NzModalRef } from 'ng-zorro-antd/modal'; -import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { FormBuilder, FormGroup, Validators, } from '@angular/forms'; import { HttpClient } from '@angular/common/http'; import { TreeService } from 'src/app/service/tree.service'; +import { NzTreeComponent } from 'ng-zorro-antd/tree'; @Component({ selector: 'app-addrole', templateUrl: './addrole.component.html', styleUrls: ['./addrole.component.scss'] }) export class AddroleComponent implements OnInit { - + @ViewChild('nzTreeComponent', { static: false }) nzTreeComponent!: NzTreeComponent; + @Input() data?: any; + @Input() nodes?: any; @Input() title?: string; @Input() subtitle?: string; - @Input() nodes?: any; + validateForm!: FormGroup; constructor(private modal: NzModalRef, private fb: FormBuilder, private http: HttpClient, private toTree: TreeService) { } @@ -23,10 +26,10 @@ export class AddroleComponent implements OnInit { this.validateForm = this.fb.group({ name: [null, [Validators.required]], power: [null, [Validators.required]], - // menus: [null] + menus: [null] }); } - + totalCount getAllMenus() { let params = { diff --git a/src/app/system-management/role/editrole/editrole.component.html b/src/app/system-management/role/editrole/editrole.component.html index b6b040b..38539e9 100644 --- a/src/app/system-management/role/editrole/editrole.component.html +++ b/src/app/system-management/role/editrole/editrole.component.html @@ -16,21 +16,21 @@ - + + \ No newline at end of file diff --git a/src/app/system-management/role/editrole/editrole.component.ts b/src/app/system-management/role/editrole/editrole.component.ts index a215613..3f9b4ee 100644 --- a/src/app/system-management/role/editrole/editrole.component.ts +++ b/src/app/system-management/role/editrole/editrole.component.ts @@ -20,15 +20,33 @@ export class EditroleComponent implements OnInit { ngOnInit(): void { this.nodes.length != 0 ? null : this.getAllMenus() this.multipleValue = this.data.grantedPermissions + this.getMenus() this.validateForm = this.fb.group({ name: [null, [Validators.required]], power: [null, [Validators.required]], - // menus: [null] + menus: [null] }); if (this.optionList.length == 0) { this.loadMore() } } + getMenus() { + let params = { + Id: this.data.id, + } + this.http.get('/api/services/app/Role/Get', { + params: params + }).subscribe((data: any) => { + // console.log(666, data) + let arr = [] + data.result.menus.forEach(element => { + arr.push(element.id) + }); + this.validateForm.patchValue({ + menus: arr + }); + }) + } totalCount getAllMenus() { let params = { diff --git a/src/app/system-management/role/role.component.html b/src/app/system-management/role/role.component.html index ef1935f..722f951 100644 --- a/src/app/system-management/role/role.component.html +++ b/src/app/system-management/role/role.component.html @@ -29,7 +29,7 @@ 编辑 - 分配菜单 + 删除 diff --git a/src/app/system-management/role/role.component.ts b/src/app/system-management/role/role.component.ts index f9549e7..6e19603 100644 --- a/src/app/system-management/role/role.component.ts +++ b/src/app/system-management/role/role.component.ts @@ -52,7 +52,7 @@ export class RoleComponent implements OnInit { this.http.get('/api/services/app/Menu/GetAll', { params: params }).subscribe((data: any) => { - console.log(666, data) + // console.log(666, data) this.totalCount = data.result.totalCount data.result.items.forEach(element => { element.key = element.id @@ -86,8 +86,20 @@ export class RoleComponent implements OnInit { DisplayName: instance.validateForm.value.name, grantedPermissions: arr } - this.http.post('/api/services/app/Role/Create', body).subscribe(data => { + let body2=instance.validateForm.value.menus + this.http.post('/api/services/app/Role/Create', body).subscribe((data:any) => { resolve(data) + this.http.post('/api/services/app/Role/SetRoleMenus', body2, { + params: { + roleId: data.result.id + } + }).subscribe(data => { + resolve(data) + + // this.message.create('success', '分配成功!'); + + return true + }) this.message.create('success', '创建成功!'); this.getAllRoles() return true @@ -103,7 +115,7 @@ export class RoleComponent implements OnInit { modal.afterOpen.subscribe(() => console.log('[afterOpen] emitted!')); modal.afterClose.subscribe(result => console.log('[afterClose] The result is:', result)); } - + edit(item) { const modal = this.modal.create({ nzTitle: '编辑角色', @@ -131,8 +143,20 @@ export class RoleComponent implements OnInit { DisplayName: instance.validateForm.value.name, grantedPermissions: arr } - this.http.put('/api/services/app/Role/Update', body).subscribe(data => { + let body2=instance.validateForm.value.menus + this.http.put('/api/services/app/Role/Update', body).subscribe((data:any) => { resolve(data) + this.http.post('/api/services/app/Role/SetRoleMenus', body2, { + params: { + roleId: data.result.id + } + }).subscribe(data => { + resolve(data) + + // this.message.create('success', '分配成功!'); + + return true + }) this.message.create('success', '修改成功!'); this.getAllRoles() return true