Initial import of weiyuan frontend

This commit is contained in:
qiubaishen
2026-10-15 16:33:46 +08:00
commit d8f3aee261
774 changed files with 374914 additions and 0 deletions
+478
View File
@@ -0,0 +1,478 @@
/*
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 <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useState, useEffect } from 'react';
import { Card, Row, Col, Badge, Empty, Spin } from '@douyinfe/semi-ui';
import { Activity, Zap } from 'lucide-react';
import { useTranslation } from 'react-i18next';
// 模拟渠道数据
const generateMockChannels = () => {
const channelNames = [
'OpenAI GPT-4',
'Claude 3.5 Sonnet',
'Gemini Pro',
'DeepSeek V3',
'Qwen Plus',
'Moonshot AI',
'GLM-4',
'Doubao Pro',
];
const statuses = ['available', 'available', 'available', 'busy', 'disabled'];
const speedLevels = ['fast', 'fast', 'medium', 'slow'];
return channelNames.map((name, index) => {
const status = statuses[Math.floor(Math.random() * statuses.length)];
const speed = speedLevels[Math.floor(Math.random() * speedLevels.length)];
// 生成稳定性趋势数据(24小时)
const stability = Array.from({ length: 24 }, () =>
status === 'available'
? 85 + Math.random() * 15 // 85-100%
: status === 'busy'
? 60 + Math.random() * 25 // 60-85%
: 0,
);
return {
id: index + 1,
name,
status,
speed,
speedMs:
speed === 'fast'
? 200 + Math.random() * 300
: speed === 'medium'
? 500 + Math.random() * 500
: 1000 + Math.random() * 1000,
stability,
uptime:
status === 'available'
? 99.5 + Math.random() * 0.5
: status === 'busy'
? 95 + Math.random() * 4
: 0,
};
});
};
const ChannelMonitor = () => {
const { t } = useTranslation();
const [channels, setChannels] = useState([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
// 模拟数据加载
setTimeout(() => {
setChannels(generateMockChannels());
setLoading(false);
}, 800);
// 每30秒刷新一次数据
const interval = setInterval(() => {
setChannels(generateMockChannels());
}, 30000);
return () => clearInterval(interval);
}, []);
const getStatusConfig = (status) => {
const configs = {
available: {
color: 'var(--semi-color-success)',
bgColor: 'rgba(82, 196, 26, 0.1)',
text: t('可用'),
dotColor: 'success',
},
busy: {
color: 'var(--semi-color-warning)',
bgColor: 'rgba(250, 173, 20, 0.1)',
text: t('繁忙'),
dotColor: 'warning',
},
unavailable: {
color: 'var(--semi-color-danger)',
bgColor: 'rgba(255, 77, 79, 0.1)',
text: t('不可用'),
dotColor: 'danger',
},
disabled: {
color: '#8c8c8c',
bgColor: 'rgba(140, 140, 140, 0.1)',
text: t('已关闭'),
dotColor: 'tertiary',
},
};
return configs[status] || configs.disabled;
};
const getSpeedConfig = (speed) => {
const configs = {
fast: {
color: 'var(--semi-color-success)',
width: '85%',
text: t('快'),
gradient:
'linear-gradient(90deg, var(--semi-color-success) 0%, #95de64 100%)',
},
medium: {
color: 'var(--semi-color-warning)',
width: '60%',
text: t('中等'),
gradient:
'linear-gradient(90deg, var(--semi-color-warning) 0%, #ffd666 100%)',
},
slow: {
color: 'var(--semi-color-danger)',
width: '35%',
text: t('慢'),
gradient:
'linear-gradient(90deg, var(--semi-color-danger) 0%, #ff7875 100%)',
},
};
return configs[speed] || configs.medium;
};
const renderSparkline = (data) => {
if (!data || data.length === 0) return null;
const max = Math.max(...data);
const min = Math.min(...data);
const range = max - min || 1;
const points = data
.map((value, index) => {
const x = (index / (data.length - 1)) * 100;
const y = 100 - ((value - min) / range) * 100;
return `${x},${y}`;
})
.join(' ');
const avgStability = data.reduce((a, b) => a + b, 0) / data.length;
const lineColor =
avgStability >= 95
? 'var(--semi-color-success)'
: avgStability >= 85
? 'var(--semi-color-warning)'
: 'var(--semi-color-danger)';
return (
<svg
width='100%'
height='40'
viewBox='0 0 100 100'
preserveAspectRatio='none'
style={{ display: 'block' }}
>
<defs>
<linearGradient
id={`gradient-${data[0]}`}
x1='0%'
y1='0%'
x2='0%'
y2='100%'
>
<stop
offset='0%'
style={{ stopColor: lineColor, stopOpacity: 0.3 }}
/>
<stop
offset='100%'
style={{ stopColor: lineColor, stopOpacity: 0 }}
/>
</linearGradient>
</defs>
<polyline
fill={`url(#gradient-${data[0]})`}
stroke='none'
points={`0,100 ${points} 100,100`}
/>
<polyline
fill='none'
stroke={lineColor}
strokeWidth='2'
points={points}
/>
</svg>
);
};
if (loading) {
return (
<div style={{ textAlign: 'center', padding: '60px 0' }}>
<Spin size='large' />
</div>
);
}
if (channels.length === 0) {
return <Empty description={t('暂无渠道数据')} />;
}
return (
<div className='channel-monitor'>
<style>
{`
.channel-card {
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
border: 1px solid var(--semi-color-border);
position: relative;
overflow: hidden;
}
.channel-card:hover {
transform: translateY(-4px);
box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
border-color: var(--semi-color-primary);
}
.channel-card::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
height: 3px;
background: linear-gradient(90deg, var(--semi-color-primary) 0%, var(--semi-color-primary-light-default) 100%);
opacity: 0;
transition: opacity 0.3s;
}
.channel-card:hover::before {
opacity: 1;
}
.status-badge {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 4px 12px;
border-radius: 12px;
font-size: 12px;
font-weight: 500;
}
.speed-bar-container {
position: relative;
height: 24px;
background: var(--semi-color-fill-0);
border-radius: 12px;
overflow: hidden;
}
.speed-bar {
height: 100%;
border-radius: 12px;
transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
display: flex;
align-items: center;
padding: 0 12px;
font-size: 12px;
font-weight: 600;
color: white;
}
.metric-item {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 0;
}
.metric-icon {
display: flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
border-radius: 8px;
background: var(--semi-color-fill-0);
}
.metric-value {
font-size: 20px;
font-weight: 600;
color: var(--semi-color-text-0);
}
.metric-label {
font-size: 12px;
color: var(--semi-color-text-2);
}
`}
</style>
<Row gutter={[16, 16]}>
{channels.map((channel) => {
const statusConfig = getStatusConfig(channel.status);
const speedConfig = getSpeedConfig(channel.speed);
return (
<Col key={channel.id} xs={24} sm={12} lg={8} xl={6}>
<Card
className='channel-card'
bodyStyle={{ padding: '20px' }}
style={{ height: '100%' }}
>
{/* 渠道名称和状态 */}
<div style={{ marginBottom: '16px' }}>
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
marginBottom: '8px',
}}
>
<h4
style={{
margin: 0,
fontSize: '16px',
fontWeight: 600,
color: 'var(--semi-color-text-0)',
}}
>
{channel.name}
</h4>
</div>
<div
style={{
display: 'inline-block',
padding: '4px 12px',
borderRadius: '12px',
fontSize: '12px',
fontWeight: 500,
color: statusConfig.color,
backgroundColor: statusConfig.bgColor,
border: `1px solid ${statusConfig.color}30`,
}}
>
<Badge
dot
type={statusConfig.dotColor}
style={{ marginRight: '6px' }}
/>
{statusConfig.text}
</div>
</div>
{/* 响应速度 */}
<div style={{ marginBottom: '16px' }}>
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
marginBottom: '8px',
}}
>
<span
style={{
fontSize: '13px',
fontWeight: 500,
color: 'var(--semi-color-text-1)',
}}
>
<Zap
size={14}
style={{ marginRight: '4px', verticalAlign: 'middle' }}
/>
{t('响应速度')}
</span>
<span
style={{
fontSize: '12px',
color: 'var(--semi-color-text-2)',
}}
>
{Math.round(channel.speedMs)}ms
</span>
</div>
<div className='speed-bar-container'>
<div
className='speed-bar'
style={{
width: speedConfig.width,
background: speedConfig.gradient,
}}
>
{speedConfig.text}
</div>
</div>
</div>
{/* 稳定性趋势 */}
<div style={{ marginBottom: '12px' }}>
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
marginBottom: '8px',
}}
>
<span
style={{
fontSize: '13px',
fontWeight: 500,
color: 'var(--semi-color-text-1)',
}}
>
<Activity
size={14}
style={{ marginRight: '4px', verticalAlign: 'middle' }}
/>
{t('稳定性')} (24h)
</span>
<span
style={{
fontSize: '12px',
fontWeight: 600,
color:
channel.uptime >= 99
? 'var(--semi-color-success)'
: channel.uptime >= 95
? 'var(--semi-color-warning)'
: 'var(--semi-color-danger)',
}}
>
{channel.uptime.toFixed(2)}%
</span>
</div>
<div
style={{
background: 'var(--semi-color-fill-0)',
borderRadius: '8px',
padding: '8px',
}}
>
{renderSparkline(channel.stability)}
</div>
</div>
</Card>
</Col>
);
})}
</Row>
</div>
);
};
export default ChannelMonitor;