|
|
@ -1,64 +1,63 @@ |
|
|
|
import { PermItemDTO, UserRoleDTO } from "@admin/app/dtos/user.dto"; |
|
|
|
import { ApiService } from "@admin/app/services"; |
|
|
|
import { Component } from "@angular/core"; |
|
|
|
import { Component, Input, OnChanges, SimpleChanges } from "@angular/core"; |
|
|
|
import { ActivatedRoute } from "@angular/router"; |
|
|
|
import { AnyObject } from "@cdk/types"; |
|
|
|
import { NzMessageService } from "ng-zorro-antd/message"; |
|
|
|
import { finalize } from "rxjs"; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: "app-role-permission", |
|
|
|
templateUrl: "./role-permission.component.html", |
|
|
|
styleUrls: ["./role-permission.component.less"], |
|
|
|
}) |
|
|
|
export class RolePermissionComponent { |
|
|
|
constructor(private api: ApiService, private route: ActivatedRoute) {} |
|
|
|
export class RolePermissionComponent implements OnChanges { |
|
|
|
constructor(private api: ApiService, private route: ActivatedRoute, private msg: NzMessageService) {} |
|
|
|
|
|
|
|
roleId: string | null = null; |
|
|
|
@Input() perms: PermItemDTO[] = []; |
|
|
|
|
|
|
|
permissions = { |
|
|
|
食材管理: [ |
|
|
|
{ label: "食材列表-查看", value: "1-1" }, |
|
|
|
{ label: "食材-新增/编辑/删除", value: "1-2" }, |
|
|
|
], |
|
|
|
菜品管理: [ |
|
|
|
{ label: "菜品列表-查看", value: "2-1" }, |
|
|
|
{ label: "菜品-新增/编辑/删除", value: "2-2" }, |
|
|
|
], |
|
|
|
食谱管理: [ |
|
|
|
{ label: "食谱列表-查看", value: "3-1" }, |
|
|
|
{ label: "食谱-新增/编辑/删除", value: "3-2" }, |
|
|
|
{ label: "食谱审核列表-查看", value: "3-3" }, |
|
|
|
{ label: "食谱审核列表-通过/驳回", value: "3-4" }, |
|
|
|
{ label: "食谱发布计划-查看", value: "3-5" }, |
|
|
|
{ label: "食谱发布计划-发布/取消发布", value: "3-6" }, |
|
|
|
], |
|
|
|
人群营养标准管理: [ |
|
|
|
{ label: "模型列表-查看", value: "4-1" }, |
|
|
|
{ label: "营养标准模型-新增/编辑/删除", value: "4-2" }, |
|
|
|
], |
|
|
|
单位管理: [ |
|
|
|
{ label: "单位列表-查看", value: "5-1" }, |
|
|
|
{ label: "单位-新增/编辑/启用/禁用/删除", value: "5-2" }, |
|
|
|
], |
|
|
|
系统设置: [ |
|
|
|
{ label: "用户列表-查看", value: "6-1" }, |
|
|
|
{ label: "角色权限-新增/编辑/删除", value: "6-2" }, |
|
|
|
{ label: "用户-新增/编辑/删除", value: "6-3" }, |
|
|
|
], |
|
|
|
}; |
|
|
|
@Input() role!: UserRoleDTO; |
|
|
|
|
|
|
|
hasPermissions = new Set<string>(); |
|
|
|
loading = false; |
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
this.route.queryParamMap.subscribe((r) => { |
|
|
|
this.roleId = r.get("roleId"); |
|
|
|
if (this.roleId) { |
|
|
|
} |
|
|
|
}); |
|
|
|
ngOnChanges(changes: SimpleChanges): void { |
|
|
|
if (changes["perms"]?.currentValue) { |
|
|
|
const perms: PermItemDTO[] = changes["perms"].currentValue; |
|
|
|
this.permissions = perms.reduce((a, c) => { |
|
|
|
const key = c["category"]; |
|
|
|
const o = { ...c, label: c.itemName, value: c.id }; |
|
|
|
if (a[key]) { |
|
|
|
a[key].push(o); |
|
|
|
} else { |
|
|
|
a[key] = [o]; |
|
|
|
} |
|
|
|
return a; |
|
|
|
}, {} as Record<string, Array<{ label: string; value: number } & AnyObject>>); |
|
|
|
} |
|
|
|
if (changes["role"]?.currentValue) { |
|
|
|
const role: UserRoleDTO = changes["role"].currentValue; |
|
|
|
let perms: number[] = []; |
|
|
|
try { |
|
|
|
perms = JSON.parse(role.roleItems); |
|
|
|
} catch (error) {} |
|
|
|
this.hasPermissions.clear(); |
|
|
|
perms.forEach((p) => { |
|
|
|
this.hasPermissions.add(p); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
permissions = {}; |
|
|
|
|
|
|
|
hasPermissions = new Set<number>(); |
|
|
|
|
|
|
|
ngOnInit(): void {} |
|
|
|
|
|
|
|
returenZero() { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
onPermissionChange(checked: boolean, key: string) { |
|
|
|
onPermissionChange(checked: boolean, key: number) { |
|
|
|
if (!checked && this.hasPermissions.has(key)) { |
|
|
|
this.hasPermissions.delete(key); |
|
|
|
} else { |
|
|
@ -67,6 +66,17 @@ export class RolePermissionComponent { |
|
|
|
} |
|
|
|
|
|
|
|
onSubmit() { |
|
|
|
console.log("this.hasPermissions", this.hasPermissions); |
|
|
|
const role = { ...this.role, roleId: this.role.id, items: Array.from(this.hasPermissions) }; |
|
|
|
this.loading = true; |
|
|
|
this.api |
|
|
|
.updateRole(role) |
|
|
|
.pipe( |
|
|
|
finalize(() => { |
|
|
|
this.loading = false; |
|
|
|
}) |
|
|
|
) |
|
|
|
.subscribe((res) => { |
|
|
|
this.msg.success(res.desc); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|