feat: 参考原型图 ui优化提交 企业端-企业中心 相关的页面

This commit is contained in:
zhanjunhao
2026-11-06 20:19:43 +08:00
parent 43048626a6
commit a075732cb4
147 changed files with 9816 additions and 8768 deletions
+222 -263
View File
@@ -21,20 +21,20 @@ import { useTranslation } from 'react-i18next';
import {
RefreshCw,
Receipt,
Coins,
Wallet,
Zap,
Activity,
BarChart3,
Download,
Trophy,
Search,
} from 'lucide-react';
import { Card as AntCard, Form as AntForm, Tabs as AntTabs } from 'antd';
import {
Table,
Select,
Button,
DatePicker,
Input,
Tabs,
TabPane,
Checkbox,
Radio,
RadioGroup,
@@ -45,7 +45,7 @@ import {
useOrgMemberRanking,
} from '../../hooks/org/useOrgData';
import OrgPageHeader from './components/OrgPageHeader';
import StatCard from './components/OrgStatCard';
import { OrgFilterCard, OrgListCard } from './components/OrgListCard';
import OrgModal from './components/OrgModal';
import {
API,
@@ -58,13 +58,6 @@ import {
timestamp2string,
} from '../../helpers';
// ========== 排名徽标颜色 ==========
const rankColors = {
1: 'from-yellow-400 to-yellow-500',
2: 'from-gray-300 to-gray-400',
3: 'from-orange-400 to-orange-500',
};
// ========== 缓存 Token 解析(来自 other JSON 字段)==========
function getCacheTokens(record) {
const other = getLogOther(record.other);
@@ -609,86 +602,71 @@ const OrgLogs = ({ orgId, orgRole, isDeptManager = false }) => {
];
}, [appliedFilters, canViewTeamUsage, isAdmin, members, t]);
// ========== 日志表格列 ==========
// ========== 日志表格列(宽度与渲染对齐原型 EnterpriseExpenses)==========
const logColumns = useMemo(
() => [
{
title: t('时间'),
dataIndex: 'created_at',
width: 170,
width: 185,
render: (v) => (v ? timestamp2string(v) : '-'),
},
{
title: t('用户'),
dataIndex: 'username',
width: 120,
render: (v, record) => (
<span className='text-sm text-gray-700 dark:text-gray-300 truncate'>
{record.display_name || v || '-'}
</span>
),
width: 105,
ellipsis: true,
render: (v, record) => record.display_name || v || '-',
},
{
title: t('模型'),
dataIndex: 'model_name',
width: 180,
width: 175,
ellipsis: true,
render: (v) => (
<code className='text-xs px-1.5 py-0.5 bg-gray-100 dark:bg-neutral-800 rounded'>
{v || '-'}
</code>
),
render: (v) => <span className='oc-exp-model'>{v || '-'}</span>,
},
{
title: t('Token 名称'),
title: t('密钥名称'),
dataIndex: 'token_name',
width: 120,
width: 235,
ellipsis: true,
render: (v) => (
<span className='text-sm text-gray-600 dark:text-gray-400'>
{v || '-'}
render: (v) => v || '-',
},
{
title: t('提示 / 补全'),
width: 165,
render: (_, record) => (
<span className='oc-number'>
<span title='Prompt'>{record.prompt_tokens || 0}</span>{' '}
<span className='oc-muted' title='Completion'>
/ {record.completion_tokens || 0}
</span>
</span>
),
},
{
title: t('提示 / 补全'),
width: 130,
render: (_, record) => (
<div className='text-xs text-gray-600 dark:text-gray-400'>
<span title='Prompt'>{record.prompt_tokens || 0}</span>
<span className='mx-1 text-gray-300 dark:text-gray-600'>/</span>
<span title='Completion'>{record.completion_tokens || 0}</span>
</div>
),
},
{
title: t('缓存 / 缓存创建'),
width: 130,
width: 180,
render: (_, record) => (
<div className='text-xs text-gray-600 dark:text-gray-400'>
<span title={t('缓存 Tokens')}>{getCacheTokens(record)}</span>
<span className='mx-1 text-gray-300 dark:text-gray-600'>/</span>
<span title={t('缓存创建 Tokens')}>
{getCacheCreationTokens(record)}
<span className='oc-number'>
<span title={t('缓存 Tokens')}>{getCacheTokens(record)}</span>{' '}
<span className='oc-muted' title={t('缓存创建 Tokens')}>
/ {getCacheCreationTokens(record)}
</span>
</div>
</span>
),
},
{
title: t('消耗额度'),
dataIndex: 'quota',
width: 110,
width: 150,
align: 'right',
render: (v) => (
<span className='text-orange-600 dark:text-orange-400 font-medium text-sm'>
{renderQuota(v, 6)}
</span>
),
render: (v) => <span className='oc-exp-cost'>{renderQuota(v, 6)}</span>,
},
{
title: t('耗时'),
dataIndex: 'use_time',
width: 80,
width: 90,
align: 'right',
render: (v) => (v ? `${v}s` : '-'),
},
@@ -696,82 +674,76 @@ const OrgLogs = ({ orgId, orgRole, isDeptManager = false }) => {
[t],
);
// ========== 排行榜表格列 ==========
// ========== 排行榜表格列(原型 90/200/190/150/160)==========
const rankingColumns = useMemo(
() => [
{
title: '#',
width: 60,
render: (_, __, index) => {
const rank = index + 1;
const gradient = rankColors[rank];
return gradient ? (
<div
className={`inline-flex items-center justify-center w-7 h-7 rounded-full bg-gradient-to-br ${gradient} text-white text-xs font-bold shadow-sm`}
>
{rank}
</div>
) : (
<div className='inline-flex items-center justify-center w-7 h-7 rounded-full bg-gray-200 dark:bg-neutral-700 text-gray-600 dark:text-gray-300 text-xs font-medium'>
{rank}
</div>
);
},
title: t('排名'),
width: 90,
render: (_, __, index) => (
<span className={`oc-exp-rank oc-exp-rank-${index + 1}`}>
{index + 1}
</span>
),
},
{
title: t('成员'),
dataIndex: 'username',
width: 160,
render: (v, record) => (
<div className='flex items-center gap-2'>
<div className='w-7 h-7 rounded-full bg-brand/10 text-brand flex items-center justify-center text-xs font-semibold flex-shrink-0'>
{(record.display_name || v || '?').charAt(0).toUpperCase()}
</div>
<span className='text-sm text-gray-700 dark:text-gray-300 truncate'>
{record.display_name || v || '-'}
</span>
</div>
),
width: 200,
render: (v, record) => record.display_name || v || '-',
},
{
title: t('消耗额度'),
dataIndex: 'quota',
width: 130,
width: 190,
align: 'right',
render: (v) => (
<span className='text-orange-600 dark:text-orange-400 font-semibold text-sm'>
{renderQuota(v, 6)}
</span>
),
render: (v) => <span className='oc-exp-cost'>{renderQuota(v, 6)}</span>,
},
{
title: t('请求数'),
dataIndex: 'requests',
width: 100,
width: 150,
align: 'right',
render: (v) => (
<span className='text-sm text-gray-600 dark:text-gray-400'>
{formatNumber(v)}
</span>
),
render: (v) => <span className='oc-number'>{formatNumber(v)}</span>,
},
{
title: t('Token 数'),
dataIndex: 'tokens',
width: 120,
width: 160,
align: 'right',
render: (v) => (
<span className='text-sm text-gray-600 dark:text-gray-400'>
{formatNumber(v)}
</span>
),
render: (v) => <span className='oc-number'>{formatNumber(v)}</span>,
},
],
[t],
);
const statItems = [
{
key: 'quota',
icon: Wallet,
label: t('总消耗额度'),
value: statLoading ? '...' : renderQuota(stat.quota, 2),
},
{
key: 'rpm',
icon: Zap,
label: stat.has_time_range ? t('平均 RPM') : t('RPM(需选时间范围)'),
value: statLoading ? '...' : stat.has_time_range ? String(stat.rpm) : '—',
},
{
key: 'tpm',
icon: BarChart3,
label: stat.has_time_range ? t('平均 TPM') : t('TPM(需选时间范围)'),
value: statLoading
? '...'
: stat.has_time_range
? formatNumber(stat.tpm)
: '—',
},
];
return (
<div className='uc-page'>
<div className='uc-page oc-page'>
{/* 标题栏 */}
<OrgPageHeader
title={canViewTeamUsage ? t('消耗明细') : t('我的消耗明细')}
@@ -782,16 +754,107 @@ const OrgLogs = ({ orgId, orgRole, isDeptManager = false }) => {
? t('查看所负责部门成员的 API 消耗记录')
: t('查看自己的 API 调用明细')
}
/>
{/* 统计卡片(原型 .eex-stats) */}
<div className='oc-exp-stats'>
{statItems.map(({ key, icon: Icon, label, value }, i) => (
<AntCard key={key} className={`oc-exp-stat oc-exp-stat-${i}`}>
<span className='oc-exp-stat-icon'>
<Icon size={20} />
</span>
<div>
<span>{label}</span>
<strong>{value}</strong>
</div>
</AntCard>
))}
</div>
{/* 页签:明细日志 / 成员排行(原型 platform-list-tabs,只切换下方表格) */}
<AntTabs
className='oc-list-tabs oc-tabs-nav-only'
activeKey={activeTab}
onChange={setActiveTab}
items={[
{ key: 'logs', label: t('明细日志') },
...(canViewTeamUsage
? [{ key: 'ranking', label: t('成员排行') }]
: []),
]}
/>
{/* 筛选栏(原型 .ee-filter-card / .eex-filter-grid) */}
<OrgFilterCard
className='oc-exp-filter'
actions={
<>
<Button onClick={handleReset}>{t('重置')}</Button>
<Button
icon={<Download size={14} />}
type='primary'
icon={<Search size={16} />}
onClick={() => handleSearch(false)}
loading={loading}
>
{t('搜索')}
</Button>
</>
}
>
<AntForm layout='vertical' requiredMark={false} component='div'>
<AntForm.Item label={t('成员')}>
{canViewTeamUsage ? (
<Select
value={selectedUserId}
onChange={setSelectedUserId}
optionList={memberOptions}
style={{ width: '100%' }}
placeholder={isAdmin ? t('全部成员') : t('全部部门成员')}
filter
/>
) : (
<div className='oc-exp-self'>{t('仅本人')}</div>
)}
</AntForm.Item>
</AntForm>
<AntForm layout='vertical' requiredMark={false} component='div'>
<AntForm.Item label={t('时间范围')}>
<DatePicker
type='dateTimeRange'
value={dateRange}
onChange={(v) => {
setDateRange(v);
setIsDefaultRange(false);
}}
placeholder={[t('开始时间'), t('结束时间')]}
style={{ width: '100%' }}
/>
</AntForm.Item>
</AntForm>
<AntForm layout='vertical' requiredMark={false} component='div'>
<AntForm.Item label={t('模型名称')}>
<Input
placeholder={t('请输入模型名称')}
value={modelName}
onChange={setModelName}
onEnterPress={() => handleSearch(false)}
/>
</AntForm.Item>
</AntForm>
</OrgFilterCard>
<OrgListCard
title={activeTab === 'ranking' ? t('成员排行') : t('明细日志')}
tools={
<>
<Button
icon={<Download size={16} />}
onClick={() => setExportModalVisible(true)}
>
{t('导出')}
</Button>
<Button
icon={<RefreshCw size={14} />}
icon={<RefreshCw size={16} />}
onClick={() => handleSearch(true)}
loading={loading}
>
@@ -799,164 +862,60 @@ const OrgLogs = ({ orgId, orgRole, isDeptManager = false }) => {
</Button>
</>
}
/>
{/* 统计卡片 */}
<div className='grid grid-cols-1 sm:grid-cols-3 gap-3 mb-4'>
<StatCard
compact
tone='brand'
icon={Coins}
label={t('总消耗额度')}
value={statLoading ? '...' : renderQuota(stat.quota, 2)}
/>
<StatCard
compact
tone='rose'
icon={Zap}
label={stat.has_time_range ? t('平均 RPM') : t('RPM(需选时间范围)')}
value={
statLoading ? '...' : stat.has_time_range ? String(stat.rpm) : '—'
}
/>
<StatCard
compact
tone='sky'
icon={Activity}
label={stat.has_time_range ? t('平均 TPM') : t('TPM(需选时间范围)')}
value={
statLoading
? '...'
: stat.has_time_range
? formatNumber(stat.tpm)
: '—'
}
/>
</div>
{/* 筛选栏 */}
<div className='flex flex-wrap items-end gap-3 mb-4 p-4 rounded-xl border border-[var(--border-subtle)] bg-[var(--surface-card)] shadow-[var(--elevation-xs)]'>
{canViewTeamUsage ? (
<div className='min-w-[160px]'>
<div className='text-xs text-gray-500 dark:text-gray-400 mb-1'>
{t('成员')}
</div>
<Select
value={selectedUserId}
onChange={setSelectedUserId}
optionList={memberOptions}
style={{ width: 180 }}
placeholder={isAdmin ? t('全部成员') : t('全部部门成员')}
filter
/>
</div>
) : (
<div className='min-w-[160px]'>
<div className='text-xs text-gray-500 dark:text-gray-400 mb-1'>
{t('成员')}
</div>
<div className='h-8 px-3 inline-flex items-center rounded-md border border-gray-200 dark:border-neutral-700 bg-gray-50/80 dark:bg-neutral-800/70 text-sm text-gray-600 dark:text-gray-300'>
{t('仅本人')}
</div>
</div>
)}
<div className='min-w-[280px]'>
<div className='text-xs text-gray-500 dark:text-gray-400 mb-1'>
{t('时间范围')}
</div>
<DatePicker
type='dateTimeRange'
density='compact'
value={dateRange}
onChange={(v) => {
setDateRange(v);
setIsDefaultRange(false);
}}
placeholder={[t('开始时间'), t('结束时间')]}
style={{ width: 320 }}
/>
</div>
<div className='min-w-[140px]'>
<div className='text-xs text-gray-500 dark:text-gray-400 mb-1'>
{t('模型名称')}
</div>
<Input
placeholder={t('输入模型名称')}
value={modelName}
onChange={setModelName}
onEnterPress={() => handleSearch(false)}
style={{ width: 180 }}
/>
</div>
<div className='flex gap-2'>
<Button
theme='solid'
onClick={() => handleSearch(false)}
loading={loading}
>
{t('查询')}
</Button>
<Button onClick={handleReset}>{t('重置')}</Button>
</div>
</div>
{/* Tabs: 明细日志 / 成员排行 */}
<div className='rounded-xl border border-[var(--border-subtle)] bg-[var(--surface-card)] shadow-[var(--elevation-xs)] p-4'>
<Tabs activeKey={activeTab} onChange={setActiveTab}>
<TabPane tab={t('明细日志')} itemKey='logs'>
<Table
columns={logColumns}
dataSource={logs}
loading={loading}
rowKey='id'
pagination={{
currentPage: page,
pageSize,
total,
onPageChange: (p) => doPageFetch(p),
}}
empty={
<div className='py-10 text-center'>
<div className='inline-flex p-3 rounded-full bg-gray-100 dark:bg-neutral-800 mb-3'>
<Receipt
size={24}
className='text-gray-400 dark:text-gray-500'
/>
</div>
<p className='text-gray-400 dark:text-gray-500 text-sm'>
{t('暂无消耗记录')}
</p>
>
{activeTab === 'ranking' && canViewTeamUsage ? (
<Table
columns={rankingColumns}
dataSource={ranking}
loading={rankingLoading}
rowKey='user_id'
pagination={false}
scroll={{ x: 790 }}
empty={
<div className='py-10 text-center'>
<div className='inline-flex p-3 rounded-full bg-gray-100 dark:bg-neutral-800 mb-3'>
<Trophy
size={24}
className='text-gray-400 dark:text-gray-500'
/>
</div>
}
/>
</TabPane>
{canViewTeamUsage && (
<TabPane tab={t('成员排行')} itemKey='ranking'>
<Table
columns={rankingColumns}
dataSource={ranking}
loading={rankingLoading}
rowKey='user_id'
pagination={false}
empty={
<div className='py-10 text-center'>
<div className='inline-flex p-3 rounded-full bg-gray-100 dark:bg-neutral-800 mb-3'>
<Trophy
size={24}
className='text-gray-400 dark:text-gray-500'
/>
</div>
<p className='text-gray-400 dark:text-gray-500 text-sm'>
{t('暂无排行数据')}
</p>
</div>
}
/>
</TabPane>
)}
</Tabs>
</div>
<p className='text-gray-400 dark:text-gray-500 text-sm'>
{t('暂无排行数据')}
</p>
</div>
}
/>
) : (
<Table
columns={logColumns}
dataSource={logs}
loading={loading}
rowKey='id'
scroll={{ x: 1285 }}
pagination={{
currentPage: page,
pageSize,
total,
showSizeChanger: false,
onPageChange: (p) => doPageFetch(p),
showTotal: (n) => t('共 {{total}} 条', { total: n }),
}}
empty={
<div className='py-10 text-center'>
<div className='inline-flex p-3 rounded-full bg-gray-100 dark:bg-neutral-800 mb-3'>
<Receipt
size={24}
className='text-gray-400 dark:text-gray-500'
/>
</div>
<p className='text-gray-400 dark:text-gray-500 text-sm'>
{t('暂无消耗记录')}
</p>
</div>
}
/>
)}
</OrgListCard>
{/* 导出弹窗:汇总 / 按用户 + 字段选择 */}
<OrgModal