82 lines
2.1 KiB
TypeScript
82 lines
2.1 KiB
TypeScript
import { apiRequest } from "./_shared";
|
|
|
|
// 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
|
|
};
|
|
|
|
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 代替 */
|