import { formatIdReference, formatUserReference, } from '../../helpers/safeDisplay'; import { Trans } from 'react-i18next'; import { I18N_TECHNICAL_TEXT } from '../../i18n/technicalText.js'; import React from 'react'; import { Card, Avatar, Progress } from '@/components/ui'; import { renderQuota } from '../../helpers'; const UserRanking = ({ data, title, icon, t }) => { if (!data || data.length === 0) { return ( {icon} {title} } styles={{ body: { padding: '16px' } }} >
{t('暂无数据')}
); } // 计算最大值用于进度条 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 ( {icon} {title} } styles={{ body: { padding: '16px' } }} >
{data.map((item, index) => (
{index + 1}
{(item.display_name || item.username)?.charAt(0)?.toUpperCase() || 'U'}
{formatUserReference( item.display_name || item.username, item.user_id, t('未知用户'), )} {formatIdReference(item.user_id)} {renderQuota(item.quota || 0)}
{item.requests?.toLocaleString()} {t('次请求')} {(item.tokens || 0).toLocaleString()}{' '} {I18N_TECHNICAL_TEXT.TOKENS}
{t('余额')}: {renderQuota(item.balance || 0)}
))}
); }; export default UserRanking;