refactor API export

This commit is contained in:
Timi
2026-08-21 16:34:39 +08:00
parent 175838f7c5
commit 98ab992728
11 changed files with 335 additions and 399 deletions
+88 -120
View File
@@ -3,124 +3,92 @@ import type { ModuleCode, Page, PageResult, Permission, Role, RolePayload, Autho
const BASE_URI = "/user/role";
async function list(req: Page<Role>): Promise<PageResult<Role>> {
return axios.post(`${BASE_URI}/list`, req);
}
async function detail(id: string): Promise<Role> {
return axios.post(`${BASE_URI}/detail`, undefined, {
params: { id }
});
}
async function create(req: RolePayload): Promise<void> {
return axios.post(`${BASE_URI}/create`, req);
}
async function update(req: RolePayload): Promise<void> {
return axios.post(`${BASE_URI}/update`, req);
}
async function remove(id: string): Promise<void> {
return axios.post(`${BASE_URI}/delete`, undefined, {
params: { id }
});
}
/** 查询当前登录用户在模块内可管理的角色。 */
async function manageableList(moduleCode: ModuleCode): Promise<Role[]> {
return await axios.post(`${BASE_URI}/manageable/list`, undefined, {
params: { moduleCode }
});
}
/** 查询当前登录用户在模块内可授权给账号的角色。 */
async function grantableList(moduleCode: ModuleCode): Promise<Role[]> {
return await axios.post(`${BASE_URI}/grantable/list`, undefined, {
params: { moduleCode }
});
}
/** 查询当前登录用户直属角色详情,不按可管理范围过滤。 */
async function currentDetailList(moduleCode?: ModuleCode): Promise<Role[]> {
return await axios.post(`${BASE_URI}/current/detail/list`, undefined, {
params: { moduleCode }
});
}
/** 查询当前登录用户可以给目标角色配置的直接权限 P 候选项。 */
async function grantablePermissionList(roleId: string): Promise<Permission[]> {
return await axios.post(`${BASE_URI}/permission/grantable/list`, undefined, {
params: { roleId }
});
}
/** 查询目标角色当前可继续转授的权限 D。 */
async function delegationList(roleId: string): Promise<Permission[]> {
return await axios.post(`${BASE_URI}/delegation/list`, undefined, {
params: { roleId }
});
}
/** 查询当前登录用户可以给目标角色配置的 D 候选项。 */
async function grantableDelegationList(roleId: string): Promise<Permission[]> {
return await axios.post(`${BASE_URI}/delegation/grantable/list`, undefined, {
params: { roleId }
});
}
/** 覆盖保存目标角色可继续转授的权限 D。 */
async function updateDelegation(req: Pick<RolePayload, "id" | "delegationPermissionIdList">): Promise<void> {
await axios.post(`${BASE_URI}/delegation/update`, req);
}
/** 查询目标角色可选管理父级。 */
async function parentGrantableList(roleId: string): Promise<Role[]> {
return await axios.post(`${BASE_URI}/parent/grantable/list`, undefined, {
params: { roleId }
});
}
/** 保存目标角色管理父级。 */
async function updateParent(req: Pick<RolePayload, "id" | "parentRoleId">): Promise<void> {
await axios.post(`${BASE_URI}/parent/update`, req);
}
async function authorizedList(userId: string, moduleCode?: ModuleCode): Promise<Role[]> {
return axios.post(`${BASE_URI}/authorized/list`, undefined, {
params: {
userId,
moduleCode
}
});
}
async function authorize(req: AuthorizeUserRole): Promise<void> {
return axios.post(`${BASE_URI}/authorized/create`, req);
}
async function authorizedPermission(userId: string): Promise<Permission[]> {
return axios.post(`${BASE_URI}/authorized/permission`, undefined, {
params: { userId }
});
}
export default {
list,
detail,
create,
update,
remove,
manageableList,
grantableList,
currentDetailList,
grantablePermissionList,
delegationList,
grantableDelegationList,
updateDelegation,
parentGrantableList,
updateParent,
authorizedList,
authorize,
authorizedPermission
export const RoleAPI = {
async list(req: Page<Role>): Promise<PageResult<Role>> {
return axios.post(`${BASE_URI}/list`, req);
},
async detail(id: string): Promise<Role> {
return axios.post(`${BASE_URI}/detail`, undefined, {
params: { id }
});
},
async create(req: RolePayload): Promise<void> {
return axios.post(`${BASE_URI}/create`, req);
},
async update(req: RolePayload): Promise<void> {
return axios.post(`${BASE_URI}/update`, req);
},
async remove(id: string): Promise<void> {
return axios.post(`${BASE_URI}/delete`, undefined, {
params: { id }
});
},
/** 查询当前登录用户在模块内可管理的角色。 */
async manageableList(moduleCode: ModuleCode): Promise<Role[]> {
return await axios.post(`${BASE_URI}/manageable/list`, undefined, {
params: { moduleCode }
});
},
/** 查询当前登录用户在模块内可授权给账号的角色。 */
async grantableList(moduleCode: ModuleCode): Promise<Role[]> {
return await axios.post(`${BASE_URI}/grantable/list`, undefined, {
params: { moduleCode }
});
},
/** 查询当前登录用户直属角色详情,不按可管理范围过滤。 */
async currentDetailList(moduleCode?: ModuleCode): Promise<Role[]> {
return await axios.post(`${BASE_URI}/current/detail/list`, undefined, {
params: { moduleCode }
});
},
/** 查询当前登录用户可以给目标角色配置的直接权限 P 候选项。 */
async grantablePermissionList(roleId: string): Promise<Permission[]> {
return await axios.post(`${BASE_URI}/permission/grantable/list`, undefined, {
params: { roleId }
});
},
/** 查询目标角色当前可继续转授的权限 D。 */
async delegationList(roleId: string): Promise<Permission[]> {
return await axios.post(`${BASE_URI}/delegation/list`, undefined, {
params: { roleId }
});
},
/** 查询当前登录用户可以给目标角色配置的 D 候选项。 */
async grantableDelegationList(roleId: string): Promise<Permission[]> {
return await axios.post(`${BASE_URI}/delegation/grantable/list`, undefined, {
params: { roleId }
});
},
/** 覆盖保存目标角色可继续转授的权限 D。 */
async updateDelegation(req: Pick<RolePayload, "id" | "delegationPermissionIdList">): Promise<void> {
await axios.post(`${BASE_URI}/delegation/update`, req);
},
/** 查询目标角色可选管理父级。 */
async parentGrantableList(roleId: string): Promise<Role[]> {
return await axios.post(`${BASE_URI}/parent/grantable/list`, undefined, {
params: { roleId }
});
},
/** 保存目标角色管理父级。 */
async updateParent(req: Pick<RolePayload, "id" | "parentRoleId">): Promise<void> {
await axios.post(`${BASE_URI}/parent/update`, req);
},
async authorizedList(userId: string, moduleCode?: ModuleCode): Promise<Role[]> {
return axios.post(`${BASE_URI}/authorized/list`, undefined, {
params: {
userId,
moduleCode
}
});
},
async authorize(req: AuthorizeUserRole): Promise<void> {
return axios.post(`${BASE_URI}/authorized/create`, req);
},
async authorizedPermission(userId: string): Promise<Permission[]> {
return axios.post(`${BASE_URI}/authorized/permission`, undefined, {
params: { userId }
});
}
};
export default RoleAPI;