2aa9d73325
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
155 lines
4.6 KiB
React
155 lines
4.6 KiB
React
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 (
|
||
<Card
|
||
className={`shadow-sm hover:shadow-md transition-shadow ${embedded ? 'analytics-fold-content' : ''}`}
|
||
title={
|
||
embedded ? undefined : (
|
||
<div className='flex items-center gap-2'>
|
||
<span className='text-brand'>{icon}</span>
|
||
<span className='font-semibold'>{title}</span>
|
||
</div>
|
||
)
|
||
}
|
||
styles={{ body: { padding: '16px' } }}
|
||
>
|
||
<div className='h-[300px] flex items-center justify-center text-gray-400'>
|
||
{t('暂无数据')}
|
||
</div>
|
||
</Card>
|
||
);
|
||
}
|
||
|
||
// 预计算排名(后端已按充值总额降序排好,直接按顺序编号)
|
||
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) => (
|
||
<div
|
||
className={`w-7 h-7 rounded-full flex items-center justify-center text-xs font-bold ${getRankBadge(rank)}`}
|
||
>
|
||
{rank}
|
||
</div>
|
||
),
|
||
},
|
||
{
|
||
title: t('用户昵称'),
|
||
dataIndex: 'display_name',
|
||
width: 160,
|
||
render: (text, record) => (
|
||
<div className='flex flex-col'>
|
||
<span
|
||
className='font-medium text-sm truncate'
|
||
title={formatUserReference(text, record.user_id, t('未知用户'))}
|
||
>
|
||
{formatUserReference(text, record.user_id, t('未知用户'))}
|
||
</span>
|
||
<span className='text-xs text-gray-400 truncate'>
|
||
{I18N_TECHNICAL_TEXT.ID} {formatIdReference(record.user_id)}
|
||
</span>
|
||
</div>
|
||
),
|
||
},
|
||
{
|
||
title: t('充值总额'),
|
||
dataIndex: 'total_topup',
|
||
width: 130,
|
||
sorter: (a, b) => a.total_topup - b.total_topup,
|
||
defaultSortOrder: 'descend',
|
||
render: (value) => (
|
||
<span className='font-semibold text-red-500'>
|
||
¥{formatNumber(value, 2, '0.00')}
|
||
</span>
|
||
),
|
||
},
|
||
{
|
||
title: t('历史消耗'),
|
||
dataIndex: 'used_quota',
|
||
width: 130,
|
||
sorter: (a, b) => a.used_quota - b.used_quota,
|
||
render: (value) => (
|
||
<span className='text-orange-600 dark:text-orange-400'>
|
||
{renderQuota(value || 0)}
|
||
</span>
|
||
),
|
||
},
|
||
{
|
||
title: t('当前余额'),
|
||
dataIndex: 'balance',
|
||
width: 130,
|
||
sorter: (a, b) => a.balance - b.balance,
|
||
render: (value) => (
|
||
<span className='font-medium text-green-600 dark:text-green-400'>
|
||
{renderQuota(value || 0)}
|
||
</span>
|
||
),
|
||
},
|
||
];
|
||
|
||
return (
|
||
<Card
|
||
className={`shadow-sm hover:shadow-md transition-shadow ${embedded ? 'analytics-fold-content' : ''}`}
|
||
title={
|
||
embedded ? undefined : (
|
||
<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'>
|
||
<Trans
|
||
t={t}
|
||
i18nKey='共 {{length}} 人'
|
||
values={{ length: data.length }}
|
||
/>
|
||
</span>
|
||
</div>
|
||
)
|
||
}
|
||
styles={{ body: { padding: '0' } }}
|
||
>
|
||
<Table
|
||
// 列宽合计远超窄屏视口;没有 scroll 时表格会压缩到 min-content 硬塞进去,
|
||
// 末尾的操作列落在视口外,且 iOS 上滚动条不可见、毫无可拖动提示
|
||
scroll={{ x: 'max-content' }}
|
||
columns={columns}
|
||
dataSource={dataWithRank}
|
||
rowKey='user_id'
|
||
pagination={
|
||
data.length > 20 ? { pageSize: 20, showSizeChanger: true } : false
|
||
}
|
||
size='small'
|
||
bordered={false}
|
||
style={{ borderRadius: 0 }}
|
||
/>
|
||
</Card>
|
||
);
|
||
};
|
||
|
||
export default UserTopupRanking;
|