- 用户/组织/资源页批量删除改批量接口 + 失败汇总提示 - 角色页新增「分配部门」(dataScope=custom 时显示,部门树勾选) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
73 lines
2.3 KiB
TypeScript
73 lines
2.3 KiB
TypeScript
import { http } from '@/api/http'
|
||
|
||
export type DataScope = 'all' | 'dept' | 'dept_and_child' | 'self' | 'custom'
|
||
|
||
export interface Role {
|
||
id: string
|
||
tenantCode: string
|
||
code: string
|
||
name: string
|
||
dataScope: DataScope
|
||
status: 'enabled' | 'disabled'
|
||
remark: string | null
|
||
createdAt: number
|
||
}
|
||
|
||
export interface RoleListQuery {
|
||
page: number
|
||
pageSize: number
|
||
name?: string
|
||
code?: string
|
||
status?: string
|
||
}
|
||
|
||
export interface RoleListResult {
|
||
list: Role[]
|
||
total: number
|
||
page: number
|
||
pageSize: number
|
||
}
|
||
|
||
export function listRoles(query: RoleListQuery, signal?: AbortSignal): Promise<RoleListResult> {
|
||
const params: Record<string, unknown> = { page: query.page, pageSize: query.pageSize }
|
||
if (query.name) params.name = query.name
|
||
if (query.code) params.code = query.code
|
||
if (query.status) params.status = query.status
|
||
return http.get<RoleListResult>('/roles', { params, signal })
|
||
}
|
||
|
||
export function createRole(data: { code: string; name: string; dataScope?: DataScope; remark?: string }): Promise<Role> {
|
||
return http.post<Role>('/roles', data)
|
||
}
|
||
|
||
export function updateRole(
|
||
id: string,
|
||
data: { name?: string; dataScope?: DataScope; status?: string; remark?: string },
|
||
): Promise<Role> {
|
||
return http.patch<Role>(`/roles/${id}`, data)
|
||
}
|
||
|
||
export function deleteRole(id: string): Promise<unknown> {
|
||
return http.delete(`/roles/${id}`)
|
||
}
|
||
|
||
/** 角色已分配的资源 code 列表(注意:URL 的 :id 是 roleCode 而非 UUID)。 */
|
||
export function listAssignedResources(roleCode: string, signal?: AbortSignal): Promise<string[]> {
|
||
return http.get<string[]>(`/roles/${roleCode}/resources`, { signal })
|
||
}
|
||
|
||
/** 分配资源(注意:URL 的 :id 是 roleCode 而非 UUID)。 */
|
||
export function assignResources(roleCode: string, resourceCodes: string[]): Promise<unknown> {
|
||
return http.put(`/roles/${roleCode}/resources`, { resourceCodes })
|
||
}
|
||
|
||
/** 角色已分配的数据权限部门 code 列表(data_scope=custom)。 */
|
||
export function listAssignedOrgs(roleCode: string, signal?: AbortSignal): Promise<string[]> {
|
||
return http.get<string[]>(`/roles/${roleCode}/orgs`, { signal })
|
||
}
|
||
|
||
/** 分配数据权限部门。 */
|
||
export function assignOrgs(roleCode: string, orgCodes: string[]): Promise<unknown> {
|
||
return http.put(`/roles/${roleCode}/orgs`, { orgCodes })
|
||
}
|