feat: 参考原型图 ui优化提交 企业端-企业中心 相关的页面
This commit is contained in:
@@ -28,28 +28,24 @@ import { timestamp2string } from '../../helpers/utils';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import {
|
||||
BarChart2,
|
||||
Users,
|
||||
Key,
|
||||
Wallet,
|
||||
TrendingUp,
|
||||
ArrowRight,
|
||||
ShieldCheck,
|
||||
Crown,
|
||||
Shield,
|
||||
PiggyBank,
|
||||
Flame,
|
||||
Coins,
|
||||
RefreshCw,
|
||||
Search,
|
||||
FileText,
|
||||
CreditCard,
|
||||
Activity,
|
||||
} from 'lucide-react';
|
||||
import {
|
||||
Avatar as AntAvatar,
|
||||
Card as AntCard,
|
||||
Tag as AntTag,
|
||||
Typography,
|
||||
} from 'antd';
|
||||
import {
|
||||
Progress,
|
||||
Table,
|
||||
Tag,
|
||||
Button,
|
||||
DatePicker,
|
||||
Input,
|
||||
@@ -60,14 +56,14 @@ import { useOrgDashboard, useOrgQuota } from '../../hooks/org/useOrgData';
|
||||
import { renderQuota } from '../../helpers/render';
|
||||
import { API, showError } from '../../helpers';
|
||||
import Loading from '../../components/common/ui/Loading';
|
||||
import OrgPageHeader from './components/OrgPageHeader';
|
||||
import OrgBreadcrumb from './components/OrgBreadcrumb';
|
||||
import OrgAnalyticsPanel from './components/OrgAnalyticsPanel';
|
||||
import StatCard from './components/OrgStatCard';
|
||||
import OrgPanel from './components/OrgPanel';
|
||||
import '../../styles/org-center.css';
|
||||
import OrgSideSheet from './components/OrgSideSheet';
|
||||
import OrgStateBlock from './components/OrgStateBlock';
|
||||
import { StatusContext } from '../../context/Status';
|
||||
import { normalizeSidebarModulesAdmin } from '../../constants/sidebarModules';
|
||||
import { getOrgQuotaAvailability } from './orgQuotaAvailability';
|
||||
|
||||
const getOrgHeaders = (orgId) => ({ 'X-Org-Id': String(orgId) });
|
||||
|
||||
@@ -108,7 +104,7 @@ const isFeatureEnabled = (flags, key) => {
|
||||
// 状态配置
|
||||
const getStatusConfig = (status, t) => {
|
||||
const map = {
|
||||
1: { label: t('正常'), tagLabel: t('运行正常'), color: 'green' },
|
||||
1: { label: t('正常'), tagLabel: t('企业运行正常'), color: 'green' },
|
||||
2: { label: t('冻结'), tagLabel: t('已被冻结'), color: 'red' },
|
||||
3: { label: t('欠费'), tagLabel: t('额度不足'), color: 'orange' },
|
||||
};
|
||||
@@ -363,7 +359,20 @@ const MemberUsageSheet = ({ visible, onClose, member, orgId, t }) => {
|
||||
);
|
||||
};
|
||||
|
||||
const OrgDashboard = ({ orgId, orgRole, featureFlags }) => {
|
||||
// 原型 .ea-budget-primary strong small:货币符号缩小为独立 small,数值格式仍来自 renderQuota
|
||||
const renderBudgetAmount = (quota) => {
|
||||
const text = String(renderQuota(quota, 2) ?? '');
|
||||
const m = text.match(/^([^\d\-−]+)(.*)$/);
|
||||
if (!m) return text;
|
||||
return (
|
||||
<>
|
||||
<small>{m[1].trim()}</small>
|
||||
{m[2]}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const OrgDashboard = ({ orgId, orgRole, orgName, featureFlags }) => {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const [statusState] = useContext(StatusContext);
|
||||
@@ -398,140 +407,88 @@ const OrgDashboard = ({ orgId, orgRole, featureFlags }) => {
|
||||
{
|
||||
title: t('成员'),
|
||||
dataIndex: 'display_name',
|
||||
width: 200,
|
||||
render: (text, record) => (
|
||||
<div className='flex items-center gap-2.5'>
|
||||
<div className='flex-shrink-0 w-8 h-8 rounded-full bg-brand/10 text-brand flex items-center justify-center text-xs font-semibold'>
|
||||
{(text || record.username || '?').charAt(0).toUpperCase()}
|
||||
</div>
|
||||
<div className='min-w-0'>
|
||||
width: 170,
|
||||
render: (text, record) => {
|
||||
const name = text || record.username;
|
||||
return (
|
||||
<div className='oc-ea-member'>
|
||||
<AntAvatar size={28}>
|
||||
{(name || '?').charAt(0).toUpperCase()}
|
||||
</AntAvatar>
|
||||
{isAdmin ? (
|
||||
<div
|
||||
className='font-medium text-brand-deep truncate text-sm cursor-pointer hover:text-brand hover:underline transition-colors'
|
||||
<button
|
||||
type='button'
|
||||
className='oc-ea-member-link'
|
||||
onClick={() => handleViewMemberUsage(record)}
|
||||
>
|
||||
{text || record.username}
|
||||
</div>
|
||||
{name}
|
||||
</button>
|
||||
) : (
|
||||
<div className='font-medium text-gray-900 dark:text-white truncate text-sm'>
|
||||
{text || record.username}
|
||||
</div>
|
||||
<span>{name}</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: t('角色'),
|
||||
dataIndex: 'role',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
width: 132,
|
||||
render: (role) => {
|
||||
const config = {
|
||||
owner: { label: t('所有者'), color: 'red', icon: Crown },
|
||||
admin: { label: t('管理员'), color: 'blue', icon: ShieldCheck },
|
||||
dept_admin: {
|
||||
label: t('部门管理员'),
|
||||
color: 'cyan',
|
||||
icon: ShieldCheck,
|
||||
},
|
||||
super_admin: {
|
||||
label: t('超级管理员'),
|
||||
color: 'violet',
|
||||
icon: ShieldCheck,
|
||||
},
|
||||
member: { label: t('成员'), color: 'grey', icon: Shield },
|
||||
owner: { label: t('所有者'), color: 'volcano' },
|
||||
admin: { label: t('管理员'), color: 'geekblue' },
|
||||
dept_admin: { label: t('部门管理员'), color: 'cyan' },
|
||||
super_admin: { label: t('超级管理员'), color: 'purple' },
|
||||
member: { label: t('成员'), color: 'default' },
|
||||
};
|
||||
const c = config[role] || config.member;
|
||||
return (
|
||||
<div className='flex items-center justify-center gap-1'>
|
||||
<c.icon
|
||||
size={12}
|
||||
className={
|
||||
role === 'owner'
|
||||
? 'text-amber-500'
|
||||
: role === 'admin' ||
|
||||
role === 'dept_admin' ||
|
||||
role === 'super_admin'
|
||||
? 'text-brand-deep'
|
||||
: 'text-gray-400 dark:text-gray-500'
|
||||
}
|
||||
/>
|
||||
<Tag size='small' color={c.color}>
|
||||
{c.label}
|
||||
</Tag>
|
||||
</div>
|
||||
);
|
||||
return <AntTag color={c.color}>{c.label}</AntTag>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: t('周期内已用'),
|
||||
dataIndex: 'quota_used_in_period',
|
||||
width: 120,
|
||||
width: 130,
|
||||
align: 'right',
|
||||
render: (v, record) =>
|
||||
isPeriodicQuotaPeriod(record.quota_period) ? (
|
||||
<span className='text-gray-700 dark:text-gray-300 font-medium'>
|
||||
{renderQuota(safeQuotaNumber(v), 2)}
|
||||
</span>
|
||||
) : (
|
||||
<span className='text-xs text-gray-400 dark:text-gray-500'>—</span>
|
||||
),
|
||||
isPeriodicQuotaPeriod(record.quota_period)
|
||||
? renderQuota(safeQuotaNumber(v), 2)
|
||||
: '—',
|
||||
},
|
||||
{
|
||||
title: t('总已用额度'),
|
||||
dataIndex: 'used_quota',
|
||||
width: 120,
|
||||
width: 130,
|
||||
align: 'right',
|
||||
render: (v) => (
|
||||
<span className='text-gray-700 dark:text-gray-300 font-medium'>
|
||||
{renderQuota(safeQuotaNumber(v), 2)}
|
||||
</span>
|
||||
),
|
||||
render: (v) => renderQuota(safeQuotaNumber(v), 2),
|
||||
},
|
||||
{
|
||||
title: t('额度上限/周期'),
|
||||
title: t('额度上限 / 周期'),
|
||||
dataIndex: 'quota_limit',
|
||||
width: 150,
|
||||
align: 'right',
|
||||
render: (v, record) => {
|
||||
const quotaLimit = safeQuotaNumber(v);
|
||||
return quotaLimit > 0 ? (
|
||||
<div className='text-right'>
|
||||
<div className='text-gray-700 dark:text-gray-300'>
|
||||
{renderQuota(quotaLimit, 2)}
|
||||
</div>
|
||||
<div
|
||||
className={`text-[11px] ${
|
||||
isPeriodicQuotaPeriod(record.quota_period)
|
||||
? 'text-gray-400 dark:text-gray-500'
|
||||
: 'text-amber-500'
|
||||
}`}
|
||||
>
|
||||
<div className='oc-ea-limit'>
|
||||
{renderQuota(quotaLimit, 2)}
|
||||
<small>
|
||||
{quotaPeriodLimitLabel(t, record.quota_period)}
|
||||
{!isPeriodicQuotaPeriod(record.quota_period) &&
|
||||
` · ${t('不重置')}`}
|
||||
</div>
|
||||
</small>
|
||||
</div>
|
||||
) : (
|
||||
<span className='text-gray-400 dark:text-gray-500'>
|
||||
{t('不限')}
|
||||
</span>
|
||||
t('不限')
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: t('使用进度'),
|
||||
width: 160,
|
||||
width: 150,
|
||||
render: (_, record) => {
|
||||
const quotaLimit = safeQuotaNumber(record.quota_limit);
|
||||
if (quotaLimit <= 0) {
|
||||
return (
|
||||
<span className='text-xs text-gray-400 dark:text-gray-500'>
|
||||
-
|
||||
</span>
|
||||
);
|
||||
}
|
||||
if (quotaLimit <= 0) return '—';
|
||||
// 周期模式按「周期内已用 / 上限」;终身模式按「总已用 / 上限」。
|
||||
const usedForProgress = isPeriodicQuotaPeriod(record.quota_period)
|
||||
? safeQuotaNumber(record.quota_used_in_period)
|
||||
@@ -541,17 +498,11 @@ const OrgDashboard = ({ orgId, orgRole, featureFlags }) => {
|
||||
Math.round((usedForProgress / quotaLimit) * 100),
|
||||
);
|
||||
return (
|
||||
<div className='flex items-center gap-2'>
|
||||
<Progress
|
||||
percent={percent}
|
||||
size='small'
|
||||
style={{ width: 100 }}
|
||||
stroke={usageStrokeColor(percent)}
|
||||
/>
|
||||
<span className='text-xs text-gray-500 dark:text-gray-400 w-8 text-right'>
|
||||
{percent}%
|
||||
</span>
|
||||
</div>
|
||||
<Progress
|
||||
percent={percent}
|
||||
size='small'
|
||||
stroke={usageStrokeColor(percent)}
|
||||
/>
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -559,6 +510,22 @@ const OrgDashboard = ({ orgId, orgRole, featureFlags }) => {
|
||||
[t, isAdmin, handleViewMemberUsage],
|
||||
);
|
||||
|
||||
// “成员用量”按钮:切换到成员用量明细并在页内定位(不发请求)
|
||||
const membersAnchorRef = useRef(null);
|
||||
const [detailTab, setDetailTab] = useState('models');
|
||||
const showMembers = () => {
|
||||
setDetailTab('members');
|
||||
window.setTimeout(() => {
|
||||
const reduce = window.matchMedia?.(
|
||||
'(prefers-reduced-motion: reduce)',
|
||||
)?.matches;
|
||||
membersAnchorRef.current?.scrollIntoView({
|
||||
behavior: reduce ? 'auto' : 'smooth',
|
||||
block: 'start',
|
||||
});
|
||||
}, 60);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetch();
|
||||
fetchQuota();
|
||||
@@ -578,7 +545,7 @@ const OrgDashboard = ({ orgId, orgRole, featureFlags }) => {
|
||||
? Math.min(100, Math.round((usedQuota / totalQuota) * 100))
|
||||
: 0;
|
||||
|
||||
// 成员/令牌容量占用率:与其他使用进度共用同一套阈值语义色
|
||||
// 成员/密钥容量占用率:与其他使用进度共用同一套阈值语义色
|
||||
const memberPercent =
|
||||
data?.max_members > 0
|
||||
? Math.min(
|
||||
@@ -595,9 +562,10 @@ const OrgDashboard = ({ orgId, orgRole, featureFlags }) => {
|
||||
: 0;
|
||||
|
||||
const statusConfig = getStatusConfig(data?.status, t);
|
||||
const quotaAvailability = getOrgQuotaAvailability(data);
|
||||
|
||||
// 成员明细对账:成员合计(终身已用)与企业池已用(org.UsedQuota)通常不相等,
|
||||
// 差额为「未归属」消费(令牌未绑定成员 / 管理员直接使用 / 成员跟踪前的历史),
|
||||
// 差额为「未归属」消费(密钥未绑定成员 / 管理员直接使用 / 成员跟踪前的历史),
|
||||
// 显式列出避免用户误以为成员明细加总应等于顶部「已用额度」。
|
||||
const memberQuotaRows = quotaData?.member_quotas || [];
|
||||
const memberQuotaPage = Number(quotaData?.member_page || 1);
|
||||
@@ -615,29 +583,88 @@ const OrgDashboard = ({ orgId, orgRole, featureFlags }) => {
|
||||
const poolUsedQuota = Number(quotaData?.used_quota ?? data?.used_quota ?? 0);
|
||||
const unattributedQuota = Math.max(0, poolUsedQuota - memberUsedSum);
|
||||
|
||||
const statusTone = data?.status === 1 ? 'ok' : data?.status ? 'warn' : 'none';
|
||||
|
||||
const memberUsageCard = (
|
||||
<AntCard className='oc-ea-detail-card oc-ea-members'>
|
||||
<div className='oc-ea-table-toolbar'>
|
||||
<h2>{t('成员用量明细')}</h2>
|
||||
<Link to='/org/members' className='oc-ea-view-all'>
|
||||
{t('查看全部')}
|
||||
<ArrowRight size={12} />
|
||||
</Link>
|
||||
</div>
|
||||
<Table
|
||||
columns={memberColumns}
|
||||
dataSource={memberQuotaRows}
|
||||
loading={quotaLoading}
|
||||
rowKey='member_id'
|
||||
scroll={{ x: 860 }}
|
||||
pagination={
|
||||
memberQuotaTotal > memberQuotaPageSize
|
||||
? {
|
||||
currentPage: memberQuotaPage,
|
||||
pageSize: memberQuotaPageSize,
|
||||
total: memberQuotaTotal,
|
||||
showSizeChanger: false,
|
||||
onPageChange: (page) => fetchQuota(page, memberQuotaPageSize),
|
||||
showTotal: (n) => t('共 {{total}} 条', { total: n }),
|
||||
}
|
||||
: false
|
||||
}
|
||||
empty={<OrgStateBlock icon={Users} title={t('暂无成员数据')} />}
|
||||
/>
|
||||
{memberQuotaRows.length > 0 && (
|
||||
<div className='oc-ea-member-total'>
|
||||
<span>
|
||||
{t('成员合计已用')}
|
||||
<strong>{renderQuota(memberUsedSum, 2)}</strong>
|
||||
</span>
|
||||
<span>
|
||||
{t('企业池已用')}
|
||||
<strong>{renderQuota(poolUsedQuota, 2)}</strong>
|
||||
</span>
|
||||
{unattributedQuota > 0 && (
|
||||
<Tooltip
|
||||
content={t(
|
||||
'企业池已用包含未绑定到具体成员的消费(如管理员直接使用、密钥未分配成员、成员跟踪前的历史数据),因此成员合计通常小于企业池已用。',
|
||||
)}
|
||||
>
|
||||
<span className='oc-ea-unattributed'>
|
||||
{t('未归属差额')}
|
||||
<strong>{renderQuota(unattributedQuota, 2)}</strong>
|
||||
</span>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</AntCard>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className='uc-page space-y-6'>
|
||||
{/* Header */}
|
||||
<OrgPageHeader
|
||||
icon={BarChart2}
|
||||
title={t('企业概览')}
|
||||
subtitle={t(
|
||||
'聚合企业额度、组织规模与成员消耗,和个人工作台保持职责分离',
|
||||
)}
|
||||
actions={
|
||||
<>
|
||||
{isAdmin && (
|
||||
<Button
|
||||
icon={<CreditCard size={14} />}
|
||||
theme='solid'
|
||||
type='primary'
|
||||
onClick={() => navigate('/org/recharge')}
|
||||
>
|
||||
{t('立即充值')}
|
||||
</Button>
|
||||
)}
|
||||
<div className='uc-page oc-page oc-dashboard'>
|
||||
<div className='oc-dash-breadcrumb'>
|
||||
<OrgBreadcrumb current={t('数据看板')} />
|
||||
</div>
|
||||
|
||||
{/* 企业概况(原型 .ea-hero) */}
|
||||
<header className='oc-dash-hero'>
|
||||
<div className={`oc-dash-health is-${statusTone}`}>
|
||||
<span>
|
||||
<i aria-hidden='true' />
|
||||
{statusConfig.tagLabel}
|
||||
</span>
|
||||
{orgName && <div className='oc-dash-org-name'>{orgName}</div>}
|
||||
</div>
|
||||
<div className='oc-dash-heading'>
|
||||
<div>
|
||||
<h1>{t('企业数据看板')}</h1>
|
||||
<p>{t('掌握企业额度、组织规模与模型消耗')}</p>
|
||||
</div>
|
||||
<div className='oc-dash-actions'>
|
||||
<Button onClick={showMembers}>{t('成员用量')}</Button>
|
||||
<Button
|
||||
icon={<RefreshCw size={14} />}
|
||||
icon={<RefreshCw size={16} />}
|
||||
onClick={() => {
|
||||
fetch();
|
||||
fetchQuota(memberQuotaPage, memberQuotaPageSize);
|
||||
@@ -646,237 +673,132 @@ const OrgDashboard = ({ orgId, orgRole, featureFlags }) => {
|
||||
>
|
||||
{t('刷新')}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
|
||||
{/* 统计卡片 - 三列 */}
|
||||
<div className='grid grid-cols-1 sm:grid-cols-3 gap-4'>
|
||||
<StatCard
|
||||
icon={Users}
|
||||
title={t('企业成员')}
|
||||
value={data?.member_count ?? 0}
|
||||
tone='brand'
|
||||
loading={loading}
|
||||
subtitle={
|
||||
data?.max_members > 0
|
||||
? `${t('上限')}: ${data.max_members}`
|
||||
: t('不限')
|
||||
}
|
||||
extra={
|
||||
data?.max_members > 0 && (
|
||||
<Progress
|
||||
percent={memberPercent}
|
||||
size='small'
|
||||
stroke={usageStrokeColor(memberPercent)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
/>
|
||||
<StatCard
|
||||
icon={Key}
|
||||
title={t('企业令牌')}
|
||||
value={data?.token_count ?? 0}
|
||||
tone='amber'
|
||||
loading={loading}
|
||||
subtitle={
|
||||
data?.max_tokens > 0
|
||||
? `${t('上限')}: ${data.max_tokens}`
|
||||
: t('不限')
|
||||
}
|
||||
extra={
|
||||
data?.max_tokens > 0 && (
|
||||
<Progress
|
||||
percent={tokenPercent}
|
||||
size='small'
|
||||
stroke={usageStrokeColor(tokenPercent)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
/>
|
||||
<StatCard
|
||||
icon={TrendingUp}
|
||||
title={t('企业状态')}
|
||||
value={statusConfig.label}
|
||||
tone='sky'
|
||||
loading={loading}
|
||||
extra={
|
||||
data && (
|
||||
<Tag
|
||||
size='small'
|
||||
color={statusConfig.color}
|
||||
type='light'
|
||||
className='mt-0.5'
|
||||
{isAdmin && (
|
||||
<Button
|
||||
icon={<Wallet size={16} />}
|
||||
theme='solid'
|
||||
type='primary'
|
||||
onClick={() => navigate('/org/recharge')}
|
||||
>
|
||||
{statusConfig.tagLabel}
|
||||
</Tag>
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 额度使用详情 - 全宽 */}
|
||||
<OrgPanel icon={Wallet} title={t('额度使用详情')} padding='p-5'>
|
||||
<div className='grid grid-cols-1 sm:grid-cols-3 gap-4'>
|
||||
{/* 总额度 */}
|
||||
<div className='flex items-center gap-3 p-4 rounded-xl bg-gray-50/80 dark:bg-neutral-800/50 border border-gray-100 dark:border-neutral-700/50'>
|
||||
<div className='p-2 rounded-lg bg-brand/10'>
|
||||
<Coins size={16} className='text-brand-deep' />
|
||||
</div>
|
||||
<div>
|
||||
<div className='text-xs font-medium text-gray-400 dark:text-gray-500 mb-0.5'>
|
||||
{t('总额度')}
|
||||
</div>
|
||||
<div className='text-lg font-bold text-gray-900 dark:text-white'>
|
||||
{data ? renderQuota(totalQuota, 2) : '-'}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/* 已用额度 */}
|
||||
<div className='flex items-center gap-3 p-4 rounded-xl bg-orange-50/80 dark:bg-orange-900/10 border border-orange-100 dark:border-orange-800/30'>
|
||||
<div className='p-2 rounded-lg bg-orange-100 dark:bg-orange-900/30'>
|
||||
<Flame
|
||||
size={16}
|
||||
className='text-orange-600 dark:text-orange-400'
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<div className='text-xs font-medium text-gray-400 dark:text-gray-500 mb-0.5'>
|
||||
{t('已用额度')}
|
||||
</div>
|
||||
<div className='text-lg font-bold text-orange-600 dark:text-orange-400'>
|
||||
{data ? renderQuota(usedQuota, 2) : '-'}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/* 剩余额度 */}
|
||||
<div className='flex items-center gap-3 p-4 rounded-xl bg-emerald-50/80 dark:bg-emerald-900/10 border border-emerald-100 dark:border-emerald-800/30'>
|
||||
<div className='p-2 rounded-lg bg-emerald-100 dark:bg-emerald-900/30'>
|
||||
<PiggyBank
|
||||
size={16}
|
||||
className='text-emerald-600 dark:text-emerald-400'
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<div className='text-xs font-medium text-gray-400 dark:text-gray-500 mb-0.5'>
|
||||
{t('剩余额度')}
|
||||
</div>
|
||||
<div className='text-lg font-bold text-emerald-600 dark:text-emerald-400'>
|
||||
{data ? renderQuota(Number(data.quota || 0), 2) : '-'}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 使用率进度条 */}
|
||||
<div className='mt-5 pt-4 border-t border-gray-100 dark:border-neutral-800'>
|
||||
<div className='flex items-center justify-between mb-2'>
|
||||
<span className='text-sm text-gray-500 dark:text-gray-400'>
|
||||
{t('使用率(累计)')}
|
||||
</span>
|
||||
<span
|
||||
className='text-sm font-semibold'
|
||||
style={{ color: usageStrokeColor(usedPercent) }}
|
||||
>
|
||||
{usedPercent}%
|
||||
</span>
|
||||
</div>
|
||||
<div className='w-full h-3 bg-gray-100 dark:bg-neutral-800 rounded-full overflow-hidden'>
|
||||
{/* 渐变由同一语义色的浅调 → 本色构成(单色相),
|
||||
不再引入第二色相(旧 emerald→teal 与用量分析的 teal 系列色撞车) */}
|
||||
<div
|
||||
className='h-full rounded-full transition-all duration-1000 ease-out'
|
||||
style={{
|
||||
width: `${Math.max(usedPercent, 0)}%`,
|
||||
background: `linear-gradient(90deg, color-mix(in srgb, ${usageStrokeColor(usedPercent)} 72%, #fff) 0%, ${usageStrokeColor(usedPercent)} 100%)`,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</OrgPanel>
|
||||
|
||||
{/* 成员用量明细 */}
|
||||
<OrgPanel
|
||||
icon={Users}
|
||||
title={t('成员用量明细')}
|
||||
padding='p-5'
|
||||
bodyClassName='overflow-x-auto'
|
||||
actions={
|
||||
<Link
|
||||
to='/org/members'
|
||||
className='flex items-center gap-1 text-xs text-brand-deep hover:text-brand transition-colors'
|
||||
>
|
||||
{t('查看全部')}
|
||||
<ArrowRight size={12} />
|
||||
</Link>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
columns={memberColumns}
|
||||
dataSource={memberQuotaRows}
|
||||
loading={quotaLoading}
|
||||
rowKey='member_id'
|
||||
pagination={
|
||||
memberQuotaTotal > memberQuotaPageSize
|
||||
? {
|
||||
currentPage: memberQuotaPage,
|
||||
pageSize: memberQuotaPageSize,
|
||||
total: memberQuotaTotal,
|
||||
showSizeChanger: false,
|
||||
onPageChange: (page) => fetchQuota(page, memberQuotaPageSize),
|
||||
}
|
||||
: false
|
||||
}
|
||||
size='small'
|
||||
empty={<OrgStateBlock icon={Users} title={t('暂无成员数据')} />}
|
||||
/>
|
||||
{memberQuotaRows.length > 0 && (
|
||||
<div className='mt-3 pt-3 border-t border-gray-100 dark:border-neutral-800 flex flex-wrap items-center gap-x-6 gap-y-1 text-xs'>
|
||||
<span className='text-gray-500 dark:text-gray-400'>
|
||||
{t('成员合计已用')}:
|
||||
<span className='font-medium text-gray-700 dark:text-gray-300'>
|
||||
{renderQuota(memberUsedSum, 2)}
|
||||
</span>
|
||||
</span>
|
||||
<span className='text-gray-500 dark:text-gray-400'>
|
||||
{t('企业池已用')}:
|
||||
<span className='font-medium text-gray-700 dark:text-gray-300'>
|
||||
{renderQuota(poolUsedQuota, 2)}
|
||||
</span>
|
||||
</span>
|
||||
{unattributedQuota > 0 && (
|
||||
<Tooltip
|
||||
content={t(
|
||||
'企业池已用包含未绑定到具体成员的消费(如管理员直接使用、令牌未分配成员、成员跟踪前的历史数据),因此成员合计通常小于企业池已用。',
|
||||
)}
|
||||
>
|
||||
<span className='text-amber-600 dark:text-amber-400 cursor-help'>
|
||||
{t('未归属差额')}:
|
||||
<span className='font-medium'>
|
||||
{renderQuota(unattributedQuota, 2)}
|
||||
</span>
|
||||
</span>
|
||||
</Tooltip>
|
||||
{t('立即充值')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</OrgPanel>
|
||||
|
||||
{showAnalytics && (
|
||||
<div className='space-y-3'>
|
||||
<div className='flex items-center gap-2 px-1'>
|
||||
<Activity size={16} className='text-brand-deep' />
|
||||
<div>
|
||||
<div className='font-semibold text-gray-950 dark:text-white'>
|
||||
{t('多维用量分析')}
|
||||
</div>
|
||||
<div className='oc-dash-overview'>
|
||||
<AntCard className='oc-dash-budget'>
|
||||
<div className='oc-dash-budget-heading'>
|
||||
<h2>{t('企业额度')}</h2>
|
||||
<span>{t('累计额度使用情况')}</span>
|
||||
</div>
|
||||
<div className='oc-dash-budget-primary'>
|
||||
<span>{t('剩余额度')}</span>
|
||||
<strong>
|
||||
{data ? renderBudgetAmount(Number(data.quota || 0)) : '-'}
|
||||
</strong>
|
||||
{quotaAvailability && (
|
||||
<div
|
||||
className={`oc-dash-budget-availability is-${quotaAvailability.type}`}
|
||||
role='status'
|
||||
>
|
||||
<Typography.Text type={quotaAvailability.type}>
|
||||
{t(quotaAvailability.label)}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className='oc-dash-budget-secondary'>
|
||||
<div>
|
||||
<span>{t('总额度')}</span>
|
||||
<strong>{data ? renderQuota(totalQuota, 2) : '-'}</strong>
|
||||
</div>
|
||||
<div className='text-xs text-gray-500 dark:text-gray-400'>
|
||||
{t('管理员专属经营数据,避免与个人工作台重复展示')}
|
||||
<div>
|
||||
<span>{t('已用额度')}</span>
|
||||
<strong>{data ? renderQuota(usedQuota, 2) : '-'}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div className='oc-dash-budget-progress'>
|
||||
<div>
|
||||
<span>{t('累计使用率')}</span>
|
||||
<strong style={{ color: usageStrokeColor(usedPercent) }}>
|
||||
{usedPercent}%
|
||||
</strong>
|
||||
</div>
|
||||
<Progress
|
||||
percent={usedPercent}
|
||||
size='small'
|
||||
showInfo={false}
|
||||
stroke={usageStrokeColor(usedPercent)}
|
||||
/>
|
||||
</div>
|
||||
</AntCard>
|
||||
|
||||
<div className='oc-dash-org'>
|
||||
<div>
|
||||
<span>
|
||||
<Users size={16} />
|
||||
{t('企业成员')}
|
||||
</span>
|
||||
<strong>
|
||||
{data?.member_count ?? 0}
|
||||
<small>
|
||||
{data?.max_members > 0
|
||||
? `/ ${Number(data.max_members).toLocaleString()}`
|
||||
: `/ ${t('不限')}`}
|
||||
</small>
|
||||
</strong>
|
||||
{data?.max_members > 0 && (
|
||||
<Progress
|
||||
percent={memberPercent}
|
||||
size='small'
|
||||
showInfo={false}
|
||||
stroke={usageStrokeColor(memberPercent)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<span>
|
||||
<Key size={16} />
|
||||
{t('企业密钥')}
|
||||
</span>
|
||||
<strong>
|
||||
{data?.token_count ?? 0}
|
||||
<small>
|
||||
{data?.max_tokens > 0
|
||||
? `/ ${Number(data.max_tokens).toLocaleString()}`
|
||||
: `/ ${t('不限')}`}
|
||||
</small>
|
||||
</strong>
|
||||
{data?.max_tokens > 0 && (
|
||||
<Progress
|
||||
percent={tokenPercent}
|
||||
size='small'
|
||||
showInfo={false}
|
||||
stroke={usageStrokeColor(tokenPercent)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className='oc-dash-status'>
|
||||
<span>
|
||||
<Activity size={16} />
|
||||
{t('企业状态')}
|
||||
</span>
|
||||
<strong>{statusConfig.label}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<OrgAnalyticsPanel orgId={orgId} />
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{showAnalytics ? (
|
||||
<OrgAnalyticsPanel
|
||||
orgId={orgId}
|
||||
memberUsage={memberUsageCard}
|
||||
detailTab={detailTab}
|
||||
onDetailTabChange={setDetailTab}
|
||||
detailsRef={membersAnchorRef}
|
||||
/>
|
||||
) : (
|
||||
<div ref={membersAnchorRef}>{memberUsageCard}</div>
|
||||
)}
|
||||
|
||||
{/* 成员用量明细抽屉 */}
|
||||
|
||||
Reference in New Issue
Block a user