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
@@ -0,0 +1,157 @@
/*
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, { useState } from 'react';
import { Card, Table, Progress } from '@douyinfe/semi-ui';
import { renderQuota } from '../../helpers';
const ChannelConsumption = ({ data, title, icon, t }) => {
const [currentPage, setCurrentPage] = useState(1);
const [pageSize, setPageSize] = useState(10);
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 getGlobalIndex = (pageIndex) =>
(currentPage - 1) * pageSize + pageIndex;
const columns = [
{
title: '#',
dataIndex: 'index',
key: 'index',
width: 50,
render: (_, record, index) => {
const globalIndex = getGlobalIndex(index);
return (
<span
className={`font-medium ${globalIndex < 3 ? 'text-orange-500' : 'text-gray-500'}`}
>
{globalIndex + 1}
</span>
);
},
},
{
title: t('渠道名称'),
dataIndex: 'channel_name',
key: 'channel_name',
render: (text) => (
<span className='font-medium truncate' title={text}>
{text || t('未知渠道')}
</span>
),
},
{
title: t('消耗额度'),
dataIndex: 'quota',
key: 'quota',
width: 180,
render: (val, record) => (
<div className='flex items-center gap-2'>
<Progress
percent={(val / maxQuota) * 100}
showInfo={false}
size='small'
style={{ width: 80, height: 6 }}
stroke='#3b82f6'
/>
<span className='text-sm font-medium text-gray-700 dark:text-gray-300'>
{renderQuota(val || 0)}
</span>
</div>
),
},
{
title: t('请求次数'),
dataIndex: 'count',
key: 'count',
width: 100,
align: 'right',
render: (val) => (
<span className='text-gray-600'>{(val || 0).toLocaleString()}</span>
),
},
{
title: t('占比'),
dataIndex: 'percent',
key: 'percent',
width: 80,
align: 'right',
render: (val) => (
<span className='text-gray-500'>{(val || 0).toFixed(1)}%</span>
),
},
];
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'>TOP {data.length}</span>
</div>
}
bodyStyle={{ padding: '0' }}
>
<Table
columns={columns}
dataSource={data}
pagination={{
currentPage,
pageSize,
showSizeChanger: true,
pageSizeOpts: [10, 20, 30],
showTotal: (total) => `${t('共')} ${total} ${t('条')}`,
onPageChange: (page) => setCurrentPage(page),
onPageSizeChange: (size) => {
setPageSize(size);
setCurrentPage(1);
},
}}
size='small'
rowKey={(record, index) => `${record.channel_name}-${index}`}
/>
</Card>
);
};
export default ChannelConsumption;