Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
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, { useMemo } from 'react';
|
||||
import { Card } from '@douyinfe/semi-ui';
|
||||
import { VChart } from '@visactor/react-vchart';
|
||||
import { renderQuota } from '../../helpers';
|
||||
|
||||
const ModelDistribution = ({ data, title, icon, t }) => {
|
||||
const pieSpec = useMemo(() => {
|
||||
if (!data || data.length === 0) return null;
|
||||
|
||||
const chartData = data.slice(0, 8).map((item) => ({
|
||||
name: item.model_name || t('未知'),
|
||||
value: item.quota || 0,
|
||||
}));
|
||||
|
||||
// 如果有更多数据,合并为"其他"
|
||||
if (data.length > 8) {
|
||||
const otherQuota = data
|
||||
.slice(8)
|
||||
.reduce((sum, item) => sum + (item.quota || 0), 0);
|
||||
chartData.push({ name: t('其他'), value: otherQuota });
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'pie',
|
||||
data: [{ id: 'modelDist', values: chartData }],
|
||||
valueField: 'value',
|
||||
categoryField: 'name',
|
||||
outerRadius: 0.8,
|
||||
innerRadius: 0.5,
|
||||
padAngle: 0.02,
|
||||
pie: {
|
||||
style: {
|
||||
cornerRadius: 4,
|
||||
},
|
||||
},
|
||||
tooltip: {
|
||||
mark: {
|
||||
content: [
|
||||
{
|
||||
key: (datum) => datum?.name,
|
||||
value: (datum) => renderQuota(datum?.value || 0),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
legends: {
|
||||
visible: true,
|
||||
position: 'right',
|
||||
orient: 'vertical',
|
||||
item: {
|
||||
width: 100,
|
||||
label: {
|
||||
style: {
|
||||
fontSize: 11,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
label: {
|
||||
visible: false,
|
||||
},
|
||||
color: [
|
||||
'#3b82f6',
|
||||
'#10b981',
|
||||
'#f59e0b',
|
||||
'#ef4444',
|
||||
'#8b5cf6',
|
||||
'#06b6d4',
|
||||
'#f97316',
|
||||
'#84cc16',
|
||||
'#94a3b8',
|
||||
],
|
||||
};
|
||||
}, [data, t]);
|
||||
|
||||
// 排行列表
|
||||
const topModels = data?.slice(0, 5) || [];
|
||||
|
||||
return (
|
||||
<Card
|
||||
className='shadow-sm hover:shadow-md transition-shadow'
|
||||
title={
|
||||
<div className='flex items-center gap-2'>
|
||||
<span className='text-brand'>{icon}</span>
|
||||
<span className='font-semibold'>{title}</span>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: '16px' }}
|
||||
>
|
||||
{pieSpec ? (
|
||||
<div>
|
||||
<VChart
|
||||
spec={pieSpec}
|
||||
option={{ mode: 'desktop-browser' }}
|
||||
style={{ height: 200 }}
|
||||
/>
|
||||
<div className='mt-4 space-y-2'>
|
||||
{topModels.map((item, index) => (
|
||||
<div key={index} className='flex items-center gap-2'>
|
||||
<span className='text-xs text-gray-500 w-4'>{index + 1}</span>
|
||||
<span
|
||||
className='text-sm flex-1 truncate'
|
||||
title={item.model_name}
|
||||
>
|
||||
{item.model_name}
|
||||
</span>
|
||||
<span className='text-xs text-gray-500'>
|
||||
{item.percent?.toFixed(1)}%
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className='h-[300px] flex items-center justify-center text-gray-400'>
|
||||
{t('暂无数据')}
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default ModelDistribution;
|
||||
Reference in New Issue
Block a user