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,104 @@
|
||||
// 服务器/资产/区域/资源型号
|
||||
// 从 services/api.ts 拆分 — Q3 api.ts 模块化
|
||||
|
||||
import { http, type ListResponse } from '@/utils/request';
|
||||
|
||||
export const serverApi = {
|
||||
getServers: async (params?: { page?: number; page_size?: number; keyword?: string; status?: string }) => {
|
||||
return http.get<ListResponse>('/servers', params);
|
||||
},
|
||||
getServerDetail: async (id: number | string) => {
|
||||
return http.get(`/servers/${id}`);
|
||||
},
|
||||
getServerStats: async () => {
|
||||
return http.get('/servers/stats');
|
||||
},
|
||||
createServer: async ( data: any) => {
|
||||
return http.post('/servers', data);
|
||||
},
|
||||
updateServer: async (id: number | string, data: any) => {
|
||||
return http.put(`/servers/${id}`, data);
|
||||
},
|
||||
deleteServer: async (id: number | string) => {
|
||||
return http.delete(`/servers/${id}`);
|
||||
},
|
||||
batchDelete: async (ids: number[]) => {
|
||||
return http.post('/servers/batch-delete', { ids });
|
||||
},
|
||||
batchCreate: async (data: { servers: any[]; region_id?: string; auth_type?: string; credential_id?: number; default_port?: number }) => {
|
||||
return http.post('/servers/batch', data);
|
||||
},
|
||||
getMetrics: async (_id: number | string) => {
|
||||
// 后端暂无单机 metrics,用 dashboard metrics
|
||||
return http.get('/dashboard/metrics');
|
||||
},
|
||||
// 远程安装 Agent(通过 SSH 执行安装脚本),可选传入凭据
|
||||
installAgent: async (id: number | string, token: string, creds?: { username?: string; password?: string; ssh_key?: string; auth_type?: string }) => {
|
||||
const body: Record<string, any> = { token };
|
||||
if (creds) Object.assign(body, creds);
|
||||
return http.post<{ installed: boolean; arch: string; output: string }>(`/servers/${id}/install-agent`, body);
|
||||
},
|
||||
// 批量远程安装 Agent
|
||||
batchInstallAgent: async (ids: number[], token: string) => {
|
||||
return http.post<{ total: number; success: number; results: any[] }>(`/servers/install-agent?token=${encodeURIComponent(token)}`, { server_ids: ids });
|
||||
},
|
||||
|
||||
// SFTP 文件浏览
|
||||
listFiles: async (serverId: number, path: string) => {
|
||||
return http.get(`/servers/${serverId}/files?path=${encodeURIComponent(path)}`);
|
||||
},
|
||||
downloadFile: async (serverId: number, filePath: string) => {
|
||||
return http.download(`/servers/${serverId}/files/download?path=${encodeURIComponent(filePath)}`);
|
||||
},
|
||||
uploadFile: async (serverId: number, dirPath: string, file: File) => {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return http.upload(`/servers/${serverId}/files/upload?path=${encodeURIComponent(dirPath)}`, formData);
|
||||
},
|
||||
deleteFile: async (serverId: number, filePath: string) => {
|
||||
return http.delete(`/servers/${serverId}/files?path=${encodeURIComponent(filePath)}`);
|
||||
},
|
||||
mkdir: async (serverId: number, dirPath: string) => {
|
||||
return http.post(`/servers/${serverId}/files/mkdir`, { path: dirPath });
|
||||
},
|
||||
};
|
||||
|
||||
// ==================== Kubernetes 集群 API ====================
|
||||
|
||||
export const regionApi = {
|
||||
list: async () => {
|
||||
return http.get<ListResponse>('/regions');
|
||||
},
|
||||
create: async ( data: any) => {
|
||||
return http.post('/regions', data);
|
||||
},
|
||||
update: async (id: number | string, data: any) => {
|
||||
return http.put(`/regions/${id}`, data);
|
||||
},
|
||||
delete: async (id: number | string) => {
|
||||
return http.delete(`/regions/${id}`);
|
||||
},
|
||||
// 批量删除 // Logan.Li
|
||||
batchDelete: async (ids: number[]) => {
|
||||
return http.delete('/regions/batch-delete', { ids });
|
||||
},
|
||||
};
|
||||
|
||||
// ==================== 资源模型 API ====================
|
||||
|
||||
export const resourceModelApi = {
|
||||
list: async () => {
|
||||
return http.get<ListResponse>('/resource-models');
|
||||
},
|
||||
create: async ( data: any) => {
|
||||
return http.post('/resource-models', data);
|
||||
},
|
||||
update: async (id: number | string, data: any) => {
|
||||
return http.put(`/resource-models/${id}`, data);
|
||||
},
|
||||
delete: async (id: number | string) => {
|
||||
return http.delete(`/resource-models/${id}`);
|
||||
},
|
||||
};
|
||||
|
||||
// ==================== 审计日志 API ====================
|
||||
Reference in new issue
Block a user