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
+170 -130
View File
@@ -17,29 +17,23 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { Breadcrumb } from 'antd';
import {
Breadcrumb,
Card as AntCard,
Progress as AntProgress,
Tag as AntTag,
} from 'antd';
import { timestamp2string } from '../../helpers/utils';
import { useNavigate } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import {
Button,
Tag,
Progress,
Form,
Toast,
Empty,
Spin,
Typography,
} from '@/components/ui';
import { Button, Tag, Form, Toast, Empty, Spin } from '@/components/ui';
import {
Wallet,
Key,
FileClock,
Plus,
RefreshCw,
Pencil,
Clock,
TrendingUp,
BarChart3,
Coins,
KeyRound,
} from 'lucide-react';
@@ -55,8 +49,8 @@ import OrgModal from './components/OrgModal';
import OrgNicknameModal from './components/OrgNicknameModal';
import OrgPasswordModal from './components/OrgPasswordModal';
import { orgStatusColor } from './components/orgStatus';
import OrgPanel from './components/OrgPanel';
import StatCard from './components/OrgStatCard';
import '../../styles/org-center.css';
// 时段问候(工作台 hero 签名区的 eyebrow)
const getGreeting = (t) => {
@@ -68,7 +62,6 @@ const getGreeting = (t) => {
return t('晚上好');
};
const { Text, Title } = Typography;
const getOrgHeaders = (orgId) => ({ 'X-Org-Id': String(orgId) });
const PERIODIC_QUOTA_PERIODS = new Set(['daily', 'weekly', 'monthly']);
@@ -119,7 +112,11 @@ const reqStatusTag = (t, status) => {
expired: { text: t('已过期') },
};
const s = map[status] || { text: status };
return <Tag color={orgStatusColor(status)}>{s.text}</Tag>;
return (
<Tag color={orgStatusColor(status)} bordered={false}>
{s.text}
</Tag>
);
};
const isFeatureEnabled = (flags, key) => {
@@ -127,23 +124,35 @@ const isFeatureEnabled = (flags, key) => {
return value === true || value === 'true' || value === '1' || value === 1;
};
// 用量趋势小块:窗口标题 + 消耗 + 请求数
const UsageBlock = ({ t, title, data }) => (
<div className='org-workbench-usage-block'>
<div className='text-xs font-medium text-gray-500 dark:text-gray-400 mb-1'>
{title}
</div>
<div className='text-lg font-semibold tabular-nums text-[var(--text-primary)]'>
{renderQuota(data?.quota || 0, 2)}
</div>
<div className='text-xs text-gray-500 mt-0.5'>
{t('请求数')} {data?.requests || 0} · {t('Token 总量')}{' '}
{data?.tokens || 0}
</div>
</div>
);
// 金额拆分货币符号(原型 <small>¥</small>742.17);无符号时原样展示
const splitAmount = (text) => {
const s = String(text ?? '');
const m = s.match(/^([^\d\-−]+)(.*)$/);
return m ? [m[1].trim(), m[2]] : ['', s];
};
const formatCount = (v) => Number(v || 0).toLocaleString('en-US');
// 企业工作台:员工自助门户(§36.1)——个人额度/用量统计/令牌/申请。
// 个人用量块:窗口标题 + 消耗 + 请求数 + Token 总量(原型 .ew-usage-grid article)
const UsageBlock = ({ t, title, data }) => {
const [symbol, amount] = splitAmount(renderQuota(data?.quota || 0, 2));
return (
<article>
<span>{title}</span>
<strong>
{symbol && <small>{symbol}</small>}
{amount}
</strong>
<div>
{t('请求数')} <b>{formatCount(data?.requests)}</b>
</div>
<div>
{t('Token 总量')} <b>{formatCount(data?.tokens)}</b>
</div>
</article>
);
};
// 企业工作台:员工自助门户(§36.1)——个人额度/用量统计/密钥/申请。
const OrgWorkbench = ({ orgId, orgRole, featureFlags }) => {
const { t } = useTranslation();
const navigate = useNavigate();
@@ -386,7 +395,7 @@ const OrgWorkbench = ({ orgId, orgRole, featureFlags }) => {
summary?.member?.display_name || summary?.member?.username || '';
return (
<div className='org-stagger org-workbench'>
<div className='org-stagger org-workbench oc-page oc-workbench'>
<Breadcrumb
className='org-workbench-breadcrumb'
items={[{ title: t('企业中心') }, { title: t('工作台') }]}
@@ -394,26 +403,27 @@ const OrgWorkbench = ({ orgId, orgRole, featureFlags }) => {
<OrgHero
eyebrow={`${getGreeting(t)}${memberName ? ',' + memberName : ''}`}
title={summary?.organization?.name || t('企业工作台')}
subtitle={`${t('个人工作台')} · ${t('我的角色')}:${roleLabel(t, role)}${summary?.member?.department_name ? ' · ' + summary.member.department_name : ''}`}
subtitle={
// 原型以标签呈现身份信息(个人工作台 / 角色 / 部门),数据同原副标题
<span className='oc-wb-tags'>
<AntTag>{t('个人工作台')}</AntTag>
<AntTag>{roleLabel(t, role)}</AntTag>
{summary?.member?.department_name && (
<AntTag>{summary.member.department_name}</AntTag>
)}
</span>
}
actions={
<>
<Button
theme='light'
icon={<Pencil size={14} />}
onClick={openNickModal}
>
<Button theme='light' onClick={openNickModal}>
{t('编辑昵称')}
</Button>
<Button
theme='light'
icon={<KeyRound size={14} />}
onClick={() => setPwdModal(true)}
>
<Button theme='light' onClick={() => setPwdModal(true)}>
{t('修改密码')}
</Button>
<Button
theme='light'
icon={<RefreshCw size={14} />}
icon={<RefreshCw size={16} />}
loading={loading}
onClick={() => {
fetchSummary();
@@ -454,121 +464,146 @@ const OrgWorkbench = ({ orgId, orgRole, featureFlags }) => {
/>
</div>
{/* 我的额度进度 + 我的令牌 */}
<div className='org-workbench-middle'>
<OrgPanel className='org-workbench-quota'>
<div className='flex items-center gap-2 mb-3'>
<Wallet size={18} className='text-brand-deep' />
<Text strong>{t('我的额度')}</Text>
{/* 我的额度 + 我的密钥(原型 .ew-middle) */}
<div className='oc-wb-middle'>
<AntCard className='oc-wb-card oc-wb-quota'>
<div className='oc-wb-heading'>
<h2>
<Wallet size={16} />
{t('我的额度')}
</h2>
{quotaLimit > 0 && <span>{quotaLimitLabel}</span>}
</div>
{quotaLimit > 0 ? (
<>
<Progress
<div className='oc-wb-quota-main'>
<div>
<strong>
{renderQuota(Math.max(0, quotaLimit - usedQuota), 2)}
</strong>
<span>
{t('可用')} / {renderQuota(quotaLimit, 2)}
</span>
</div>
<div className='oc-wb-percent'>
{quotaPercent}%<span>{t('已使用')}</span>
</div>
</div>
<AntProgress
percent={quotaPercent}
stroke={
quotaPercent >= 90 ? 'var(--ui-color-danger)' : undefined
showInfo={false}
size='small'
strokeColor={
quotaPercent >= 90
? 'var(--ui-color-danger)'
: {
'0%': 'var(--oc-quota-from)',
'100%': 'var(--oc-quota-to)',
}
}
style={{ marginBottom: 8 }}
/>
<Text type='tertiary' size='small'>
{quotaIsPeriodic ? t('本周期已用') : t('已用')}{' '}
{renderQuota(usedQuota, 2)} / {renderQuota(quotaLimit, 2)}
{quotaIsPeriodic
? ` · ${t('累计已用')} ${renderQuota(totalUsedQuota, 2)}`
: ''}
</Text>
<div className='oc-wb-quota-caption'>
<span>
{quotaIsPeriodic ? t('本周期已用') : t('已用')}{' '}
{renderQuota(usedQuota, 2)}
</span>
{quotaIsPeriodic && (
<span>
{t('累计已用')} {renderQuota(totalUsedQuota, 2)}
</span>
)}
</div>
</>
) : (
<Text type='tertiary' size='small'>
<p className='oc-wb-quota-empty'>
{t('未设个人上限,使用企业统一额度池')}
</Text>
</p>
)}
<div className='mt-2'>
<Text type='tertiary' size='small'>
{t('实际可用还受所在部门/项目及企业预算约束。')}
</Text>
</div>
<div className='mt-3'>
<div className='oc-wb-quota-bottom'>
<span>{t('实际可用还受所在部门/项目及企业预算约束。')}</span>
<Button
size='small'
icon={<Plus size={14} />}
theme='solid'
onClick={openReqModal}
disabled={!approvalEnabled || subjectOptions.length === 0}
>
{t('申请提额')}
</Button>
</div>
</OrgPanel>
</AntCard>
<OrgPanel className='org-workbench-tokens'>
<div className='flex items-center gap-2 mb-3'>
<Key size={18} className='text-brand-deep' />
<Text strong>{t('我的令牌')}</Text>
<AntCard className='oc-wb-card oc-wb-tokens'>
<div className='oc-wb-heading'>
<h2>
<Key size={16} />
{t('我的密钥')}
</h2>
</div>
<Title heading={2} style={{ margin: '4px 0' }}>
{summary?.token_count ?? 0}
</Title>
<Button
size='small'
theme='light'
onClick={() => navigate('/org/tokens')}
>
{t('管理令牌')}
<div className='oc-wb-token-content'>
<span className='oc-wb-token-art' aria-hidden='true'>
<KeyRound size={40} />
</span>
<div>
<strong>{summary?.token_count ?? 0}</strong>
<span>{t('个密钥')}</span>
</div>
</div>
<Button theme='light' onClick={() => navigate('/org/tokens')}>
{t('管理密钥')}
</Button>
</OrgPanel>
</AntCard>
</div>
{/* 个人用量趋势 */}
<OrgPanel className='org-workbench-usage'>
<div className='flex items-center gap-2 mb-3'>
<TrendingUp size={18} className='text-brand-deep' />
<Text strong>{t('个人用量趋势')}</Text>
{/* 个人用量(原型 .ew-usage) */}
<AntCard className='oc-wb-card oc-wb-usage'>
<div className='oc-wb-heading'>
<h2>
<BarChart3 size={16} />
{t('个人用量')}
</h2>
<span>{t('消费与调用概览')}</span>
</div>
<div className='org-workbench-usage-grid'>
<div className='oc-wb-usage-grid'>
<UsageBlock t={t} title={t('今日')} data={usage.today} />
<UsageBlock t={t} title={t('近 7 天')} data={usage.last7d} />
<UsageBlock t={t} title={t('近 30 天')} data={usage.last30d} />
<UsageBlock t={t} title={t('累计')} data={usage.total} />
</div>
</OrgPanel>
</AntCard>
{/* 最近申请 */}
<OrgPanel>
<div className='flex items-center gap-2 mb-3'>
<FileClock size={18} className='text-brand-deep' />
<Text strong>{t('最近申请')}</Text>
{/* 最近申请(原型 .ew-requests) */}
<AntCard className='oc-wb-card oc-wb-requests'>
<div className='oc-wb-heading'>
<h2>
<FileClock size={16} />
{t('最近申请')}
</h2>
</div>
{summary?.recent_requests?.length ? (
<div className='flex flex-col divide-y divide-[var(--ui-color-border)]'>
{summary.recent_requests.map((r) => (
<div
key={r.id}
className='flex items-center justify-between py-2.5'
>
<div>
<Text>
{r.request_type === 'quota'
? t('提额申请')
: r.request_type}
{r.reason ? ` · ${r.reason}` : ''}
</Text>
<div>
<Text type='tertiary' size='small'>
{r.created_at ? timestamp2string(r.created_at) : ''}
</Text>
</div>
</div>
{reqStatusTag(t, r.status)}
summary.recent_requests.map((r) => (
<article key={r.id}>
<span className='oc-wb-request-icon' aria-hidden='true'>
<FileClock size={16} />
</span>
<div>
<h3>
{r.request_type === 'quota' ? t('提额申请') : r.request_type}
{r.reason ? ` · ${r.reason}` : ''}
</h3>
<span>
{r.created_at ? timestamp2string(r.created_at) : ''}
</span>
</div>
))}
</div>
{reqStatusTag(t, r.status)}
</article>
))
) : (
<Empty description={t('暂无申请记录')} />
)}
</OrgPanel>
</AntCard>
{/* 提额申请弹窗 */}
<OrgModal
className='oc-dialog'
title={t('申请提额')}
visible={reqModal}
onOk={submitRequest}
@@ -576,20 +611,19 @@ const OrgWorkbench = ({ orgId, orgRole, featureFlags }) => {
okText={t('提交申请')}
cancelText={t('取消')}
>
<Form getFormApi={setFormApi}>
{/* 原型 .ew 提额弹窗:竖排表单、不显示必填星号(校验规则不变),说明为字段 extra */}
<Form getFormApi={setFormApi} requiredMark={false}>
<Form.Select
field='subject'
label={t('提额对象')}
initValue={subjectOptions[0]?.value}
optionList={subjectOptions}
rules={[{ required: true, message: t('请选择提额对象') }]}
style={{ width: '100%' }}
/>
<Text type='tertiary' size='small'>
{t(
extraText={t(
'个人额度用于解除您自己的使用上限;部门/项目额度属于预算上限,可能有独立周期。',
)}
</Text>
style={{ width: '100%' }}
/>
<Form.InputNumber
field='delta'
label={deltaLabel}
@@ -612,7 +646,13 @@ const OrgWorkbench = ({ orgId, orgRole, featureFlags }) => {
]}
style={{ width: '100%' }}
/>
<Form.TextArea field='reason' label={t('申请理由')} maxCount={200} />
<Form.TextArea
field='reason'
label={t('申请理由')}
maxCount={200}
rows={4}
showCount
/>
</Form>
</OrgModal>