diff --git a/frontend/src/components/agent/AgentAlerts.tsx b/frontend/src/components/agent/AgentAlerts.tsx index 7a802ff..e2a3d89 100644 --- a/frontend/src/components/agent/AgentAlerts.tsx +++ b/frontend/src/components/agent/AgentAlerts.tsx @@ -28,8 +28,10 @@ import { } from './agentAlertHelper'; import { AgentRuleDialog } from './AgentRuleDialog'; import type { JsonData } from '@/types/common'; +import { useTranslation } from 'react-i18next'; export function AgentAlerts() { + const { t } = useTranslation(); const confirm = useConfirm(); const [activeTab, setActiveTab] = useState('events'); const [alerts, setAlerts] = useState([]); @@ -52,7 +54,7 @@ export function AgentAlerts() { setRules(asList(rulesRes)); } catch (err) { console.error(err); - toast.error('加载告警数据失败'); + toast.error(t('agent.agentalerts.s7ffaa4')); } finally { setLoading(false); } @@ -64,14 +66,14 @@ export function AgentAlerts() { // ============ 告警事件 ============ const handleResolve = async (id: number) => { - const ok = await confirm({ title: '恢复告警', description: '确定将此告警标记为已恢复?', confirmText: '恢复' }); + const ok = await confirm({ title: t('agent.agentalerts.sd56d01'), description: t('agent.agentalerts.s99f0fb'), confirmText: t('common.resume') }); if (!ok) return; try { await agentApi.resolveAlert(id); - toast.success('告警已恢复'); + toast.success(t('agent.agentalerts.s0e2352')); loadData(); } catch (err) { - toast.error(err?.message || '操作失败'); + toast.error(err?.message || t('common.operationFailed')); } }; @@ -87,14 +89,14 @@ export function AgentAlerts() { }; const handleDeleteRule = async (id: number) => { - const ok = await confirm({ title: '删除规则', description: '确定删除此告警规则?', confirmText: '删除', variant: 'destructive' }); + const ok = await confirm({ title: t('alert.deleteRule'), description: t('agent.agentalerts.sd30155'), confirmText: t('common.delete'), variant: 'destructive' }); if (!ok) return; try { await agentApi.deleteRule(id); - toast.success('规则已删除'); + toast.success(t('agent.agentalerts.s8b2798')); loadData(); } catch (err) { - toast.error(err?.message || '删除失败'); + toast.error(err?.message || t('common.deleteFailed')); } }; @@ -103,7 +105,7 @@ export function AgentAlerts() { await agentApi.updateRule(rule.id, { ...rule, enabled: !rule.enabled }); loadData(); } catch (err) { - toast.error(err?.message || '操作失败'); + toast.error(err?.message || t('common.operationFailed')); } }; @@ -112,8 +114,8 @@ export function AgentAlerts() { {/* 页头 */}
-

Agent 告警

-

基于 Agent 上报指标的告警规则与事件

+

{t('agent.agentalerts.s87efbd')}

+

{t('agent.agentalerts.s03a08c')}

diff --git a/frontend/src/components/agent/AgentMonitor.tsx b/frontend/src/components/agent/AgentMonitor.tsx index 34c2975..13a3e77 100644 --- a/frontend/src/components/agent/AgentMonitor.tsx +++ b/frontend/src/components/agent/AgentMonitor.tsx @@ -23,6 +23,7 @@ import { } from '@/components/ui/dialog'; import { +import { useTranslation } from 'react-i18next'; Cpu, MemoryStick, HardDrive, @@ -41,6 +42,7 @@ import { // ============ 组件 ============ export function AgentMonitor() { + const { t } = useTranslation(); const [hosts, setHosts] = useState([]); const [loading, setLoading] = useState(true); const [refreshing, setRefreshing] = useState(false); @@ -68,7 +70,7 @@ export function AgentMonitor() { if (fresh) setSelectedHost(fresh); } } catch (err) { - if (!silent) toast.error('加载主机列表失败'); + if (!silent) toast.error(t('agent.agentmonitor.s5760f6')); console.error(err); } finally { setLoading(false); @@ -97,7 +99,7 @@ export function AgentMonitor() { // 提交远程命令(直连 SSH 即时返回) const submitCommand = async () => { if (!cmdCommand.trim()) { - toast.error('请输入要执行的命令'); + toast.error(t('agent.agentmonitor.s9358aa')); return; } setCmdSubmitting(true); @@ -111,11 +113,11 @@ export function AgentMonitor() { const resData = (res?.data ?? {}) as Record; setCmdResult({ status: res?.code === 200 ? 'completed' : 'failed', - result: (resData.output as string) || (res?.message as string) || '无输出', + result: (resData.output as string) || (res?.message as string) || t('agent.agentmonitor.s26d45b'), error: resData.error as string | undefined, }); } catch (err) { - setCmdResult({ status: 'failed', result: err?.message || '执行失败' }); + setCmdResult({ status: 'failed', result: err?.message || t('automation.scriptFailed') }); } finally { setCmdSubmitting(false); loadLatest(true); @@ -129,9 +131,9 @@ export function AgentMonitor() { const onlineCount = hosts.filter((h) => isOnline(h.last_report || h.last_reported_at || h.updated_at)).length; const stats = [ - { label: '主机总数', value: hosts.length, icon: Server, color: 'dg-text-blue' }, - { label: '在线', value: onlineCount, icon: Wifi, color: 'dg-text-green' }, - { label: '离线', value: hosts.length - onlineCount, icon: WifiOff, color: 'dg-text-red' }, + { label: t('agent.agentmonitor.sd94cd2'), value: hosts.length, icon: Server, color: 'dg-text-blue' }, + { label: t('common.online'), value: onlineCount, icon: Wifi, color: 'dg-text-green' }, + { label: t('common.offline'), value: hosts.length - onlineCount, icon: WifiOff, color: 'dg-text-red' }, ]; return ( @@ -139,8 +141,8 @@ export function AgentMonitor() { {/* 页头 */}
-

Agent 监控

-

实时监控 Agent 上报的主机指标

+

{t('agent.agentMonitor')}

+

{t('agent.agentmonitor.sa75d75')}