refactor(frontend): P0 API 层收口与 http 统一
- 统一 http.ts baseURL:get/post/download/upload 均走 resolveApiUrl - agentUtils 下沉至 lib/agent-utils,API 层移除对 components 的依赖 - 扩展 metricsApi/snmpApi/prometheusProxyApi/zabbixProxyApi - 扩展 pipelineApi/credentialApi 覆盖流水线与凭证场景 - 14 个组件/页面禁止直连 http,统一走 @/services/api
This commit is contained in:
1 parent
bfd6431b9d
commit
7fb2236b4d
27 files changed
+194
-150
No files matched your search
@@ -1,32 +1,2 @@
|
||||
// Agent 监控相关工具函数(从 AgentMonitor.tsx 提取,供多组件共享) // Logan.Li
|
||||
|
||||
/** 在线判定:3 分钟内有上报视为在线 */
|
||||
export function isOnline( lastReport: any): boolean {
|
||||
if (!lastReport) return false;
|
||||
const t = new Date(lastReport).getTime();
|
||||
if (Number.isNaN(t)) return false;
|
||||
return Date.now() - t < 3 * 60 * 1000;
|
||||
}
|
||||
|
||||
/** 相对时间格式化("3分钟前" / "2小时前") */
|
||||
export function timeAgo( ts: any): string {
|
||||
if (!ts) return '--';
|
||||
const t = new Date(ts).getTime();
|
||||
if (Number.isNaN(t)) return '--';
|
||||
const diff = Math.floor((Date.now() - t) / 1000);
|
||||
if (diff < 60) return `${diff}秒前`;
|
||||
if (diff < 3600) return `${Math.floor(diff / 60)}分钟前`;
|
||||
if (diff < 86400) return `${Math.floor(diff / 3600)}小时前`;
|
||||
return new Date(ts).toLocaleString();
|
||||
}
|
||||
|
||||
/** 兼容多种列表响应包装:数组 / {list} / {items} / {data} */
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function asList( data: any): any[] {
|
||||
if (!data) return [];
|
||||
if (Array.isArray(data)) return data;
|
||||
if (Array.isArray(data.list)) return data.list;
|
||||
if (Array.isArray(data.items)) return data.items;
|
||||
if (Array.isArray(data.data)) return data.data;
|
||||
return [];
|
||||
}
|
||||
// 兼容旧路径,统一从 lib 导出 // Logan.Li
|
||||
export { isOnline, timeAgo, asList } from '@/lib/agent-utils';
|
||||
Reference in new issue
Block a user