Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
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, Table, Button } from '@douyinfe/semi-ui';
|
||||
import { IconDownload } from '@douyinfe/semi-icons';
|
||||
import { renderQuota } from '../../helpers';
|
||||
|
||||
const DailyStatsTable = ({ data, title, icon, t }) => {
|
||||
const columns = [
|
||||
{
|
||||
title: t('日期'),
|
||||
dataIndex: 'date',
|
||||
key: 'date',
|
||||
width: 120,
|
||||
fixed: 'left',
|
||||
render: (text) => <span className='font-medium'>{text}</span>,
|
||||
},
|
||||
{
|
||||
title: t('新增用户'),
|
||||
dataIndex: 'new_users',
|
||||
key: 'new_users',
|
||||
width: 100,
|
||||
align: 'right',
|
||||
render: (val) => (
|
||||
<span className='text-green-600'>{(val || 0).toLocaleString()}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('活跃用户'),
|
||||
dataIndex: 'active_users',
|
||||
key: 'active_users',
|
||||
width: 100,
|
||||
align: 'right',
|
||||
render: (val) => (
|
||||
<span className='text-blue-600'>{(val || 0).toLocaleString()}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('充值人数'),
|
||||
dataIndex: 'topup_users',
|
||||
key: 'topup_users',
|
||||
width: 100,
|
||||
align: 'right',
|
||||
render: (val) => <span>{(val || 0).toLocaleString()}</span>,
|
||||
},
|
||||
{
|
||||
title: t('充值金额'),
|
||||
dataIndex: 'topup_amount',
|
||||
key: 'topup_amount',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: (val) => (
|
||||
<span className='text-yellow-600 font-medium'>
|
||||
¥{(val || 0).toFixed(2)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('消耗额度'),
|
||||
dataIndex: 'consume_quota',
|
||||
key: 'consume_quota',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: (val) => (
|
||||
<span className='text-brand-deep font-medium'>
|
||||
{renderQuota(val || 0)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('请求次数'),
|
||||
dataIndex: 'requests',
|
||||
key: 'requests',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: (val) => <span>{(val || 0).toLocaleString()}</span>,
|
||||
},
|
||||
{
|
||||
title: t('Token消耗'),
|
||||
dataIndex: 'tokens',
|
||||
key: 'tokens',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: (val) => {
|
||||
const tokens = val || 0;
|
||||
if (tokens >= 1000000) {
|
||||
return <span>{(tokens / 1000000).toFixed(2)}M</span>;
|
||||
} else if (tokens >= 1000) {
|
||||
return <span>{(tokens / 1000).toFixed(1)}K</span>;
|
||||
}
|
||||
return <span>{tokens.toLocaleString()}</span>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: t('人均消耗'),
|
||||
dataIndex: 'avg_consume',
|
||||
key: 'avg_consume',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: (val) => (
|
||||
<span className='text-gray-600'>{renderQuota(val || 0)}</span>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
// 导出CSV
|
||||
const handleExport = () => {
|
||||
if (!data || data.length === 0) return;
|
||||
|
||||
const headers = [
|
||||
t('日期'),
|
||||
t('新增用户'),
|
||||
t('活跃用户'),
|
||||
t('充值人数'),
|
||||
t('充值金额'),
|
||||
t('消耗额度'),
|
||||
t('请求次数'),
|
||||
t('Token消耗'),
|
||||
t('人均消耗'),
|
||||
];
|
||||
|
||||
const rows = data.map((row) => [
|
||||
row.date,
|
||||
row.new_users || 0,
|
||||
row.active_users || 0,
|
||||
row.topup_users || 0,
|
||||
row.topup_amount || 0,
|
||||
row.consume_quota || 0,
|
||||
row.requests || 0,
|
||||
row.tokens || 0,
|
||||
row.avg_consume || 0,
|
||||
]);
|
||||
|
||||
const csvContent =
|
||||
'\uFEFF' +
|
||||
[headers.join(','), ...rows.map((row) => row.join(','))].join('\n');
|
||||
|
||||
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
|
||||
const link = document.createElement('a');
|
||||
link.href = URL.createObjectURL(blob);
|
||||
link.download = `analytics_${new Date().toISOString().split('T')[0]}.csv`;
|
||||
link.click();
|
||||
};
|
||||
|
||||
return (
|
||||
<Card
|
||||
className='shadow-sm hover:shadow-md transition-shadow'
|
||||
title={
|
||||
<div className='flex items-center justify-between w-full'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<span className='text-brand'>{icon}</span>
|
||||
<span className='font-semibold'>{title}</span>
|
||||
</div>
|
||||
<Button
|
||||
icon={<IconDownload />}
|
||||
size='small'
|
||||
onClick={handleExport}
|
||||
disabled={!data || data.length === 0}
|
||||
>
|
||||
{t('导出CSV')}
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: '0' }}
|
||||
>
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={data || []}
|
||||
pagination={{
|
||||
pageSize: 10,
|
||||
showSizeChanger: true,
|
||||
showTotal: (total) => `${t('共')} ${total} ${t('条')}`,
|
||||
}}
|
||||
scroll={{ x: 1100 }}
|
||||
size='small'
|
||||
rowKey='date'
|
||||
empty={
|
||||
<div className='py-8 text-center text-gray-400'>{t('暂无数据')}</div>
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default DailyStatsTable;
|
||||
Reference in New Issue
Block a user