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
+139
View File
@@ -0,0 +1,139 @@
/*
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 from 'react';
import { Card, Avatar, Progress } from '@douyinfe/semi-ui';
import { renderQuota } from '../../helpers';
const UserRanking = ({ data, title, icon, t }) => {
if (!data || data.length === 0) {
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' }}
>
<div className='h-[300px] flex items-center justify-center text-gray-400'>
{t('暂无数据')}
</div>
</Card>
);
}
// 计算最大值用于进度条
const maxQuota = Math.max(...data.map((item) => item.quota || 0));
// 排名颜色
const getRankStyle = (index) => {
if (index === 0)
return 'bg-gradient-to-r from-yellow-400 to-yellow-500 text-white';
if (index === 1)
return 'bg-gradient-to-r from-gray-300 to-gray-400 text-white';
if (index === 2)
return 'bg-gradient-to-r from-orange-400 to-orange-500 text-white';
return 'bg-gray-200 text-gray-600';
};
// 进度条颜色
const getProgressColor = (index) => {
if (index === 0) return '#f59e0b';
if (index === 1) return '#9ca3af';
if (index === 2) return '#f97316';
return '#3b82f6';
};
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>
<span className='text-xs text-gray-400 ml-2'>
{t('共')} {data.length} {t('人')}
</span>
</div>
}
bodyStyle={{ padding: '16px' }}
>
<div className='space-y-2 max-h-[450px] overflow-y-auto pr-1'>
{data.map((item, index) => (
<div
key={item.user_id}
className='flex items-center gap-3 p-2 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors'
>
<div
className={`w-7 h-7 rounded-full flex items-center justify-center text-xs font-bold flex-shrink-0 ${getRankStyle(
index,
)}`}
>
{index + 1}
</div>
<Avatar size='small' color='blue' className='flex-shrink-0'>
{(item.display_name || item.username)?.charAt(0)?.toUpperCase() ||
'U'}
</Avatar>
<div className='flex-1 min-w-0'>
<div className='flex items-center justify-between'>
<span
className='text-sm font-medium truncate'
title={`${item.display_name || item.username || 'User'} (ID: ${item.user_id})`}
>
{item.display_name || item.username || `User ${item.user_id}`}
<span className='text-xs text-gray-400 ml-1'>
#{item.user_id}
</span>
</span>
<span className='text-sm font-semibold text-gray-700 dark:text-gray-300 ml-2'>
{renderQuota(item.quota || 0)}
</span>
</div>
<Progress
percent={(item.quota / maxQuota) * 100}
showInfo={false}
size='small'
style={{ height: 4 }}
stroke={getProgressColor(index)}
/>
<div className='flex justify-between text-xs text-gray-400 mt-1'>
<span>
{item.requests?.toLocaleString()} {t('次请求')}
</span>
<span>{(item.tokens || 0).toLocaleString()} tokens</span>
</div>
<div className='flex justify-between text-xs mt-1'>
<span className='text-gray-500'>{t('余额')}:</span>
<span className='font-medium text-green-600 dark:text-green-400'>
{renderQuota(item.balance || 0)}
</span>
</div>
</div>
</div>
))}
</div>
</Card>
);
};
export default UserRanking;