refactor(frontend): services/api 迁至 src/api,http 迁至 utils/request
对齐 Vue 后台惯例: - src/api/ 域 API(原 services/api) - src/utils/request.ts HTTP 封装(原 services/http.ts) - src/utils/export.ts 客户端导出工具 - src/utils/index.ts 工具统一出口 全局导入改为 @/api 与 @/utils/request,tsc + build 通过。
This commit is contained in:
1 parent
9bf35b369c
commit
d19a03d427
145 files changed
+156
-142
No files matched your search
@@ -0,0 +1,103 @@
|
||||
// 用户认证 & LDAP
|
||||
// 从 services/api.ts 拆分 — Q3 api.ts 模块化
|
||||
|
||||
import { http, getApiBase, type ListResponse } from '@/utils/request';
|
||||
import { useUserStore } from '@/store';
|
||||
|
||||
export const userApi = {
|
||||
login: async (username: string, password: string) => {
|
||||
return http.post<{ token: string; expires_in: number; user: unknown; permissions?: string[] }>(
|
||||
'/auth/login',
|
||||
{ username, password }
|
||||
);
|
||||
},
|
||||
getMyPermissions: async () => {
|
||||
return http.get<{ permissions: string[]; is_admin: boolean }>('/user/permissions');
|
||||
},
|
||||
register: async (data: { username: string; password: string; nickname?: string; email?: string }) => {
|
||||
return http.post('/auth/register', data);
|
||||
},
|
||||
getProfile: async () => {
|
||||
return http.get('/user/profile');
|
||||
},
|
||||
updateProfile: async ( data: any) => {
|
||||
return http.put('/user/profile', data);
|
||||
},
|
||||
changePassword: async (data: { old_password: string; new_password: string }) => {
|
||||
return http.put('/user/password', data);
|
||||
},
|
||||
getUsers: async (params?: { page?: number; page_size?: number; keyword?: string }) => {
|
||||
return http.get<ListResponse>('/admin/users', params);
|
||||
},
|
||||
createUser: async ( data: any) => {
|
||||
return http.post('/admin/users', data);
|
||||
},
|
||||
updateUser: async (id: number | string, data: any) => {
|
||||
return http.put(`/admin/users/${id}`, data);
|
||||
},
|
||||
deleteUser: async (id: number | string) => {
|
||||
return http.delete(`/admin/users/${id}`);
|
||||
},
|
||||
batchImport: async (data: { users: any[]; skip_existing?: boolean }) => {
|
||||
return http.post('/admin/users/batch-import', data);
|
||||
},
|
||||
downloadTemplate: () => {
|
||||
const token = useUserStore.getState().token || localStorage.getItem('token') || '';
|
||||
window.open(`${getApiBase()}/admin/users/import-template?token=${token}`, '_blank');
|
||||
},
|
||||
// 角色列表 // Logan.Li
|
||||
getRoles: async () => {
|
||||
return http.get<ListResponse>('/user/roles');
|
||||
},
|
||||
// 角色管理(管理员) // Logan.Li
|
||||
createRole: async (data: { name: string; code: string; description?: string; permission_ids?: number[] }) => {
|
||||
return http.post('/admin/roles', data);
|
||||
},
|
||||
updateRole: async (id: number | string, data: { name?: string; code?: string; description?: string; permission_ids?: number[] }) => {
|
||||
return http.put(`/admin/roles/${id}`, data);
|
||||
},
|
||||
deleteRole: async (id: number | string) => {
|
||||
return http.delete(`/admin/roles/${id}`);
|
||||
},
|
||||
// 权限列表(供角色权限选择)
|
||||
getPermissions: async () => {
|
||||
return http.get<ListResponse>('/admin/permissions');
|
||||
},
|
||||
};
|
||||
|
||||
// ==================== LDAP 配置 API ====================
|
||||
|
||||
export const ldapApi = {
|
||||
getConfig: async () => {
|
||||
return http.get('/admin/ldap-config');
|
||||
},
|
||||
updateConfig: async ( data: any) => {
|
||||
return http.put('/admin/ldap-config', data);
|
||||
},
|
||||
testConnection: async (data?: { test_user?: string; test_password?: string }) => {
|
||||
return http.post('/admin/ldap-config/test', data || {});
|
||||
},
|
||||
listUsers: async (ouDn?: string) => {
|
||||
return http.post('/admin/ldap-config/users', { ou_dn: ouDn || '' });
|
||||
},
|
||||
batchImport: async ( users: any[]) => {
|
||||
return http.post('/admin/ldap-config/import', { users });
|
||||
},
|
||||
listOUs: async () => {
|
||||
return http.post('/admin/ldap-config/ou-list', {});
|
||||
},
|
||||
createOU: async (data: { ou_name: string; parent_dn?: string; description?: string }) => {
|
||||
return http.post('/admin/ldap-config/create-ou', data);
|
||||
},
|
||||
createUser: async (data: { username: string; password: string; display_name?: string; email?: string; ou_dn?: string }) => {
|
||||
return http.post('/admin/ldap-config/create-user', data);
|
||||
},
|
||||
deleteUser: async (dn: string) => {
|
||||
return http.post('/admin/ldap-config/delete-user', { dn });
|
||||
},
|
||||
updateUser: async (data: { dn: string; cn?: string; mail?: string; phone?: string; title?: string }) => {
|
||||
return http.post('/admin/ldap-config/update-user', data);
|
||||
},
|
||||
};
|
||||
|
||||
// ==================== 仪表盘 API ====================
|
||||
Reference in new issue
Block a user