|
|
@ -14,47 +14,61 @@ import { EditroleComponent } from './editrole/editrole.component'; |
|
|
|
export class RoleComponent implements OnInit { |
|
|
|
export class RoleComponent implements OnInit { |
|
|
|
|
|
|
|
|
|
|
|
constructor(private modal: NzModalService, private viewContainerRef: ViewContainerRef, private message: NzMessageService, private http: HttpClient, private toTree: TreeService) { } |
|
|
|
constructor(private modal: NzModalService, private viewContainerRef: ViewContainerRef, private message: NzMessageService, private http: HttpClient, private toTree: TreeService) { } |
|
|
|
listOfData = [11 |
|
|
|
listOfData = []; |
|
|
|
]; |
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
ngOnInit(): void { |
|
|
|
|
|
|
|
this.getAllRoles() |
|
|
|
} |
|
|
|
} |
|
|
|
getAllRoles() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取角色列表
|
|
|
|
|
|
|
|
isLoading = false |
|
|
|
|
|
|
|
async getAllRoles() { |
|
|
|
|
|
|
|
this.isLoading = true |
|
|
|
|
|
|
|
let params = { |
|
|
|
|
|
|
|
PageNumber: 1, |
|
|
|
|
|
|
|
PageSize: 100 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
await new Promise<void>((resolve, reject) => { |
|
|
|
|
|
|
|
this.http.get('/api/Roles', { |
|
|
|
|
|
|
|
params: params |
|
|
|
|
|
|
|
}).subscribe((data: any) => { |
|
|
|
|
|
|
|
this.isLoading = false |
|
|
|
|
|
|
|
this.listOfData = data.items |
|
|
|
|
|
|
|
resolve(data) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addRole() { |
|
|
|
addRole() { |
|
|
|
const modal = this.modal.create({ |
|
|
|
const modal = this.modal.create({ |
|
|
|
nzTitle: '新增角色', |
|
|
|
nzTitle: '新增角色', |
|
|
|
nzContent: AddroleComponent, |
|
|
|
nzContent: AddroleComponent, |
|
|
|
nzViewContainerRef: this.viewContainerRef, |
|
|
|
nzViewContainerRef: this.viewContainerRef, |
|
|
|
nzWidth: 400, |
|
|
|
nzWidth: 400, |
|
|
|
nzComponentParams: { |
|
|
|
|
|
|
|
nodes: null |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
let body = { |
|
|
|
let body = { |
|
|
|
name: instance.validateForm.value.name, |
|
|
|
name: instance.validateForm.value.name |
|
|
|
DisplayName: instance.validateForm.value.name, |
|
|
|
|
|
|
|
grantedPermissions: instance.validateForm.value.power || [] |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
let body2 = instance.validateForm.value.menus || [] |
|
|
|
this.http.post('/api/Roles', body).subscribe({ |
|
|
|
this.http.post('/api/services/app/Role/Create', body).subscribe({ |
|
|
|
next: async (data) => { |
|
|
|
next: (data) => { |
|
|
|
await this.getAllRoles() |
|
|
|
|
|
|
|
this.message.create('success', '创建成功'); |
|
|
|
resolve(data) |
|
|
|
resolve(data) |
|
|
|
this.message.create('success', '创建成功!'); |
|
|
|
|
|
|
|
this.getAllRoles() |
|
|
|
|
|
|
|
return true |
|
|
|
return true |
|
|
|
}, |
|
|
|
}, |
|
|
|
error: (err) => { |
|
|
|
error: (err) => { |
|
|
|
this.message.create('warning', '分配菜单错误!'); |
|
|
|
this.isLoading = false |
|
|
|
|
|
|
|
this.message.create('warning', '创建失败'); |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.message.create('warning', '请填写完整!'); |
|
|
|
this.message.create('warning', '请填写完整'); |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -76,28 +90,24 @@ export class RoleComponent implements OnInit { |
|
|
|
nzOnOk: async () => { |
|
|
|
nzOnOk: async () => { |
|
|
|
if (instance.validateForm.valid) { |
|
|
|
if (instance.validateForm.valid) { |
|
|
|
await new Promise(resolve => { |
|
|
|
await new Promise(resolve => { |
|
|
|
console.log('表单信息', instance.validateForm) |
|
|
|
|
|
|
|
let body = { |
|
|
|
let body = { |
|
|
|
id: item.id, |
|
|
|
|
|
|
|
name: instance.validateForm.value.name, |
|
|
|
name: instance.validateForm.value.name, |
|
|
|
DisplayName: instance.validateForm.value.name, |
|
|
|
|
|
|
|
grantedPermissions: instance.validateForm.value.power || [] |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
let body2 = instance.validateForm.value.menus || [] |
|
|
|
this.http.patch(`/api/Roles/${item.id}`, body).subscribe({ |
|
|
|
this.http.put('/api/services/app/Role/Update', body).subscribe({ |
|
|
|
next: async (data) => { |
|
|
|
next: (data) => { |
|
|
|
await this.getAllRoles() |
|
|
|
resolve(data) |
|
|
|
resolve(data) |
|
|
|
this.message.create('success', '修改成功!'); |
|
|
|
this.message.create('success', '修改成功'); |
|
|
|
this.getAllRoles() |
|
|
|
|
|
|
|
return true |
|
|
|
return true |
|
|
|
}, |
|
|
|
}, |
|
|
|
error: (err) => { |
|
|
|
error: (err) => { |
|
|
|
this.message.create('warning', '分配菜单错误!'); |
|
|
|
this.message.create('warning', '修改失败'); |
|
|
|
|
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.message.create('warning', '请填写完整!'); |
|
|
|
this.message.create('warning', '请填写完整'); |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -107,18 +117,37 @@ export class RoleComponent implements OnInit { |
|
|
|
// Return a result when closed
|
|
|
|
// Return a result when closed
|
|
|
|
modal.afterClose.subscribe(result => console.log('[afterClose] The result is:', result)); |
|
|
|
modal.afterClose.subscribe(result => console.log('[afterClose] The result is:', result)); |
|
|
|
} |
|
|
|
} |
|
|
|
forbidRole(item) { |
|
|
|
forbidRole(item, type) { |
|
|
|
|
|
|
|
this.isLoading = true |
|
|
|
|
|
|
|
let body = { |
|
|
|
|
|
|
|
enabled: type, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.http.patch(`/api/Roles/${item.id}`, body).subscribe({ |
|
|
|
|
|
|
|
next: async (data) => { |
|
|
|
|
|
|
|
await this.getAllRoles() |
|
|
|
|
|
|
|
this.message.create('success', '修改成功'); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
error: (err) => { |
|
|
|
|
|
|
|
this.isLoading = false |
|
|
|
|
|
|
|
this.message.create('warning', '修改失败'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
deleteRole(item) { |
|
|
|
deleteRole(item) { |
|
|
|
this.modal.confirm({ |
|
|
|
this.modal.confirm({ |
|
|
|
nzTitle: `确定要删除${item.title}这个机构吗?`, |
|
|
|
nzTitle: `确定要删除${item.name}这个机构吗?`, |
|
|
|
nzOkText: '确定', |
|
|
|
nzOkText: '确定', |
|
|
|
nzOkType: 'primary', |
|
|
|
nzOkType: 'primary', |
|
|
|
nzOnOk: () => { |
|
|
|
nzOnOk: () => { |
|
|
|
this.http.delete(`/api/Organizations/${item.origin.id}`).subscribe(data => { |
|
|
|
this.http.delete(`/api/Roles/${item.id}`).subscribe({ |
|
|
|
|
|
|
|
next: async (data) => { |
|
|
|
this.message.create('success', '删除成功!'); |
|
|
|
await this.getAllRoles() |
|
|
|
|
|
|
|
this.message.create('success', '删除成功'); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
error: (err) => { |
|
|
|
|
|
|
|
this.isLoading = false |
|
|
|
|
|
|
|
this.message.create('warning', '删除失败'); |
|
|
|
|
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
|
nzCancelText: '取消', |
|
|
|
nzCancelText: '取消', |
|
|
|