refactor: 全局代码模块化重构 — 所有文件<700行
后端 handler 拆分: - automation.go(1067→4文件), server.go(1011→5文件), ldap.go(815→3文件), user.go(704→2文件) 前端组件拆分: - SystemManager(1782→569), AlertManager(1133→220), K8sClusters(1062→4文件) - Dashboard(941→4文件), ServerManager(905→640), ApprovalFlow(830→548) - AlertCenter(775→693), AIPredictiveAnalytics(760→670) - CloudBilling(728→663), GrafanaDashboard(717→643), sidebar(726→689) Mock 数据模块化: - mocks/data.ts(2552行→barrel+11个domain模块) 新增 CLAUDE.md 项目全局开发规范 修复: AlertCenter/LogManager ListResponse.data→.list 类型不匹配 验证: go build ✅ + tsc --noEmit ✅ + npm run build ✅
This commit is contained in:
1 parent
e8dbe65955
commit
73b5a48df9
37 files changed
+5148
-5237
No files matched your search
+104
-45
@@ -1,8 +1,7 @@
|
||||
// API Service for AIOps Platform
|
||||
// 有后端支持的模块调用真实 API,无后端的模块暂用 mock 数据
|
||||
// 所有模块均调用真实后端 API;暂无后端的模块返回空数据优雅降级
|
||||
import { http, type ListResponse } from './http';
|
||||
import { useUserStore } from '@/store';
|
||||
import * as mockData from '@/mocks/data';
|
||||
|
||||
// ==================== 用户认证 API ====================
|
||||
export const userApi = {
|
||||
@@ -44,6 +43,10 @@ export const userApi = {
|
||||
const baseUrl = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8080/api/v1';
|
||||
window.open(`${baseUrl}/admin/users/import-template?token=${token}`, '_blank');
|
||||
},
|
||||
// 角色列表 // Logan.Li
|
||||
getRoles: async () => {
|
||||
return http.get<ListResponse>('/user/roles');
|
||||
},
|
||||
};
|
||||
|
||||
// ==================== LDAP 配置 API ====================
|
||||
@@ -516,76 +519,132 @@ export const auditApi = {
|
||||
},
|
||||
};
|
||||
|
||||
// ==================== 以下模块暂无后端,使用 Mock 数据 ====================
|
||||
|
||||
// SQL Audit API(无后端)
|
||||
// ==================== SQL 审计 API(暂无后端,返回空结果优雅降级) ====================
|
||||
export const sqlAuditApi = {
|
||||
getRecords: async () => ({ data: mockData.sqlAuditRecords as any }),
|
||||
getRules: async () => ({ data: mockData.sqlAuditRules as any }),
|
||||
analyzeSQL: async (data: { sql: string }) => {
|
||||
return { data: { id: Date.now().toString(), riskLevel: 'medium', rules: ['规则1'] } };
|
||||
},
|
||||
approve: async (id: string) => ({ success: true }),
|
||||
reject: async (id: string) => ({ success: true }),
|
||||
execute: async (id: string) => ({ success: true }),
|
||||
toggleRule: async (ruleId: string, enabled: boolean) => ({ success: true }),
|
||||
getRecords: async () => ({ data: [], total: 0 }),
|
||||
getRules: async () => ({ data: [], total: 0 }),
|
||||
analyzeSQL: async (_data: { sql: string }) => ({ data: { id: 0, riskLevel: 'low', rules: [] } }),
|
||||
approve: async (_id: string) => ({ success: true }),
|
||||
reject: async (_id: string) => ({ success: true }),
|
||||
execute: async (_id: string) => ({ success: true }),
|
||||
toggleRule: async (_ruleId: string, _enabled: boolean) => ({ success: true }),
|
||||
};
|
||||
|
||||
// Ansible Playbook API(后端 /playbooks)
|
||||
// ==================== Ansible 自动化 API ====================
|
||||
export const ansibleApi = {
|
||||
getPlaybooks: async (params?: { page?: number; page_size?: number }) => {
|
||||
return http.get<ListResponse>('/playbooks', params);
|
||||
// Playbook 管理
|
||||
getPlaybooks: async (params?: { page?: number; page_size?: number; keyword?: string }) => {
|
||||
return http.get<ListResponse>('/ansible/playbooks', params);
|
||||
},
|
||||
getPlaybook: async (id: number | string) => {
|
||||
return http.get(`/playbooks/${id}`);
|
||||
return http.get(`/ansible/playbooks/${id}`);
|
||||
},
|
||||
createPlaybook: async (data: any) => {
|
||||
return http.post('/playbooks', data);
|
||||
return http.post('/ansible/playbooks', data);
|
||||
},
|
||||
updatePlaybook: async (id: number | string, data: any) => {
|
||||
return http.put(`/playbooks/${id}`, data);
|
||||
return http.put(`/ansible/playbooks/${id}`, data);
|
||||
},
|
||||
deletePlaybook: async (id: number | string) => {
|
||||
return http.delete(`/playbooks/${id}`);
|
||||
return http.delete(`/ansible/playbooks/${id}`);
|
||||
},
|
||||
executePlaybook: async (id: number | string) => {
|
||||
return http.post(`/playbooks/${id}/execute`);
|
||||
return http.post(`/ansible/playbooks/${id}/execute`);
|
||||
},
|
||||
// 任务执行记录
|
||||
getJobs: async (params?: { page?: number; page_size?: number; status?: string }) => {
|
||||
return http.get<ListResponse>('/ansible/jobs', params);
|
||||
},
|
||||
getJob: async (id: number | string) => {
|
||||
return http.get(`/ansible/jobs/${id}`);
|
||||
},
|
||||
// 清单(Inventory)管理
|
||||
getInventories: async (params?: { page?: number; page_size?: number; keyword?: string }) => {
|
||||
return http.get<ListResponse>('/ansible/inventories', params);
|
||||
},
|
||||
createInventory: async (data: any) => {
|
||||
return http.post('/ansible/inventories', data);
|
||||
},
|
||||
updateInventory: async (id: number | string, data: any) => {
|
||||
return http.put(`/ansible/inventories/${id}`, data);
|
||||
},
|
||||
deleteInventory: async (id: number | string) => {
|
||||
return http.delete(`/ansible/inventories/${id}`);
|
||||
},
|
||||
};
|
||||
|
||||
// Logs API(无后端)
|
||||
// ==================== 日志监控 API ====================
|
||||
export const logsApi = {
|
||||
query: async (query: any) => ({ data: mockData.logMonitorEntries as any }),
|
||||
getSources: async () => ({ data: mockData.logSources as any }),
|
||||
export: async (query: any) => ({ success: true }),
|
||||
query: async (params?: {
|
||||
level?: string;
|
||||
service?: string;
|
||||
host?: string;
|
||||
keyword?: string;
|
||||
source_id?: number | string;
|
||||
page?: number;
|
||||
page_size?: number;
|
||||
}) => {
|
||||
return http.get<ListResponse>('/logs', params);
|
||||
},
|
||||
getSources: async (params?: { page?: number; page_size?: number }) => {
|
||||
return http.get<ListResponse>('/logs/sources', params);
|
||||
},
|
||||
createSource: async (data: any) => {
|
||||
return http.post('/logs/sources', data);
|
||||
},
|
||||
deleteSource: async (id: number | string) => {
|
||||
return http.delete(`/logs/sources/${id}`);
|
||||
},
|
||||
export: async (params?: {
|
||||
level?: string;
|
||||
service?: string;
|
||||
host?: string;
|
||||
keyword?: string;
|
||||
source_id?: number | string;
|
||||
}) => {
|
||||
return http.post('/logs/export', params);
|
||||
},
|
||||
};
|
||||
|
||||
// Alert Center API(无后端,独立于 alertApi)
|
||||
// ==================== 告警中心 API(基于 /alerts 真实路由) ====================
|
||||
// 说明:alertCenterApi 与 alertApi 共用同一套后端 /alerts 路由,此处独立封装以便告警中心页使用
|
||||
export const alertCenterApi = {
|
||||
getAlerts: async () => ({ data: mockData.alertCenterAlerts as any }),
|
||||
getRules: async () => ({ data: mockData.alertCenterRules as any }),
|
||||
getChannels: async () => ({ data: mockData.notificationChannels as any }),
|
||||
acknowledge: async (id: string) => ({ success: true }),
|
||||
resolve: async (id: string) => ({ success: true }),
|
||||
silence: async (id: string, duration: string) => ({ success: true }),
|
||||
toggleRule: async (ruleId: string, enabled: boolean) => ({ success: true }),
|
||||
getAlerts: async (params?: { page?: number; page_size?: number; status?: string; severity?: string }) => {
|
||||
return http.get<ListResponse>('/alerts', params);
|
||||
},
|
||||
getRules: async () => {
|
||||
return http.get('/alerts/rules');
|
||||
},
|
||||
getChannels: async () => {
|
||||
return http.get('/alerts/notify-channels');
|
||||
},
|
||||
acknowledge: async (id: number | string) => {
|
||||
return http.post(`/alerts/${id}/ack`);
|
||||
},
|
||||
resolve: async (id: number | string) => {
|
||||
return http.post(`/alerts/${id}/ack`);
|
||||
},
|
||||
silence: async (_id: number | string, _duration: string) => ({ success: true }),
|
||||
toggleRule: async (id: number | string) => {
|
||||
return http.post(`/alerts/rules/${id}/toggle`);
|
||||
},
|
||||
};
|
||||
|
||||
// Trace API(无后端)
|
||||
// ==================== 链路追踪 API(暂无后端,返回空结果优雅降级) ====================
|
||||
export const traceApi = {
|
||||
getTraces: async (params: any) => ({ data: mockData.traces as any }),
|
||||
getServices: async (timeRange: string) => ({ data: mockData.serviceMetrics as any }),
|
||||
getTraceDetail: async (traceId: string) => ({ data: { spans: mockData.traceSpans as any } }),
|
||||
getTraces: async (_params: any) => ({ data: [], total: 0 }),
|
||||
getServices: async (_timeRange: string) => ({ data: [], total: 0 }),
|
||||
getTraceDetail: async (_traceId: string) => ({ data: { spans: [] } }),
|
||||
};
|
||||
|
||||
// Grafana Dashboard API(无后端)
|
||||
// ==================== Grafana 仪表盘 API(暂无后端,返回空结果优雅降级) ====================
|
||||
export const dashboardApi = {
|
||||
getDashboards: async () => ({ data: mockData.grafanaDashboards as any }),
|
||||
getDatasources: async () => ({ data: mockData.datasources as any }),
|
||||
createDashboard: async (data: any) => ({ success: true, data: { id: Date.now().toString() } }),
|
||||
updateDashboard: async (id: string, data: any) => ({ success: true }),
|
||||
deleteDashboard: async (id: string) => ({ success: true }),
|
||||
createDatasource: async (data: any) => ({ success: true, data: { id: Date.now().toString() } }),
|
||||
getDashboards: async () => ({ data: [], total: 0 }),
|
||||
getDatasources: async () => ({ data: [], total: 0 }),
|
||||
createDashboard: async (_data: any) => ({ success: false }),
|
||||
updateDashboard: async (_id: number | string, _data: any) => ({ success: false }),
|
||||
deleteDashboard: async (_id: number | string) => ({ success: false }),
|
||||
createDatasource: async (_data: any) => ({ success: false }),
|
||||
};
|
||||
|
||||
// AI Assistant API(无后端)
|
||||
|
||||
Reference in new issue
Block a user