Browse Source

[完善]角色管理bug

beijing
邵佳豪 2 years ago
parent
commit
5835ed8790
  1. 2
      src/app/system-management/role/addrole/addrole.component.html
  2. 3
      src/app/system-management/role/editrole/editrole.component.ts
  3. 51
      src/app/system-management/role/role.component.ts

2
src/app/system-management/role/addrole/addrole.component.html

@ -12,7 +12,7 @@
<nz-form-label [nzSm]="6" [nzXs]="24" nzFor="权限">权限</nz-form-label> <nz-form-label [nzSm]="6" [nzXs]="24" nzFor="权限">权限</nz-form-label>
<nz-form-control> <nz-form-control>
<nz-select formControlName="power" nzPlaceHolder="请选择权限" nzMode="multiple"> <nz-select formControlName="power" nzPlaceHolder="请选择权限" nzMode="multiple">
<nz-option *ngFor="let o of optionList" [nzValue]="o" [nzLabel]="o.displayName"></nz-option> <nz-option *ngFor="let o of optionList" [nzValue]="o.name" [nzLabel]="o.displayName"></nz-option>
</nz-select> </nz-select>
<ng-template #renderTemplate> <ng-template #renderTemplate>
<nz-spin *ngIf="isLoading"></nz-spin> <nz-spin *ngIf="isLoading"></nz-spin>

3
src/app/system-management/role/editrole/editrole.component.ts

@ -18,6 +18,8 @@ export class EditroleComponent implements OnInit {
multipleValue: any multipleValue: any
ngOnInit(): void { ngOnInit(): void {
console.log(this.data)
console.log(6666,this.optionList)
this.nodes.length != 0 ? null : this.getAllMenus() this.nodes.length != 0 ? null : this.getAllMenus()
this.multipleValue = this.data.grantedPermissions this.multipleValue = this.data.grantedPermissions
this.getMenus() this.getMenus()
@ -37,7 +39,6 @@ export class EditroleComponent implements OnInit {
this.http.get('/api/services/app/Role/Get', { this.http.get('/api/services/app/Role/Get', {
params: params params: params
}).subscribe((data: any) => { }).subscribe((data: any) => {
// console.log(666, data)
let arr = [] let arr = []
data.result.menus.forEach(element => { data.result.menus.forEach(element => {
arr.push(element.id) arr.push(element.id)

51
src/app/system-management/role/role.component.ts

@ -75,20 +75,15 @@ export class RoleComponent implements OnInit {
nzMaskClosable: false, nzMaskClosable: false,
nzOnOk: async () => { nzOnOk: async () => {
if (instance.validateForm.valid) { if (instance.validateForm.valid) {
await new Promise(resolve => { await new Promise(resolve => {
console.log('表单信息', instance.validateForm) console.log('表单信息', instance.validateForm)
let arr = []
instance.validateForm.value.power.forEach(element => {
arr.push(element.name)
});
let body = { let body = {
name: instance.validateForm.value.name, name: instance.validateForm.value.name,
DisplayName: instance.validateForm.value.name, DisplayName: instance.validateForm.value.name,
grantedPermissions: arr grantedPermissions: instance.validateForm.value.power || []
} }
let body2=instance.validateForm.value.menus let body2 = instance.validateForm.value.menus || []
this.http.post('/api/services/app/Role/Create', body).subscribe((data:any) => { this.http.post('/api/services/app/Role/Create', body).subscribe((data: any) => {
resolve(data) resolve(data)
this.http.post('/api/services/app/Role/SetRoleMenus', body2, { this.http.post('/api/services/app/Role/SetRoleMenus', body2, {
params: { params: {
@ -96,14 +91,14 @@ export class RoleComponent implements OnInit {
} }
}).subscribe(data => { }).subscribe(data => {
resolve(data) resolve(data)
this.message.create('success', '创建成功!');
// this.message.create('success', '分配成功!'); this.getAllRoles()
return true return true
}, err => {
this.message.create('warning', '分配菜单错误!');
}) })
this.message.create('success', '创建成功!'); }, err => {
this.getAllRoles() this.message.create('warning', '创建角色错误!');
return true
}) })
}) })
} else { } else {
@ -116,14 +111,13 @@ export class RoleComponent implements OnInit {
modal.afterOpen.subscribe(() => console.log('[afterOpen] emitted!')); modal.afterOpen.subscribe(() => console.log('[afterOpen] emitted!'));
modal.afterClose.subscribe(result => console.log('[afterClose] The result is:', result)); modal.afterClose.subscribe(result => console.log('[afterClose] The result is:', result));
} }
edit(item) { edit(item) {
const modal = this.modal.create({ const modal = this.modal.create({
nzTitle: '编辑角色', nzTitle: '编辑角色',
nzContent: EditroleComponent, nzContent: EditroleComponent,
nzViewContainerRef: this.viewContainerRef, nzViewContainerRef: this.viewContainerRef,
nzWidth: 400, nzWidth: 400,
// nzOkLoading: true,
nzComponentParams: { nzComponentParams: {
data: item, data: item,
optionList: this.optionList, optionList: this.optionList,
@ -134,33 +128,30 @@ export class RoleComponent implements OnInit {
if (instance.validateForm.valid) { if (instance.validateForm.valid) {
await new Promise(resolve => { await new Promise(resolve => {
console.log('表单信息', instance.validateForm) console.log('表单信息', instance.validateForm)
let arr = []
instance.validateForm.value.power.forEach(element => {
arr.push(element.name ? element.name : element)
});
let body = { let body = {
id: item.id, id: item.id,
name: instance.validateForm.value.name, name: instance.validateForm.value.name,
DisplayName: instance.validateForm.value.name, DisplayName: instance.validateForm.value.name,
grantedPermissions: arr grantedPermissions: instance.validateForm.value.power || []
} }
let body2=instance.validateForm.value.menus let body2 = instance.validateForm.value.menus || []
this.http.put('/api/services/app/Role/Update', body).subscribe((data:any) => { this.http.put('/api/services/app/Role/Update', body).subscribe((data: any) => {
resolve(data) resolve(data)
this.http.post('/api/services/app/Role/SetRoleMenus', body2, { this.http.post('/api/services/app/Role/SetRoleMenus', body2, {
params: { params: {
roleId: data.result.id roleId: data.result.id
} }
}).subscribe(data => { }).subscribe(data => {
resolve(data) this.message.create('success', '修改成功!');
this.getAllRoles()
// this.message.create('success', '分配成功!');
return true return true
resolve(data)
}, err => {
this.message.create('warning', '分配菜单错误!');
}) })
this.message.create('success', '修改成功!');
this.getAllRoles() }, err => {
return true this.message.create('warning', '修改角色错误!');
}) })
}) })
} else { } else {

Loading…
Cancel
Save