import { formatNumber, formatIdReference, formatUserReference, } from '../../helpers/safeDisplay'; import { Trans } from 'react-i18next'; import { I18N_TECHNICAL_TEXT } from '../../i18n/technicalText.js'; import React from 'react'; import { Card, Table } from '@/components/ui'; import { renderQuota } from '../../helpers'; const UserTopupRanking = ({ data, title, icon, t, embedded = false }) => { if (!data || data.length === 0) { return ( {icon} {title} ) } styles={{ body: { padding: '16px' } }} >
{t('暂无数据')}
); } // 预计算排名(后端已按充值总额降序排好,直接按顺序编号) const dataWithRank = data.map((item, idx) => ({ ...item, _rank: idx + 1 })); // 排名样式 const getRankBadge = (rank) => { if (rank === 1) return 'bg-gradient-to-r from-yellow-400 to-yellow-500 text-white'; if (rank === 2) return 'bg-gradient-to-r from-gray-300 to-gray-400 text-white'; if (rank === 3) return 'bg-gradient-to-r from-orange-400 to-orange-500 text-white'; return 'bg-gray-200 text-gray-600'; }; const columns = [ { title: t('排名'), dataIndex: '_rank', width: 70, render: (rank) => (
{rank}
), }, { title: t('用户昵称'), dataIndex: 'display_name', width: 160, render: (text, record) => (
{formatUserReference(text, record.user_id, t('未知用户'))} {I18N_TECHNICAL_TEXT.ID} {formatIdReference(record.user_id)}
), }, { title: t('充值总额'), dataIndex: 'total_topup', width: 130, sorter: (a, b) => a.total_topup - b.total_topup, defaultSortOrder: 'descend', render: (value) => ( ¥{formatNumber(value, 2, '0.00')} ), }, { title: t('历史消耗'), dataIndex: 'used_quota', width: 130, sorter: (a, b) => a.used_quota - b.used_quota, render: (value) => ( {renderQuota(value || 0)} ), }, { title: t('当前余额'), dataIndex: 'balance', width: 130, sorter: (a, b) => a.balance - b.balance, render: (value) => ( {renderQuota(value || 0)} ), }, ]; return ( {icon} {title} ) } styles={{ body: { padding: '0' } }} > 20 ? { pageSize: 20, showSizeChanger: true } : false } size='small' bordered={false} style={{ borderRadius: 0 }} /> ); }; export default UserTopupRanking;