From 07f0c3087d374a484a4f5a22cd1945c18ae57845 Mon Sep 17 00:00:00 2001 From: cpf <1105965053@qq.com> Date: Mon, 27 Jun 2022 14:30:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8F=9C=E5=8D=95=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../role/addrole/addrole.component.html | 21 +++++++------- .../role/addrole/addrole.component.ts | 15 ++++++---- .../role/editrole/editrole.component.html | 20 ++++++------- .../role/editrole/editrole.component.ts | 20 ++++++++++++- .../system-management/role/role.component.ts | 28 ++++++++++++++++++- 5 files changed, 76 insertions(+), 28 deletions(-) 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.ts b/src/app/system-management/role/role.component.ts index f9549e7..bd2488d 100644 --- a/src/app/system-management/role/role.component.ts +++ b/src/app/system-management/role/role.component.ts @@ -86,8 +86,21 @@ export class RoleComponent implements OnInit { DisplayName: instance.validateForm.value.name, grantedPermissions: arr } + let body2=instance.validateForm.value.menus this.http.post('/api/services/app/Role/Create', body).subscribe(data => { resolve(data) + this.http.post('/api/services/app/Role/SetRoleMenus', body2, { + params: { + roleId: data.result.id + } + }).subscribe(data => { + resolve(data) + console.log(data,8252); + + // this.message.create('success', '分配成功!'); + + return true + }) this.message.create('success', '创建成功!'); this.getAllRoles() return true @@ -103,7 +116,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 +144,21 @@ export class RoleComponent implements OnInit { DisplayName: instance.validateForm.value.name, grantedPermissions: arr } + let body2=instance.validateForm.value.menus this.http.put('/api/services/app/Role/Update', body).subscribe(data => { resolve(data) + this.http.post('/api/services/app/Role/SetRoleMenus', body2, { + params: { + roleId: data.result.id + } + }).subscribe(data => { + resolve(data) + console.log(data,8252); + + // this.message.create('success', '分配成功!'); + + return true + }) this.message.create('success', '修改成功!'); this.getAllRoles() return true