feat: 修复仪表盘数据管线 — 补充应用发布种子数据 + 修复limit参数解析 + LDAP认证集成 + User类型完善

后端改进:
- 修复 dashboard/recent-alerts 的 limit 参数解析 (原代码错误地将数字解析为日期)
- 为 dashboard/recent-releases 添加 limit 参数解析支持
- 新增 generateAppReleases 种子数据生成函数 (10条应用发布记录)
- 修复 AlertEvent 的 rule_name/rule_id/severity 数据一致性
- 添加 go-ldap/ldap/v3 依赖并集成 LDAP 认证处理器
- 添加 seed.go 自动种子数据初始化 (admin用户+LDAP配置)
- User model 添加 AuthSource/LDAPConfig 字段

前端改进:
- 修复 User 类型定义以匹配后端 API (real_name/is_admin/auth_source等)
- 修复 Header.tsx 的 real_name 属性引用导致 TypeScript 编译错误
- 统一 API 服务层、暗色主题样式、组件联调优化

验证:
- go build ./... 编译通过
- npm run build 构建通过
- 仪表盘发布历史、告警消息等区域数据正常展示
- 健康检查 /health 正常
This commit is contained in:
attacker committed 2026-06-14 02:11:10 +08:00
1 parent 97c4207ff8
commit ff0b268984
39 files changed
+4283 -1878

No files matched your search

+81
View File
@@ -0,0 +1,81 @@
import { useUserStore } from '@/store';
const BASE_URL = '/api/v1';
// 后端统一响应格式
export interface ApiResponse<T = any> {
code: number;
message: string;
data: T;
}
// 列表响应格式
export interface ListResponse<T = any> {
list: T[];
total: number;
}
// 通用请求函数
async function request<T = any>(
method: string,
url: string,
body?: any,
params?: Record<string, any>
): Promise<T> {
// 构建 URL(含 query params)
let fullUrl = `${BASE_URL}${url}`;
if (params) {
const searchParams = new URLSearchParams();
Object.entries(params).forEach(([key, value]) => {
if (value !== undefined && value !== null && value !== '') {
searchParams.append(key, String(value));
}
});
const qs = searchParams.toString();
if (qs) fullUrl += `?${qs}`;
}
// 获取 token
const token = useUserStore.getState().token;
const headers: Record<string, string> = {
'Content-Type': 'application/json',
};
if (token) {
headers['Authorization'] = `Bearer ${token}`;
}
const response = await fetch(fullUrl, {
method,
headers,
body: body ? JSON.stringify(body) : undefined,
});
if (response.status === 401) {
useUserStore.getState().logout();
window.location.href = '/login';
throw new Error('登录已过期,请重新登录');
}
const json: ApiResponse<T> = await response.json();
if (json.code && json.code !== 200) {
throw new Error(json.message || '请求失败');
}
return json.data;
}
// 导出便捷方法
export const http = {
get: <T = any>(url: string, params?: Record<string, any>) =>
request<T>('GET', url, undefined, params),
post: <T = any>(url: string, body?: any) =>
request<T>('POST', url, body),
put: <T = any>(url: string, body?: any) =>
request<T>('PUT', url, body),
delete: <T = any>(url: string) =>
request<T>('DELETE', url),
};
export default http;