Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,776 @@
|
||||
/*
|
||||
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, Table, Spin } from '@douyinfe/semi-ui';
|
||||
import {
|
||||
TrendingUp,
|
||||
DollarSign,
|
||||
Activity,
|
||||
Layers,
|
||||
BarChart3,
|
||||
AlertTriangle,
|
||||
} from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
// 模拟管理员监控数据
|
||||
const generateMockAdminData = () => {
|
||||
const channels = [
|
||||
'OpenAI GPT-4',
|
||||
'Claude 3.5 Sonnet',
|
||||
'Gemini Pro',
|
||||
'DeepSeek V3',
|
||||
'Qwen Plus',
|
||||
];
|
||||
|
||||
// 生成24小时请求趋势
|
||||
const requestTrend = Array.from({ length: 24 }, (_, i) => ({
|
||||
hour: `${i}:00`,
|
||||
requests: Math.floor(Math.random() * 1000) + 500,
|
||||
}));
|
||||
|
||||
// 生成Token消耗趋势
|
||||
const tokenTrend = Array.from({ length: 12 }, (_, i) => ({
|
||||
time: `${i * 2}:00`,
|
||||
promptTokens: Math.floor(Math.random() * 50000) + 30000,
|
||||
completionTokens: Math.floor(Math.random() * 40000) + 20000,
|
||||
}));
|
||||
|
||||
// 成本分布
|
||||
const costDistribution = channels.map((name) => ({
|
||||
name,
|
||||
cost: Math.random() * 500 + 100,
|
||||
percentage: 0,
|
||||
}));
|
||||
|
||||
const totalCost = costDistribution.reduce((sum, item) => sum + item.cost, 0);
|
||||
costDistribution.forEach((item) => {
|
||||
item.percentage = ((item.cost / totalCost) * 100).toFixed(1);
|
||||
});
|
||||
|
||||
// 错误类型分布
|
||||
const errorTypes = [
|
||||
{ type: '速率超限 (Rate Limit)', count: 156 },
|
||||
{ type: '认证失败 (Auth Failed)', count: 89 },
|
||||
{ type: '超时 (Timeout)', count: 67 },
|
||||
{ type: '配额不足 (Quota Exceeded)', count: 45 },
|
||||
{ type: '模型不可用 (Model Unavailable)', count: 23 },
|
||||
];
|
||||
|
||||
// 渠道详细数据
|
||||
const channelDetails = channels.map((name, index) => ({
|
||||
id: index + 1,
|
||||
name,
|
||||
requests: Math.floor(Math.random() * 5000) + 1000,
|
||||
avgResponseTime: Math.floor(Math.random() * 800) + 200,
|
||||
tokens: Math.floor(Math.random() * 100000) + 50000,
|
||||
cost: costDistribution[index].cost.toFixed(2),
|
||||
successRate: (95 + Math.random() * 5).toFixed(2),
|
||||
}));
|
||||
|
||||
return {
|
||||
kpi: {
|
||||
totalRequests: requestTrend.reduce((sum, item) => sum + item.requests, 0),
|
||||
totalCost: totalCost.toFixed(2),
|
||||
activeChannels: channels.length,
|
||||
avgResponseTime: Math.floor(Math.random() * 300) + 200,
|
||||
},
|
||||
requestTrend,
|
||||
tokenTrend,
|
||||
costDistribution,
|
||||
errorTypes,
|
||||
channelDetails,
|
||||
quotaUsage: 73,
|
||||
};
|
||||
};
|
||||
|
||||
const AdminMonitor = () => {
|
||||
const { t } = useTranslation();
|
||||
const [data, setData] = useState(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
setTimeout(() => {
|
||||
setData(generateMockAdminData());
|
||||
setLoading(false);
|
||||
}, 1000);
|
||||
|
||||
const interval = setInterval(() => {
|
||||
setData(generateMockAdminData());
|
||||
}, 30000);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
const renderKPICard = (
|
||||
icon,
|
||||
label,
|
||||
value,
|
||||
suffix = '',
|
||||
color = '#1890ff',
|
||||
) => (
|
||||
<Card
|
||||
style={{
|
||||
background:
|
||||
'linear-gradient(135deg, rgba(24, 144, 255, 0.05) 0%, rgba(24, 144, 255, 0.01) 100%)',
|
||||
border: '1px solid var(--semi-color-border)',
|
||||
borderRadius: '12px',
|
||||
height: '100%',
|
||||
}}
|
||||
bodyStyle={{ padding: '24px' }}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: '16px' }}>
|
||||
<div
|
||||
style={{
|
||||
width: '48px',
|
||||
height: '48px',
|
||||
borderRadius: '12px',
|
||||
background: `${color}15`,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
{React.cloneElement(icon, { size: 24, color })}
|
||||
</div>
|
||||
<div style={{ flex: 1 }}>
|
||||
<div
|
||||
style={{
|
||||
fontSize: '13px',
|
||||
color: 'var(--semi-color-text-2)',
|
||||
marginBottom: '4px',
|
||||
}}
|
||||
>
|
||||
{label}
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
fontSize: '28px',
|
||||
fontWeight: 700,
|
||||
color: 'var(--semi-color-text-0)',
|
||||
lineHeight: 1,
|
||||
}}
|
||||
>
|
||||
{value}
|
||||
{suffix && (
|
||||
<span
|
||||
style={{ fontSize: '16px', fontWeight: 500, marginLeft: '4px' }}
|
||||
>
|
||||
{suffix}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
|
||||
const renderBarChart = (data, maxValue) => {
|
||||
return data.slice(0, 12).map((item, index) => {
|
||||
const percentage = (item.requests / maxValue) * 100;
|
||||
return (
|
||||
<div key={index} style={{ marginBottom: '12px' }}>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
marginBottom: '4px',
|
||||
fontSize: '12px',
|
||||
color: 'var(--semi-color-text-2)',
|
||||
}}
|
||||
>
|
||||
<span>{item.hour}</span>
|
||||
<span style={{ fontWeight: 600 }}>
|
||||
{item.requests.toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
height: '24px',
|
||||
background: 'var(--semi-color-fill-0)',
|
||||
borderRadius: '6px',
|
||||
overflow: 'hidden',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
height: '100%',
|
||||
width: `${percentage}%`,
|
||||
background: 'linear-gradient(90deg, #1890ff 0%, #40a9ff 100%)',
|
||||
borderRadius: '6px',
|
||||
transition: 'width 0.6s cubic-bezier(0.4, 0, 0.2, 1)',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const renderStackedAreaChart = (data) => {
|
||||
const maxTotal = Math.max(
|
||||
...data.map((d) => d.promptTokens + d.completionTokens),
|
||||
);
|
||||
|
||||
return (
|
||||
<div style={{ height: '200px', position: 'relative' }}>
|
||||
<svg
|
||||
width='100%'
|
||||
height='100%'
|
||||
viewBox='0 0 100 100'
|
||||
preserveAspectRatio='none'
|
||||
>
|
||||
<defs>
|
||||
<linearGradient
|
||||
id='promptGradient'
|
||||
x1='0%'
|
||||
y1='0%'
|
||||
x2='0%'
|
||||
y2='100%'
|
||||
>
|
||||
<stop
|
||||
offset='0%'
|
||||
style={{ stopColor: '#52c41a', stopOpacity: 0.6 }}
|
||||
/>
|
||||
<stop
|
||||
offset='100%'
|
||||
style={{ stopColor: '#52c41a', stopOpacity: 0.1 }}
|
||||
/>
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id='completionGradient'
|
||||
x1='0%'
|
||||
y1='0%'
|
||||
x2='0%'
|
||||
y2='100%'
|
||||
>
|
||||
<stop
|
||||
offset='0%'
|
||||
style={{ stopColor: '#1890ff', stopOpacity: 0.6 }}
|
||||
/>
|
||||
<stop
|
||||
offset='100%'
|
||||
style={{ stopColor: '#1890ff', stopOpacity: 0.1 }}
|
||||
/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<polyline
|
||||
fill='url(#completionGradient)'
|
||||
stroke='#1890ff'
|
||||
strokeWidth='0.5'
|
||||
points={data
|
||||
.map((d, i) => {
|
||||
const x = (i / (data.length - 1)) * 100;
|
||||
const y = 100 - (d.completionTokens / maxTotal) * 100;
|
||||
return `${x},${y}`;
|
||||
})
|
||||
.join(' ')}
|
||||
/>
|
||||
<polyline
|
||||
fill='url(#promptGradient)'
|
||||
stroke='#52c41a'
|
||||
strokeWidth='0.5'
|
||||
points={data
|
||||
.map((d, i) => {
|
||||
const x = (i / (data.length - 1)) * 100;
|
||||
const total = d.promptTokens + d.completionTokens;
|
||||
const y = 100 - (total / maxTotal) * 100;
|
||||
return `${x},${y}`;
|
||||
})
|
||||
.join(' ')}
|
||||
/>
|
||||
</svg>
|
||||
<div
|
||||
style={{
|
||||
position: 'absolute',
|
||||
top: '8px',
|
||||
right: '8px',
|
||||
display: 'flex',
|
||||
gap: '12px',
|
||||
fontSize: '12px',
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: '4px' }}>
|
||||
<div
|
||||
style={{
|
||||
width: '12px',
|
||||
height: '12px',
|
||||
background: '#52c41a',
|
||||
borderRadius: '2px',
|
||||
}}
|
||||
/>
|
||||
<span>Prompt</span>
|
||||
</div>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: '4px' }}>
|
||||
<div
|
||||
style={{
|
||||
width: '12px',
|
||||
height: '12px',
|
||||
background: '#1890ff',
|
||||
borderRadius: '2px',
|
||||
}}
|
||||
/>
|
||||
<span>Completion</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const renderDonutChart = (data) => {
|
||||
const total = data.reduce((sum, item) => sum + item.cost, 0);
|
||||
const colors = ['#1890ff', '#52c41a', '#faad14', '#f5222d', '#722ed1'];
|
||||
|
||||
let currentAngle = -90;
|
||||
const segments = data.map((item, index) => {
|
||||
const percentage = item.cost / total;
|
||||
const angle = percentage * 360;
|
||||
const startAngle = currentAngle;
|
||||
const endAngle = currentAngle + angle;
|
||||
currentAngle = endAngle;
|
||||
|
||||
const startRad = (startAngle * Math.PI) / 180;
|
||||
const endRad = (endAngle * Math.PI) / 180;
|
||||
|
||||
const x1 = 50 + 40 * Math.cos(startRad);
|
||||
const y1 = 50 + 40 * Math.sin(startRad);
|
||||
const x2 = 50 + 40 * Math.cos(endRad);
|
||||
const y2 = 50 + 40 * Math.sin(endRad);
|
||||
|
||||
const largeArc = angle > 180 ? 1 : 0;
|
||||
|
||||
return {
|
||||
d: `M 50 50 L ${x1} ${y1} A 40 40 0 ${largeArc} 1 ${x2} ${y2} Z`,
|
||||
color: colors[index % colors.length],
|
||||
...item,
|
||||
};
|
||||
});
|
||||
|
||||
return (
|
||||
<div>
|
||||
<svg width='100%' height='200' viewBox='0 0 100 100'>
|
||||
<circle
|
||||
cx='50'
|
||||
cy='50'
|
||||
r='40'
|
||||
fill='none'
|
||||
stroke='var(--semi-color-fill-0)'
|
||||
strokeWidth='0.5'
|
||||
/>
|
||||
{segments.map((segment, index) => (
|
||||
<path
|
||||
key={index}
|
||||
d={segment.d}
|
||||
fill={segment.color}
|
||||
opacity='0.85'
|
||||
/>
|
||||
))}
|
||||
<circle cx='50' cy='50' r='20' fill='var(--semi-color-bg-1)' />
|
||||
</svg>
|
||||
<div style={{ marginTop: '16px' }}>
|
||||
{segments.map((segment, index) => (
|
||||
<div
|
||||
key={index}
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
marginBottom: '8px',
|
||||
fontSize: '12px',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{ display: 'flex', alignItems: 'center', gap: '8px' }}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
width: '12px',
|
||||
height: '12px',
|
||||
background: segment.color,
|
||||
borderRadius: '2px',
|
||||
}}
|
||||
/>
|
||||
<span>{segment.name}</span>
|
||||
</div>
|
||||
<span style={{ fontWeight: 600 }}>
|
||||
${segment.cost.toFixed(2)} ({segment.percentage}%)
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const renderGaugeChart = (percentage) => {
|
||||
const color =
|
||||
percentage >= 90
|
||||
? 'var(--semi-color-danger)'
|
||||
: percentage >= 75
|
||||
? 'var(--semi-color-warning)'
|
||||
: 'var(--semi-color-success)';
|
||||
|
||||
return (
|
||||
<div style={{ textAlign: 'center', padding: '20px 0' }}>
|
||||
<svg width='100%' height='120' viewBox='0 0 100 60'>
|
||||
<path
|
||||
d='M 10 50 A 40 40 0 0 1 90 50'
|
||||
fill='none'
|
||||
stroke='var(--semi-color-fill-0)'
|
||||
strokeWidth='8'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
<path
|
||||
d='M 10 50 A 40 40 0 0 1 90 50'
|
||||
fill='none'
|
||||
stroke={color}
|
||||
strokeWidth='8'
|
||||
strokeLinecap='round'
|
||||
strokeDasharray={`${percentage * 1.256} 125.6`}
|
||||
/>
|
||||
<text
|
||||
x='50'
|
||||
y='45'
|
||||
textAnchor='middle'
|
||||
style={{
|
||||
fontSize: '18px',
|
||||
fontWeight: 700,
|
||||
fill: 'var(--semi-color-text-0)',
|
||||
}}
|
||||
>
|
||||
{percentage}%
|
||||
</text>
|
||||
</svg>
|
||||
<div
|
||||
style={{
|
||||
marginTop: '8px',
|
||||
fontSize: '12px',
|
||||
color: 'var(--semi-color-text-2)',
|
||||
}}
|
||||
>
|
||||
{percentage >= 90 && t('配额即将用尽')}
|
||||
{percentage >= 75 && percentage < 90 && t('配额使用偏高')}
|
||||
{percentage < 75 && t('配额正常')}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const renderHorizontalBar = (data) => {
|
||||
const maxCount = Math.max(...data.map((d) => d.count));
|
||||
|
||||
return data.map((item, index) => {
|
||||
const percentage = (item.count / maxCount) * 100;
|
||||
return (
|
||||
<div key={index} style={{ marginBottom: '16px' }}>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
marginBottom: '6px',
|
||||
fontSize: '13px',
|
||||
}}
|
||||
>
|
||||
<span style={{ color: 'var(--semi-color-text-1)' }}>
|
||||
{item.type}
|
||||
</span>
|
||||
<span
|
||||
style={{ fontWeight: 600, color: 'var(--semi-color-text-0)' }}
|
||||
>
|
||||
{item.count}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
height: '20px',
|
||||
background: 'var(--semi-color-fill-0)',
|
||||
borderRadius: '10px',
|
||||
overflow: 'hidden',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
height: '100%',
|
||||
width: `${percentage}%`,
|
||||
background: 'linear-gradient(90deg, #ff4d4f 0%, #ff7875 100%)',
|
||||
borderRadius: '10px',
|
||||
transition: 'width 0.6s cubic-bezier(0.4, 0, 0.2, 1)',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: t('渠道名称'),
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: 180,
|
||||
render: (text) => <strong>{text}</strong>,
|
||||
},
|
||||
{
|
||||
title: t('请求数'),
|
||||
dataIndex: 'requests',
|
||||
key: 'requests',
|
||||
sorter: (a, b) => a.requests - b.requests,
|
||||
render: (text) => text.toLocaleString(),
|
||||
},
|
||||
{
|
||||
title: t('平均响应时间 (ms)'),
|
||||
dataIndex: 'avgResponseTime',
|
||||
key: 'avgResponseTime',
|
||||
sorter: (a, b) => a.avgResponseTime - b.avgResponseTime,
|
||||
render: (text) => (
|
||||
<span
|
||||
style={{
|
||||
color:
|
||||
text > 500
|
||||
? 'var(--semi-color-danger)'
|
||||
: 'var(--semi-color-success)',
|
||||
}}
|
||||
>
|
||||
{text}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('Token消耗'),
|
||||
dataIndex: 'tokens',
|
||||
key: 'tokens',
|
||||
sorter: (a, b) => a.tokens - b.tokens,
|
||||
render: (text) => text.toLocaleString(),
|
||||
},
|
||||
{
|
||||
title: t('成本 (¥)'),
|
||||
dataIndex: 'cost',
|
||||
key: 'cost',
|
||||
sorter: (a, b) => parseFloat(a.cost) - parseFloat(b.cost),
|
||||
render: (text) => `¥${text}`,
|
||||
},
|
||||
{
|
||||
title: t('成功率 (%)'),
|
||||
dataIndex: 'successRate',
|
||||
key: 'successRate',
|
||||
sorter: (a, b) => parseFloat(a.successRate) - parseFloat(b.successRate),
|
||||
render: (text) => {
|
||||
const rate = parseFloat(text);
|
||||
return (
|
||||
<span
|
||||
style={{
|
||||
color:
|
||||
rate >= 99
|
||||
? 'var(--semi-color-success)'
|
||||
: rate >= 95
|
||||
? 'var(--semi-color-warning)'
|
||||
: 'var(--semi-color-danger)',
|
||||
}}
|
||||
>
|
||||
{text}%
|
||||
</span>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div style={{ textAlign: 'center', padding: '60px 0' }}>
|
||||
<Spin size='large' />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='admin-monitor'>
|
||||
<style>
|
||||
{`
|
||||
.admin-monitor .semi-card {
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.admin-monitor .semi-card:hover {
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.chart-card {
|
||||
border: 1px solid var(--semi-color-border);
|
||||
borderRadius: 12px;
|
||||
}
|
||||
`}
|
||||
</style>
|
||||
|
||||
<Row gutter={[16, 16]} style={{ marginBottom: '24px' }}>
|
||||
<Col xs={24} sm={12} lg={6}>
|
||||
{renderKPICard(
|
||||
<TrendingUp />,
|
||||
t('过去24小时总请求'),
|
||||
data.kpi.totalRequests.toLocaleString(),
|
||||
'',
|
||||
'#1890ff',
|
||||
)}
|
||||
</Col>
|
||||
<Col xs={24} sm={12} lg={6}>
|
||||
{renderKPICard(
|
||||
<DollarSign />,
|
||||
t('今日预估总成本'),
|
||||
data.kpi.totalCost,
|
||||
'¥',
|
||||
'#52c41a',
|
||||
)}
|
||||
</Col>
|
||||
<Col xs={24} sm={12} lg={6}>
|
||||
{renderKPICard(
|
||||
<Layers />,
|
||||
t('当前活跃渠道'),
|
||||
data.kpi.activeChannels,
|
||||
'',
|
||||
'#722ed1',
|
||||
)}
|
||||
</Col>
|
||||
<Col xs={24} sm={12} lg={6}>
|
||||
{renderKPICard(
|
||||
<Activity />,
|
||||
t('平均响应时间'),
|
||||
data.kpi.avgResponseTime,
|
||||
'ms',
|
||||
'#faad14',
|
||||
)}
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Row gutter={[16, 16]} style={{ marginBottom: '24px' }}>
|
||||
<Col xs={24} lg={12}>
|
||||
<Card
|
||||
className='chart-card'
|
||||
title={
|
||||
<div
|
||||
style={{ display: 'flex', alignItems: 'center', gap: '8px' }}
|
||||
>
|
||||
<BarChart3 size={18} />
|
||||
<span>{t('请求趋势')} (24h)</span>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: '20px' }}
|
||||
>
|
||||
{renderBarChart(
|
||||
data.requestTrend,
|
||||
Math.max(...data.requestTrend.map((d) => d.requests)),
|
||||
)}
|
||||
</Card>
|
||||
</Col>
|
||||
<Col xs={24} lg={12}>
|
||||
<Card
|
||||
className='chart-card'
|
||||
title={
|
||||
<div
|
||||
style={{ display: 'flex', alignItems: 'center', gap: '8px' }}
|
||||
>
|
||||
<DollarSign size={18} />
|
||||
<span>{t('成本分布')}</span>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: '20px' }}
|
||||
>
|
||||
{renderDonutChart(data.costDistribution)}
|
||||
</Card>
|
||||
</Col>
|
||||
<Col xs={24} lg={12}>
|
||||
<Card
|
||||
className='chart-card'
|
||||
title={
|
||||
<div
|
||||
style={{ display: 'flex', alignItems: 'center', gap: '8px' }}
|
||||
>
|
||||
<Activity size={18} />
|
||||
<span>{t('Token消耗趋势')} (24h)</span>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: '20px' }}
|
||||
>
|
||||
{renderStackedAreaChart(data.tokenTrend)}
|
||||
</Card>
|
||||
</Col>
|
||||
<Col xs={24} lg={12}>
|
||||
<Card
|
||||
className='chart-card'
|
||||
title={
|
||||
<div
|
||||
style={{ display: 'flex', alignItems: 'center', gap: '8px' }}
|
||||
>
|
||||
<Layers size={18} />
|
||||
<span>{t('配额使用情况')}</span>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: '20px' }}
|
||||
>
|
||||
{renderGaugeChart(data.quotaUsage)}
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Row gutter={[16, 16]} style={{ marginBottom: '24px' }}>
|
||||
<Col span={24}>
|
||||
<Card
|
||||
className='chart-card'
|
||||
title={
|
||||
<div
|
||||
style={{ display: 'flex', alignItems: 'center', gap: '8px' }}
|
||||
>
|
||||
<AlertTriangle size={18} />
|
||||
<span>{t('错误类型分布')} (24h)</span>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: '20px' }}
|
||||
>
|
||||
{renderHorizontalBar(data.errorTypes)}
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col span={24}>
|
||||
<Card
|
||||
className='chart-card'
|
||||
title={
|
||||
<div
|
||||
style={{ display: 'flex', alignItems: 'center', gap: '8px' }}
|
||||
>
|
||||
<BarChart3 size={18} />
|
||||
<span>{t('渠道详细数据')}</span>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: 0 }}
|
||||
>
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={data.channelDetails}
|
||||
pagination={false}
|
||||
rowKey='id'
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AdminMonitor;
|
||||
@@ -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;
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
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 { Tabs, Card } from '@douyinfe/semi-ui';
|
||||
import { Activity, Shield } from 'lucide-react';
|
||||
import ChannelMonitor from './ChannelMonitor';
|
||||
import AdminMonitor from './AdminMonitor';
|
||||
|
||||
const MonitorCenter = () => {
|
||||
const [activeTab, setActiveTab] = useState('channel');
|
||||
const [userRole, setUserRole] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
const raw = localStorage.getItem('user');
|
||||
if (raw) {
|
||||
try {
|
||||
const user = JSON.parse(raw);
|
||||
setUserRole(user.role || 0);
|
||||
} catch (e) {
|
||||
console.error('Failed to parse user data:', e);
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
const isAdmin = userRole >= 10;
|
||||
|
||||
return (
|
||||
<div className='mt-[60px] px-2 md:px-6 pb-8'>
|
||||
<div className='max-w-[1600px] mx-auto'>
|
||||
{/* 页面标题 */}
|
||||
<div className='mb-6'>
|
||||
<h1 className='text-3xl font-bold flex items-center gap-3'>
|
||||
<div className='w-10 h-10 rounded-lg bg-gradient-to-br from-blue-500 to-brand-to flex items-center justify-center'>
|
||||
<Activity className='w-6 h-6 text-white' />
|
||||
</div>
|
||||
监控中心
|
||||
</h1>
|
||||
<p className='text-gray-500 mt-2 ml-[52px]'>
|
||||
实时监控渠道状态与系统性能指标
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* 标签页 */}
|
||||
<Card className='shadow-lg'>
|
||||
<Tabs
|
||||
activeKey={activeTab}
|
||||
onChange={setActiveTab}
|
||||
type='line'
|
||||
size='large'
|
||||
>
|
||||
<Tabs.TabPane
|
||||
tab={
|
||||
<span className='flex items-center gap-2'>
|
||||
<Activity className='w-4 h-4' />
|
||||
渠道监控
|
||||
</span>
|
||||
}
|
||||
itemKey='channel'
|
||||
>
|
||||
<ChannelMonitor />
|
||||
</Tabs.TabPane>
|
||||
|
||||
{isAdmin && (
|
||||
<Tabs.TabPane
|
||||
tab={
|
||||
<span className='flex items-center gap-2'>
|
||||
<Shield className='w-4 h-4' />
|
||||
管理监控
|
||||
</span>
|
||||
}
|
||||
itemKey='admin'
|
||||
>
|
||||
<AdminMonitor />
|
||||
</Tabs.TabPane>
|
||||
)}
|
||||
</Tabs>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default MonitorCenter;
|
||||
Reference in New Issue
Block a user