2025-09-23 10:32:35 +08:00
|
|
|
import { request } from 'umi';
|
|
|
|
|
|
|
|
|
|
export interface RoleItem {
|
|
|
|
|
id?: number;
|
|
|
|
|
name: string;
|
|
|
|
|
code: string;
|
|
|
|
|
dataScope?: 'ALL' | 'CREATOR';
|
2025-09-29 19:29:41 +08:00
|
|
|
// 所属租户ID
|
|
|
|
|
tenantId?: string;
|
|
|
|
|
// 所属租户名称(如果后端返回)
|
|
|
|
|
tenantName?: string;
|
2025-09-23 10:32:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const roleApi = {
|
2025-09-29 19:29:41 +08:00
|
|
|
// 角色分页(按租户/包含子级)
|
|
|
|
|
page: async (params: { current?: number; pageSize?: number; tenantId?: string; includeChildren?: boolean; searchKey?: string; searchValue?: string }) => {
|
2025-09-23 10:32:35 +08:00
|
|
|
if (!params?.tenantId) return { data: [], total: 0 };
|
|
|
|
|
const res = await request('/api-user/roles', {
|
|
|
|
|
method: 'GET',
|
2025-09-29 19:29:41 +08:00
|
|
|
params: {
|
|
|
|
|
page: params.current,
|
|
|
|
|
limit: params.pageSize,
|
|
|
|
|
tenantId: params.tenantId,
|
|
|
|
|
includeChildren: params.includeChildren,
|
|
|
|
|
searchKey: params.searchKey,
|
|
|
|
|
searchValue: params.searchValue,
|
|
|
|
|
},
|
2025-09-23 10:32:35 +08:00
|
|
|
});
|
|
|
|
|
const data = (res as any).data;
|
|
|
|
|
const total = (res as any).count ?? data?.length ?? 0;
|
|
|
|
|
return { data, total } as { data: RoleItem[]; total: number };
|
|
|
|
|
},
|
2025-09-29 19:29:41 +08:00
|
|
|
|
|
|
|
|
// 新增/修改角色(传入所属租户)
|
2025-09-23 10:32:35 +08:00
|
|
|
saveOrUpdate: async (data: RoleItem) => {
|
2025-09-29 19:29:41 +08:00
|
|
|
const res = await request('/api-user/roles/saveOrUpdate', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
data,
|
|
|
|
|
params: { tenantId: (data as any)?.tenantId },
|
|
|
|
|
});
|
2025-09-23 10:32:35 +08:00
|
|
|
return (res as any).data || res;
|
|
|
|
|
},
|
2025-09-29 19:29:41 +08:00
|
|
|
|
|
|
|
|
// 删除角色
|
2025-09-23 10:32:35 +08:00
|
|
|
delete: async (id: number) => {
|
|
|
|
|
const res = await request(`/api-user/roles/${id}`, { method: 'DELETE' });
|
|
|
|
|
return (res as any).data || res;
|
|
|
|
|
},
|
2025-09-29 19:29:41 +08:00
|
|
|
|
|
|
|
|
// 所有应用(授权用)
|
2025-09-23 10:32:35 +08:00
|
|
|
apps: async () => {
|
|
|
|
|
const res = await request('/api-uaa/clients/all', { method: 'GET' });
|
|
|
|
|
return (res as any).data || [];
|
|
|
|
|
},
|
2025-09-29 19:29:41 +08:00
|
|
|
|
|
|
|
|
// 某角色的菜单(按租户)
|
2025-09-23 10:32:35 +08:00
|
|
|
menuForAuth: async (roleId: number, tenantId: string) => {
|
|
|
|
|
const res = await request(`/api-user/menus/${roleId}/menus`, { method: 'GET', params: { tenantId } });
|
|
|
|
|
return res as any[];
|
|
|
|
|
},
|
2025-09-29 19:29:41 +08:00
|
|
|
|
|
|
|
|
// 分配菜单权限
|
|
|
|
|
assignMenu: async (payload: { roleId: number; menuIds: (string | number)[] }) => {
|
2025-09-23 10:32:35 +08:00
|
|
|
const res = await request('/api-user/menus/granted', { method: 'POST', data: payload });
|
|
|
|
|
return (res as any).data || res;
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|