/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import React from 'react'; import { Card, Grid, Typography, Tag, Progress, Empty, Button, } from '@/components/ui'; import { IconRefresh, IconAlertCircle } from '@/components/ui/icons'; import { useTranslation } from 'react-i18next'; const { Row, Col } = Grid; const { Title, Text } = Typography; const ChannelMonitorView = ({ channelStatus, onRefresh }) => { const { t } = useTranslation(); // 获取状态显示 const getStatusConfig = (status) => { switch (status) { case 1: // 在线 return { color: 'green', text: t('可用'), icon: '🟢' }; case 0: // 离线 return { color: 'red', text: t('不可用'), icon: '🔴' }; case 2: // 维护中 return { color: 'orange', text: t('维护中'), icon: '🟡' }; default: return { color: 'grey', text: t('未知'), icon: '⚪' }; } }; // 获取响应速度配置 const getSpeedConfig = (responseTime) => { if (responseTime < 1000) { return { level: t('快'), color: 'green', percent: 100, bars: '🟩🟩🟩' }; } else if (responseTime < 3000) { return { level: t('中等'), color: 'yellow', percent: 66, bars: '🟨🟨' }; } else { return { level: t('慢'), color: 'red', percent: 33, bars: '🟥' }; } }; // 渲染迷你趋势图 (Sparkline) const renderSparkline = (uptime) => { const width = 100; const height = 30; const points = 12; const data = Array.from({ length: points }, (_, i) => { // 模拟趋势数据,基于uptime生成波动 const baseValue = uptime * 100; const variance = (Math.random() - 0.5) * 10; return Math.max(0, Math.min(100, baseValue + variance)); }); const pathData = data .map((value, index) => { const x = (index / (points - 1)) * width; const y = height - (value / 100) * height; return `${index === 0 ? 'M' : 'L'} ${x},${y}`; }) .join(' '); return ( 0.9 ? 'var(--ui-color-success)' : uptime > 0.7 ? 'var(--ui-color-warning)' : 'var(--ui-color-danger)' } strokeWidth='2' /> ); }; if (!channelStatus || channelStatus.length === 0) { return ( } title={t('暂无渠道数据')} description={t('请稍后刷新或联系管理员')} > ); } return (
{/* 刷新按钮 */}
{/* 渠道分组展示 */} {channelStatus.map((group, groupIndex) => (
📁 {group.categoryName} {group.monitors && group.monitors.map((channel, index) => { const statusConfig = getStatusConfig(channel.status); const speedConfig = getSpeedConfig(channel.response_time || 0); return ( {statusConfig.icon} {channel.name}
} headerStyle={{ borderBottom: '2px solid #f0f0f0' }} style={{ height: '100%', border: `2px solid ${ channel.status === 1 ? '#52c41a20' : channel.status === 0 ? '#f5222d20' : '#faad1420' }`, }} styles={{ body: { padding: 16 } }} > {/* 1. 渠道状态 */}
{t('状态')}
{statusConfig.text}
{/* 2. 响应速度 */}
{t('响应速度')} {speedConfig.level}
{channel.response_time || 0}ms
{/* 3. 稳定性 (Sparkline) */}
{t('稳定性趋势 (24h)')}
{renderSparkline(channel.uptime || 0)} {((channel.uptime || 0) * 100).toFixed(1)}%
); })}
))} ); }; export default ChannelMonitorView;