role.ts
2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// 角色与权限矩阵接口(PRD §7 角色管理,权限矩阵在详情抽屉内配置)
// 继承 ApiClient,共享 http 与 RSA 加签/验签。
import { ApiClient } from '../core/client';
import type { PageResult } from '../core/types';
export interface RoleItem {
id: string;
roleName: string;
roleCode: string;
remark?: string;
createTime?: string;
}
export interface RolePageParams {
current?: number;
size?: number;
keyword?: string;
isBuiltin?: number;
status?: number;
defaultDataScope?: number;
}
export interface RolePageItem {
roleId: number;
roleName: string;
roleCode: string;
defaultDataScope: number;
accountCount: number;
description?: string;
isBuiltin: number;
status: number;
}
export interface RolePageResult {
records: RolePageItem[];
total: number;
current: number;
size: number;
pages: number;
}
export interface RoleOption {
roleId: number;
roleName: string;
roleCode?: string;
}
export interface PermissionMatrix {
roleId: string;
groups: {
group: string;
items: { key: string; label: string; checked: boolean }[];
}[];
}
class Role extends ApiClient {
options() {
return this.get<RoleOption[]>('/system/role/options');
}
page(payload: RolePageParams) {
return this.post<RolePageResult>('/system/role/page', payload as Record<string, unknown>);
}
list(params: Record<string, unknown> = {}) {
return this.get<PageResult<RoleItem>>('/store/role/list', params);
}
create(payload: Partial<RoleItem>) {
return this.post<string>('/store/role/create', payload);
}
update(id: string, payload: Partial<RoleItem>) {
return this.post<null>('/store/role/update', { id, ...payload });
}
remove(id: string) {
return this.del<null>(`/store/role/delete/${id}`);
}
getPermissions(roleId: string) {
return this.get<PermissionMatrix>('/store/role/permissions', { roleId });
}
savePermissions(roleId: string, groups: PermissionMatrix['groups']) {
return this.post<null>('/store/role/permissions/save', { roleId, groups });
}
}
export const role = new Role();