Files
Nexus/frontend/src/constants/watchTtl.ts
T
Nexus Agent 647ebcb673 feat(watch): 监测槽分钟时长档、指标进度条与负载显示
默认 30 分钟,支持 30分/1时/2时/8时/24时;槽卡展示 CPU/内存/硬盘进度条与 1 分钟负载;API 改用 ttl_minutes。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-12 04:34:52 +08:00

37 lines
1.2 KiB
TypeScript

/** Watch slot monitoring duration options (minutes). */
export type WatchTtlMinutes = 30 | 60 | 120 | 480 | 1440
export const WATCH_TTL_DEFAULT_MINUTES: WatchTtlMinutes = 30
export const WATCH_TTL_OPTIONS: { minutes: WatchTtlMinutes; label: string }[] = [
{ minutes: 30, label: '30分' },
{ minutes: 60, label: '1时' },
{ minutes: 120, label: '2时' },
{ minutes: 480, label: '8时' },
{ minutes: 1440, label: '24时' },
]
export function normalizeWatchTtlMinutes(raw: number | null | undefined): WatchTtlMinutes {
const allowed = new Set(WATCH_TTL_OPTIONS.map((o) => o.minutes))
if (raw != null && allowed.has(raw as WatchTtlMinutes)) return raw as WatchTtlMinutes
if (raw === 8) return 480
if (raw === 24) return 1440
return WATCH_TTL_DEFAULT_MINUTES
}
export function watchTtlLabel(minutes: WatchTtlMinutes): string {
return WATCH_TTL_OPTIONS.find((o) => o.minutes === minutes)?.label ?? `${minutes}分`
}
export function watchTtlShortLabel(minutes: WatchTtlMinutes): string {
const map: Record<WatchTtlMinutes, string> = {
30: '30分钟',
60: '1小时',
120: '2小时',
480: '8小时',
1440: '24小时',
}
return map[minutes] ?? `${minutes}分钟`
}