|
@ -1,11 +1,14 @@ |
|
|
import { FoodFormComponent } from "@admin/app/components"; |
|
|
import { FoodFormComponent } from "@admin/app/components"; |
|
|
|
|
|
import { PermItemDTO, UserDTO, UserRoleDTO } from "@admin/app/dtos/user.dto"; |
|
|
import { ApiService } from "@admin/app/services"; |
|
|
import { ApiService } from "@admin/app/services"; |
|
|
import { Component, OnInit, TemplateRef, ViewChild } from "@angular/core"; |
|
|
import { Component, OnChanges, OnInit, SimpleChanges, TemplateRef, ViewChild } from "@angular/core"; |
|
|
import { FormControl, FormGroup } from "@angular/forms"; |
|
|
import { FormControl, FormGroup, FormGroupName } from "@angular/forms"; |
|
|
import { ActivatedRoute, Router } from "@angular/router"; |
|
|
import { ActivatedRoute, Router } from "@angular/router"; |
|
|
import { AnyObject, TableListOption } from "@cdk/public-api"; |
|
|
import { AnyObject, FormValidators, TableListOption, Utils } from "@cdk/public-api"; |
|
|
import { NzDrawerRef, NzDrawerService } from "ng-zorro-antd/drawer"; |
|
|
import { NzDrawerRef, NzDrawerService } from "ng-zorro-antd/drawer"; |
|
|
|
|
|
import { NzMessageService } from "ng-zorro-antd/message"; |
|
|
import { NzModalService } from "ng-zorro-antd/modal"; |
|
|
import { NzModalService } from "ng-zorro-antd/modal"; |
|
|
|
|
|
import { lastValueFrom } from "rxjs"; |
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
selector: "app-user-manage", |
|
|
selector: "app-user-manage", |
|
@ -17,28 +20,65 @@ export class UserManageComponent { |
|
|
private route: ActivatedRoute, |
|
|
private route: ActivatedRoute, |
|
|
private api: ApiService, |
|
|
private api: ApiService, |
|
|
private router: Router, |
|
|
private router: Router, |
|
|
private modal: NzModalService |
|
|
private modal: NzModalService, |
|
|
|
|
|
private msg: NzMessageService |
|
|
) {} |
|
|
) {} |
|
|
|
|
|
|
|
|
public tab = 0; |
|
|
public tab = 0; |
|
|
|
|
|
|
|
|
public roleId: string | null = null; |
|
|
public role: UserRoleDTO | null = null; |
|
|
|
|
|
|
|
|
|
|
|
public roleForm = new FormGroup({ |
|
|
|
|
|
roleId: new FormControl(""), |
|
|
|
|
|
roleName: new FormControl("", [FormValidators.required("请输入角色名称")]), |
|
|
|
|
|
items: new FormControl("1"), |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
public allPerms: PermItemDTO[] = []; |
|
|
|
|
|
|
|
|
|
|
|
public userList: UserDTO[] = []; |
|
|
|
|
|
|
|
|
|
|
|
roleList: UserRoleDTO[] = []; |
|
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
ngOnInit(): void { |
|
|
this.roleId = this.route.snapshot.queryParamMap.get("roleId"); |
|
|
|
|
|
this.tab = Number(this.route.snapshot.queryParamMap.get("tab")) || 0; |
|
|
this.tab = Number(this.route.snapshot.queryParamMap.get("tab")) || 0; |
|
|
|
|
|
this.api.getRolePerms().subscribe((res) => { |
|
|
|
|
|
this.allPerms = res.body; |
|
|
|
|
|
}); |
|
|
|
|
|
this.api.getUserList().subscribe((res) => { |
|
|
|
|
|
this.userList = res.body; |
|
|
|
|
|
}); |
|
|
|
|
|
this.getRoleList(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
onRoleChange(roleId: string) { |
|
|
getRoleList() { |
|
|
this.roleId = roleId; |
|
|
this.api.getRoleList().subscribe((res) => { |
|
|
this.router.navigate(["/system/user"], { |
|
|
this.roleList = res.body.map((i) => ({ ...i, id: i.id.toString() })); |
|
|
queryParams: { |
|
|
const roleId = this.route.snapshot.queryParamMap.get("roleId"); |
|
|
roleId, |
|
|
const role = this.roleList.find((f) => f.id === roleId); |
|
|
}, |
|
|
if (role) { |
|
|
queryParamsHandling: "merge", |
|
|
this.role = role; |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
if (this.roleList.length > 0) { |
|
|
|
|
|
this.onRoleChange(this.roleList[0].id); |
|
|
|
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
onRoleChange(roleId: string) { |
|
|
|
|
|
const role = this.roleList.find((f) => f.id === roleId); |
|
|
|
|
|
if (role) { |
|
|
|
|
|
this.role = role; |
|
|
|
|
|
this.router.navigate(["/system/user"], { |
|
|
|
|
|
queryParams: { |
|
|
|
|
|
roleId, |
|
|
|
|
|
}, |
|
|
|
|
|
queryParamsHandling: "merge", |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
onTabChange(index: number) { |
|
|
onTabChange(index: number) { |
|
|
this.tab = index; |
|
|
this.tab = index; |
|
|
this.router.navigate(["/system/user"], { |
|
|
this.router.navigate(["/system/user"], { |
|
@ -49,20 +89,43 @@ export class UserManageComponent { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
openForm(nzContent: TemplateRef<{}>, event: MouseEvent, roleId?: string) { |
|
|
openForm(nzContent: TemplateRef<{}>, event: MouseEvent, role?: UserRoleDTO) { |
|
|
event.preventDefault(); |
|
|
event.stopPropagation(); |
|
|
|
|
|
if (role) { |
|
|
|
|
|
this.roleForm.patchValue({ |
|
|
|
|
|
...role, |
|
|
|
|
|
roleId: role.id, |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
this.modal.create({ |
|
|
this.modal.create({ |
|
|
nzTitle: roleId ? "编辑角色" : "新增角色", |
|
|
nzTitle: role ? "编辑角色" : "新增角色", |
|
|
nzContent, |
|
|
nzContent, |
|
|
|
|
|
nzOnCancel: () => { |
|
|
|
|
|
this.roleForm.reset(); |
|
|
|
|
|
}, |
|
|
|
|
|
nzOnOk: async () => { |
|
|
|
|
|
if (Utils.validateFormGroup(this.roleForm)) { |
|
|
|
|
|
const res = await lastValueFrom(this.api.updateRole(this.roleForm.value)); |
|
|
|
|
|
this.msg.success(res.desc); |
|
|
|
|
|
this.getRoleList(); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
}, |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
deleteItem(event: MouseEvent, id: string) { |
|
|
deleteItem(event: MouseEvent, id: string) { |
|
|
event.preventDefault(); |
|
|
event.stopPropagation(); |
|
|
this.modal.confirm({ |
|
|
this.modal.confirm({ |
|
|
nzTitle: "警告", |
|
|
nzTitle: "警告", |
|
|
nzContent: "是否要删除该角色?", |
|
|
nzContent: "是否要删除该角色?", |
|
|
nzOkDanger: true, |
|
|
nzOkDanger: true, |
|
|
|
|
|
nzOnOk: async () => { |
|
|
|
|
|
const res = await lastValueFrom(this.api.deleteRole(id)); |
|
|
|
|
|
this.msg.success(res.desc); |
|
|
|
|
|
this.getRoleList(); |
|
|
|
|
|
}, |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|