feat: role CRUD page

This commit is contained in:
tao.chen
2026-08-25 22:52:00 +08:00
parent 5ed7e12a23
commit 6fe2d0b42e
12 changed files with 891 additions and 6 deletions
+92
View File
@@ -119,6 +119,35 @@ export type Employee = {
created_at: string;
};
// Role (Platform Role) types - 角色管理接口
export type Role = {
role_id: string;
role_code: string;
role_name: string;
is_builtin: boolean;
description: string | null;
permission_codes: string[];
};
export type PlatformPermission = {
permission_code: string;
permission_name: string;
module_code: string;
description: string | null;
};
export type RoleCreatePayload = {
role_code: string;
role_name: string;
description?: string | null;
permission_codes?: string[];
};
export type RoleUpdatePayload = {
role_name?: string;
description?: string | null; // null = clear
};
// Workspace (Project) types - 对应 API.md 第七部分系统管理接口
export type Workspace = {
workspace_id: string;
@@ -1167,6 +1196,54 @@ export async function deletePlatformEmployee(
);
}
export async function listPlatformRoles(): Promise<Role[]> {
return apiRequest<Role[]>("/api/v1/platform/roles");
}
export async function getPlatformRole(roleCode: string): Promise<Role> {
return apiRequest<Role>(`/api/v1/platform/roles/${roleCode}/permissions`);
}
export async function listPlatformPermissions(): Promise<PlatformPermission[]> {
return apiRequest<PlatformPermission[]>("/api/v1/platform/permissions");
}
export async function createPlatformRole(input: RoleCreatePayload): Promise<Role> {
return apiRequest<Role>(
"/api/v1/platform/roles",
{ method: "POST", body: JSON.stringify(input) },
);
}
export async function updatePlatformRole(
roleCode: string,
input: RoleUpdatePayload,
): Promise<Role> {
return apiRequest<Role>(
`/api/v1/platform/roles/${roleCode}`,
{ method: "PATCH", body: JSON.stringify(input) },
);
}
export async function deletePlatformRole(
roleCode: string,
): Promise<{ role_code: string; deleted: boolean }> {
return apiRequest(
`/api/v1/platform/roles/${roleCode}`,
{ method: "DELETE" },
);
}
export async function updatePlatformRolePermissions(
roleCode: string,
permissionCodes: string[],
): Promise<Role> {
return apiRequest<Role>(
`/api/v1/platform/roles/${roleCode}/permissions`,
{ method: "PATCH", body: JSON.stringify({ permission_codes: permissionCodes }) },
);
}
// 兼容旧的 workspace 级别接口(已废弃,建议使用 system-level 接口)
/** @deprecated 使用 listPlatformEmployees 代替 */
export async function listEmployees(workspaceId: string): Promise<Employee[]> {
@@ -1625,6 +1702,21 @@ export type WorkspaceBoundApi = {
deletePlatformEmployee: (
userId: string,
) => Promise<{ user_id: string; deleted: boolean }>;
listPlatformRoles: () => Promise<Role[]>;
getPlatformRole: (roleCode: string) => Promise<Role>;
listPlatformPermissions: () => Promise<PlatformPermission[]>;
createPlatformRole: (input: RoleCreatePayload) => Promise<Role>;
updatePlatformRole: (
roleCode: string,
input: RoleUpdatePayload,
) => Promise<Role>;
deletePlatformRole: (
roleCode: string,
) => Promise<{ role_code: string; deleted: boolean }>;
updatePlatformRolePermissions: (
roleCode: string,
permissionCodes: string[],
) => Promise<Role>;
createScheduleNode: (
scheduleId: string,
input: Parameters<typeof createScheduleNode>[2],