feat: 优化web
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
import { apiJson } from '@/lib/api/client';
|
||||
import { API_V1 } from '@/lib/api/paths';
|
||||
import type { DeptNode, IamDept } from '@/lib/api/types/dept';
|
||||
import type { MenuNode } from '@/lib/api/types/menu';
|
||||
import type { IamRole } from '@/lib/api/types/role';
|
||||
import type { IamTenant } from '@/lib/api/types/tenant';
|
||||
import type { IamUser } from '@/lib/api/types/user';
|
||||
|
||||
const B = `${API_V1}/iam`;
|
||||
|
||||
/** 列表响应信封 */
|
||||
type ListEnvelope<T> = { items: T[]; total: number };
|
||||
|
||||
/** 租户 */
|
||||
export const iamTenant = {
|
||||
create: (body: Partial<IamTenant>) =>
|
||||
apiJson<IamTenant>(`${B}/tenant/create`, { method: 'POST', body: JSON.stringify(body) }),
|
||||
update: (id: string, body: Partial<IamTenant>) =>
|
||||
apiJson<IamTenant>(`${B}/tenant/update/${encodeURIComponent(id)}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(body),
|
||||
}),
|
||||
deleteBatch: (ids: string[]) =>
|
||||
apiJson<void>(`${B}/tenant/delete-batch`, { method: 'DELETE', body: JSON.stringify(ids) }),
|
||||
get: (id: string) => apiJson<IamTenant>(`${B}/tenant/get/${encodeURIComponent(id)}`),
|
||||
list: (query?: Record<string, string>) => {
|
||||
const q = query ? new URLSearchParams(query).toString() : 'page=1&page_size=200';
|
||||
return apiJson<ListEnvelope<IamTenant>>(`${B}/tenant/list?${q}`);
|
||||
},
|
||||
};
|
||||
|
||||
/** 部门 */
|
||||
export const iamDept = {
|
||||
create: (body: Partial<IamDept>) =>
|
||||
apiJson<IamDept>(`${B}/dept/create`, { method: 'POST', body: JSON.stringify(body) }),
|
||||
update: (id: string, body: Partial<IamDept>) =>
|
||||
apiJson<IamDept>(`${B}/dept/update/${encodeURIComponent(id)}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(body),
|
||||
}),
|
||||
deleteBatch: (ids: string[]) =>
|
||||
apiJson<void>(`${B}/dept/delete-batch`, { method: 'DELETE', body: JSON.stringify(ids) }),
|
||||
get: (id: string) => apiJson<IamDept>(`${B}/dept/get/${encodeURIComponent(id)}`),
|
||||
tree: () => apiJson<DeptNode[]>(`${B}/dept/tree`),
|
||||
};
|
||||
|
||||
/** 角色 */
|
||||
export const iamRole = {
|
||||
create: (body: Partial<IamRole>) =>
|
||||
apiJson<IamRole>(`${B}/role/create`, { method: 'POST', body: JSON.stringify(body) }),
|
||||
update: (id: string, body: Partial<IamRole>) =>
|
||||
apiJson<IamRole>(`${B}/role/update/${encodeURIComponent(id)}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(body),
|
||||
}),
|
||||
deleteBatch: (ids: string[]) =>
|
||||
apiJson<void>(`${B}/role/delete-batch`, { method: 'DELETE', body: JSON.stringify(ids) }),
|
||||
get: (id: string) => apiJson<IamRole>(`${B}/role/get/${encodeURIComponent(id)}`),
|
||||
list: (query?: Record<string, string>) => {
|
||||
const q = query ? new URLSearchParams(query).toString() : 'page=1&page_size=50';
|
||||
return apiJson<ListEnvelope<IamRole>>(`${B}/role/list?${q}`);
|
||||
},
|
||||
};
|
||||
|
||||
/** 用户 */
|
||||
export const iamUser = {
|
||||
create: (body: Partial<IamUser>) =>
|
||||
apiJson<IamUser>(`${B}/user/create`, { method: 'POST', body: JSON.stringify(body) }),
|
||||
update: (id: string, body: Partial<IamUser>) =>
|
||||
apiJson<IamUser>(`${B}/user/update/${encodeURIComponent(id)}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(body),
|
||||
}),
|
||||
deleteBatch: (ids: string[]) =>
|
||||
apiJson<void>(`${B}/user/delete-batch`, { method: 'DELETE', body: JSON.stringify(ids) }),
|
||||
get: (id: string) => apiJson<IamUser>(`${B}/user/get/${encodeURIComponent(id)}`),
|
||||
list: (query?: Record<string, string>) => {
|
||||
const q = query ? new URLSearchParams(query).toString() : 'page=1&page_size=20';
|
||||
return apiJson<ListEnvelope<IamUser>>(`${B}/user/list?${q}`);
|
||||
},
|
||||
};
|
||||
|
||||
/** 菜单 */
|
||||
export const iamMenu = {
|
||||
create: (body: Partial<MenuNode>) =>
|
||||
apiJson<MenuNode>(`${B}/menu/create`, { method: 'POST', body: JSON.stringify(body) }),
|
||||
update: (id: string, body: Partial<MenuNode>) =>
|
||||
apiJson<MenuNode>(`${B}/menu/update/${encodeURIComponent(id)}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(body),
|
||||
}),
|
||||
deleteBatch: (ids: string[]) =>
|
||||
apiJson<void>(`${B}/menu/delete-batch`, { method: 'DELETE', body: JSON.stringify(ids) }),
|
||||
get: (id: string) => apiJson<MenuNode>(`${B}/menu/get/${encodeURIComponent(id)}`),
|
||||
tree: () => apiJson<MenuNode[]>(`${B}/menu/tree`),
|
||||
/** 当前用户可见导航树(需 Bearer,后端从 token 解析 user_id) */
|
||||
nav: () => apiJson<MenuNode[]>(`${B}/menu/nav`),
|
||||
perms: () => apiJson<{ perms: string[] }>(`${B}/menu/perms`),
|
||||
};
|
||||
Reference in New Issue
Block a user