/*
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 (
);
};
if (!channelStatus || channelStatus.length === 0) {
return (
}
title={t('暂无渠道数据')}
description={t('请稍后刷新或联系管理员')}
>
} onClick={onRefresh}>
{t('刷新数据')}
);
}
return (