Files
aiops/frontend/src/components/server/serverHelpers.tsx
T
Logan.Li e0d652d211 feat: 完善堡垒机与 Agent 智能运维能力
- 支持 Windows Agent 构建、安装脚本和统一上报协议

- 增强 RDP 剪贴板、虚拟盘和文件传输能力

- 新增 AIOps 上下文工具、告警 RCA trace 落库和回放接口

- 重构 docs 模块文档并补充终端、堡垒机、监控、AI Agent 设计
2026-07-05 23:49:36 +08:00

74 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 服务器管理共享纯函数/常量 // Logan.Li
import { Badge } from '@/components/ui/badge';
import i18n from '@/i18n';
import type { Server as ServerType } from '@/types';
import type { JsonData } from '@/types/common';
// isRdpServer 判断资产是否应展示 RDP 入口(兼容云导入仅填 os 字段的历史数据) // Logan.Li
export function isRdpServer(server: JsonData): boolean {
const protocol = String(server.protocol || '').toLowerCase();
if (protocol === 'rdp') return true;
const osType = String(server.os_type || server.os || '').toLowerCase();
return osType.includes('windows') || osType.includes('win');
}
// 解析标签:后端 tags 可能是 JSON 字符串(JSON数组/对象)、逗号分隔字符串或数组 // Logan.Li
export function getTags(server: JsonData): string[] {
const tags = server.tags;
if (!tags) return [];
if (Array.isArray(tags)) return tags;
try {
const parsed = JSON.parse(tags);
if (Array.isArray(parsed)) return parsed;
// JSON 对象 → key:value 格式展示(如 project:prod) // Logan.Li
if (typeof parsed === 'object' && parsed !== null) {
return Object.entries(parsed).map(([k, v]) => `${k}:${String(v)}`);
}
return [String(parsed)];
} catch {
return String(tags)
.split(',')
.map((t: string) => t.trim())
.filter(Boolean);
}
}
// 服务器状态徽章 // Logan.Li
export function getStatusBadge(status: ServerType['status']) {
switch (status) {
case 'running':
return (
<Badge variant="outline" className="border-emerald-500/30 dg-text-green bg-emerald-500/10">
<div className="w-1.5 h-1.5 rounded-full bg-emerald-400 mr-1.5 animate-pulse" />
{i18n.t('server.statusBadge.running')}
</Badge>
);
case 'stopped':
return (
<Badge variant="outline" className="border-[var(--dg-border)] text-[var(--dg-text-muted)] bg-[var(--dg-bg-tertiary)]">
{i18n.t('server.statusBadge.stopped')}
</Badge>
);
case 'maintenance':
return (
<Badge variant="outline" className="border-amber-500/30 dg-text-yellow bg-amber-500/10">
<div className="w-1.5 h-1.5 rounded-full bg-amber-400 mr-1.5" />
{i18n.t('server.statusBadge.maintenance')}
</Badge>
);
case 'offline':
return (
<Badge variant="outline" className="border-red-500/30 dg-text-red bg-red-500/10">
{i18n.t('server.statusBadge.offline')}
</Badge>
);
default:
return null;
}
}
// 使用率进度条颜色(CPU/内存通用)— 绿色<60% 黄色60-80% 红色>80% // Logan.Li
export function getUsageColor(usage: number): string {
return usage > 80 ? 'bg-red-400' : usage > 60 ? 'bg-amber-400' : 'bg-emerald-400';
}