feat: 参考原型图 ui优化提交 企业端-企业中心 相关的页面
This commit is contained in:
+137
-121
@@ -20,20 +20,13 @@ import React, { useEffect, useState } from 'react';
|
||||
import { getQuotaPerUnit } from '../../helpers';
|
||||
import { timestamp2string } from '../../helpers/utils';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { RefreshCw, ScrollText } from 'lucide-react';
|
||||
import {
|
||||
Table,
|
||||
Select,
|
||||
Button,
|
||||
Tag,
|
||||
Tooltip,
|
||||
Tabs,
|
||||
TabPane,
|
||||
} from '@/components/ui';
|
||||
import { RefreshCw, ScrollText, Search } from 'lucide-react';
|
||||
import { Form as AntForm, Tabs as AntTabs } from 'antd';
|
||||
import { Table, Select, Button, Tag, Tooltip } from '@/components/ui';
|
||||
import { API } from '../../helpers/api';
|
||||
import { useOrgAuditLogs } from '../../hooks/org/useOrgData';
|
||||
import OrgPageHeader from './components/OrgPageHeader';
|
||||
import OrgPanel from './components/OrgPanel';
|
||||
import { OrgFilterCard, OrgListCard } from './components/OrgListCard';
|
||||
import OrgStateBlock from './components/OrgStateBlock';
|
||||
import OrgPromptRecords from './OrgPromptRecords';
|
||||
import {
|
||||
@@ -62,14 +55,14 @@ const memberStatusMap = {
|
||||
};
|
||||
|
||||
const targetTypeLabels = {
|
||||
token: '令牌',
|
||||
token: '密钥',
|
||||
member: '成员',
|
||||
organization: '企业',
|
||||
invitation: '邀请',
|
||||
};
|
||||
|
||||
const targetTypeColors = {
|
||||
token: 'violet',
|
||||
token: 'purple',
|
||||
member: 'blue',
|
||||
organization: 'green',
|
||||
invitation: 'orange',
|
||||
@@ -95,9 +88,9 @@ const actionConfig = {
|
||||
accept_invitation: { label: '接受邀请', color: 'green' },
|
||||
cancel_invitation: { label: '取消邀请', color: 'grey' },
|
||||
|
||||
create_token: { label: '创建令牌', color: 'green' },
|
||||
update_token: { label: '更新令牌', color: 'blue' },
|
||||
delete_token: { label: '删除令牌', color: 'red' },
|
||||
create_token: { label: '创建密钥', color: 'green' },
|
||||
update_token: { label: '更新密钥', color: 'blue' },
|
||||
delete_token: { label: '删除密钥', color: 'red' },
|
||||
|
||||
admin_create_org: { label: '管理员创建企业', color: 'cyan' },
|
||||
admin_update_org: { label: '管理员更新企业', color: 'cyan' },
|
||||
@@ -134,7 +127,7 @@ const detailKeyLabels = {
|
||||
allow_ips: 'IP白名单',
|
||||
group: '分组',
|
||||
max_members: '最大成员数',
|
||||
max_tokens: '最大令牌数',
|
||||
max_tokens: '最大密钥数',
|
||||
default_member_quota: '新成员默认额度上限',
|
||||
cycle_quota: '周期额度',
|
||||
cycle_quota_delta: '周期额度增量',
|
||||
@@ -289,10 +282,10 @@ const OrgAudit = ({ orgId }) => {
|
||||
{ value: 'update_member_status', label: t('更新状态') },
|
||||
{ value: 'update_member_model_limits', label: t('更新模型限制') },
|
||||
{ value: 'update_member_admin_permissions', label: t('更新管理员权限') },
|
||||
// 令牌操作
|
||||
{ value: 'create_token', label: t('创建令牌') },
|
||||
{ value: 'update_token', label: t('更新令牌') },
|
||||
{ value: 'delete_token', label: t('删除令牌') },
|
||||
// 密钥操作
|
||||
{ value: 'create_token', label: t('创建密钥') },
|
||||
{ value: 'update_token', label: t('更新密钥') },
|
||||
{ value: 'delete_token', label: t('删除密钥') },
|
||||
// 管理员操作
|
||||
{ value: 'admin_create_org', label: t('管理员创建企业') },
|
||||
{ value: 'admin_update_org', label: t('管理员更新企业') },
|
||||
@@ -301,24 +294,21 @@ const OrgAudit = ({ orgId }) => {
|
||||
{ value: 'admin_update_status', label: t('管理员更新状态') },
|
||||
];
|
||||
|
||||
// 列宽与渲染对齐原型 EnterpriseAudit(130/170/110/500/150,scroll.x 1140);标签为无边框 filled
|
||||
const columns = [
|
||||
{
|
||||
title: t('操作者'),
|
||||
dataIndex: 'operator_name',
|
||||
width: 120,
|
||||
render: (name, record) => (
|
||||
<span className='text-sm text-gray-700 dark:text-gray-300 truncate'>
|
||||
{name || `User#${record.operator_id}`}
|
||||
</span>
|
||||
),
|
||||
width: 130,
|
||||
render: (name, record) => name || `User#${record.operator_id}`,
|
||||
},
|
||||
{
|
||||
title: t('操作'),
|
||||
title: t('操作类型'),
|
||||
dataIndex: 'action',
|
||||
width: 170,
|
||||
render: (action, record) => {
|
||||
const config = actionConfig[action];
|
||||
if (!config) return <Tag size='small'>{action}</Tag>;
|
||||
if (!config) return <Tag bordered={false}>{action}</Tag>;
|
||||
// 建企业时配的初始额度复用 admin_adjust_quota(供预警取"加额时刻"),
|
||||
// 但它不是二次人工调额,按 detail.source 区分展示
|
||||
let label = config.label;
|
||||
@@ -333,7 +323,7 @@ const OrgAudit = ({ orgId }) => {
|
||||
}
|
||||
}
|
||||
return (
|
||||
<Tag size='small' color={config.color} type='light'>
|
||||
<Tag color={config.color} bordered={false}>
|
||||
{t(label)}
|
||||
</Tag>
|
||||
);
|
||||
@@ -342,9 +332,9 @@ const OrgAudit = ({ orgId }) => {
|
||||
{
|
||||
title: t('目标类型'),
|
||||
dataIndex: 'target_type',
|
||||
width: 90,
|
||||
width: 110,
|
||||
render: (type) => (
|
||||
<Tag size='small' color={targetTypeColors[type] || 'grey'} type='ghost'>
|
||||
<Tag color={targetTypeColors[type] || 'grey'} bordered={false}>
|
||||
{t(targetTypeLabels[type] || type)}
|
||||
</Tag>
|
||||
),
|
||||
@@ -352,49 +342,43 @@ const OrgAudit = ({ orgId }) => {
|
||||
{
|
||||
title: t('详情'),
|
||||
dataIndex: 'detail',
|
||||
width: 500,
|
||||
render: (detail, record) => {
|
||||
if (!detail)
|
||||
return <span className='text-gray-400 dark:text-gray-500'>-</span>;
|
||||
if (!detail) return <span className='oc-muted'>-</span>;
|
||||
let text = detail;
|
||||
try {
|
||||
const obj = JSON.parse(detail);
|
||||
const text = formatDetail(record.action, obj, t, quotaPerUnit);
|
||||
if (text.length > 60) {
|
||||
return (
|
||||
<Tooltip
|
||||
content={text}
|
||||
position='topLeft'
|
||||
style={{ maxWidth: 400 }}
|
||||
>
|
||||
<span className='text-xs text-gray-600 dark:text-gray-400 cursor-default truncate block max-w-xs'>
|
||||
{text}
|
||||
</span>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<span className='text-xs text-gray-600 dark:text-gray-400'>
|
||||
{text}
|
||||
</span>
|
||||
text = formatDetail(
|
||||
record.action,
|
||||
JSON.parse(detail),
|
||||
t,
|
||||
quotaPerUnit,
|
||||
);
|
||||
} catch {
|
||||
return (
|
||||
<span className='text-xs text-gray-600 dark:text-gray-400'>
|
||||
{detail}
|
||||
</span>
|
||||
);
|
||||
// detail 非 JSON 时原样展示
|
||||
}
|
||||
return (
|
||||
<Tooltip content={text} position='topLeft' style={{ maxWidth: 400 }}>
|
||||
<span className='oc-audit-detail' tabIndex={0}>
|
||||
{text}
|
||||
</span>
|
||||
</Tooltip>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: t('时间'),
|
||||
dataIndex: 'created_at',
|
||||
width: 140,
|
||||
width: 150,
|
||||
render: (v) =>
|
||||
v ? (
|
||||
<Tooltip content={new Date(v * 1000).toLocaleString('zh-CN')}>
|
||||
<span className='text-xs text-gray-500 dark:text-gray-400 cursor-default'>
|
||||
<time
|
||||
className='oc-audit-time'
|
||||
dateTime={new Date(v * 1000).toISOString()}
|
||||
tabIndex={0}
|
||||
>
|
||||
{formatRelativeTime(v, t)}
|
||||
</span>
|
||||
</time>
|
||||
</Tooltip>
|
||||
) : (
|
||||
'-'
|
||||
@@ -402,69 +386,101 @@ const OrgAudit = ({ orgId }) => {
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div className='uc-page'>
|
||||
<OrgPageHeader
|
||||
title={t('审计日志')}
|
||||
subtitle={t('查看企业操作记录')}
|
||||
actions={
|
||||
activeTab === 'operations' ? (
|
||||
<>
|
||||
<Button
|
||||
icon={<RefreshCw size={14} />}
|
||||
onClick={() => fetch(page, 20, actionFilter)}
|
||||
loading={loading}
|
||||
>
|
||||
{t('刷新')}
|
||||
</Button>
|
||||
<Select
|
||||
value={actionFilter}
|
||||
onChange={(v) => {
|
||||
setActionFilter(v);
|
||||
setPage(1);
|
||||
}}
|
||||
optionList={actionOptions}
|
||||
style={{ width: 200 }}
|
||||
placeholder={t('筛选操作')}
|
||||
filter
|
||||
/>
|
||||
</>
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
const refresh = () => fetch(page, 20, actionFilter);
|
||||
// 选择即筛选(原交互):与原页头 Select 的 onChange 相同
|
||||
const applyAction = (v) => {
|
||||
setActionFilter(v ?? '');
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
<Tabs
|
||||
type='line'
|
||||
const operations = (
|
||||
<>
|
||||
<OrgFilterCard
|
||||
className='oc-audit-filter'
|
||||
actions={
|
||||
<>
|
||||
{/* 重置 = 选择“全部操作”;搜索 = 以当前筛选重新查询(同“刷新”) */}
|
||||
<Button onClick={() => applyAction('')}>{t('重置')}</Button>
|
||||
<Button
|
||||
type='primary'
|
||||
icon={<Search size={16} />}
|
||||
onClick={refresh}
|
||||
>
|
||||
{t('搜索')}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<AntForm layout='vertical' requiredMark={false} component='div'>
|
||||
<AntForm.Item label={t('操作类型')}>
|
||||
<Select
|
||||
value={actionFilter}
|
||||
onChange={applyAction}
|
||||
optionList={actionOptions}
|
||||
style={{ width: '100%' }}
|
||||
placeholder={t('全部操作')}
|
||||
filter
|
||||
/>
|
||||
</AntForm.Item>
|
||||
</AntForm>
|
||||
</OrgFilterCard>
|
||||
|
||||
<OrgListCard
|
||||
title={t('操作记录')}
|
||||
tools={
|
||||
<Button
|
||||
icon={<RefreshCw size={16} />}
|
||||
onClick={refresh}
|
||||
loading={loading}
|
||||
>
|
||||
{t('刷新')}
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={logs}
|
||||
loading={loading}
|
||||
rowKey='id'
|
||||
scroll={{ x: 1140 }}
|
||||
pagination={{
|
||||
currentPage: page,
|
||||
pageSize: 20,
|
||||
showSizeChanger: false,
|
||||
total,
|
||||
onPageChange: setPage,
|
||||
showTotal: (n) => t('共 {{total}} 条', { total: n }),
|
||||
}}
|
||||
empty={<OrgStateBlock icon={ScrollText} title={t('暂无审计日志')} />}
|
||||
/>
|
||||
</OrgListCard>
|
||||
</>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className='uc-page oc-page'>
|
||||
<OrgPageHeader title={t('审计日志')} subtitle={t('查看企业操作记录')} />
|
||||
|
||||
{/* 原型 platform-list-tabs;“提示词记录”页签沿用原 feature flag + 权限显隐 */}
|
||||
<AntTabs
|
||||
className='oc-list-tabs'
|
||||
activeKey={activeTab}
|
||||
onChange={setActiveTab}
|
||||
className='mt-2'
|
||||
>
|
||||
<TabPane tab={t('操作审计')} itemKey='operations'>
|
||||
<OrgPanel bodyClassName='overflow-x-auto' className='mt-4'>
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={logs}
|
||||
loading={loading}
|
||||
rowKey='id'
|
||||
pagination={{
|
||||
currentPage: page,
|
||||
pageSize: 20,
|
||||
total,
|
||||
onPageChange: setPage,
|
||||
}}
|
||||
empty={
|
||||
<OrgStateBlock icon={ScrollText} title={t('暂无审计日志')} />
|
||||
}
|
||||
/>
|
||||
</OrgPanel>
|
||||
</TabPane>
|
||||
|
||||
{promptArchiveEnabled && canViewPromptRecords && (
|
||||
<TabPane tab={t('提示词记录')} itemKey='prompt-records'>
|
||||
<OrgPromptRecords key={orgId} orgId={orgId} />
|
||||
</TabPane>
|
||||
)}
|
||||
</Tabs>
|
||||
items={[
|
||||
{ key: 'operations', label: t('操作审计'), children: operations },
|
||||
...(promptArchiveEnabled && canViewPromptRecords
|
||||
? [
|
||||
{
|
||||
key: 'prompt-records',
|
||||
label: t('提示词记录'),
|
||||
// 原 Tabs 预渲染全部页签(lazyRender=false),保持提示词记录随页面挂载、请求时机不变
|
||||
forceRender: true,
|
||||
children: <OrgPromptRecords key={orgId} orgId={orgId} />,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -16,8 +16,15 @@ 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 React, {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Switch } from 'antd';
|
||||
import {
|
||||
Table,
|
||||
Button,
|
||||
@@ -25,10 +32,9 @@ import {
|
||||
Toast,
|
||||
Tag,
|
||||
Progress,
|
||||
Banner,
|
||||
Popconfirm,
|
||||
} from '@/components/ui';
|
||||
import { RefreshCw, Plus, Pencil, Trash2 } from 'lucide-react';
|
||||
import { RefreshCw, Plus } from 'lucide-react';
|
||||
import { API } from '../../helpers/api';
|
||||
import { showError } from '../../helpers';
|
||||
import {
|
||||
@@ -38,7 +44,7 @@ import {
|
||||
getQuotaInputUnit,
|
||||
} from '../../helpers/render';
|
||||
import OrgPageHeader from './components/OrgPageHeader';
|
||||
import OrgPanel from './components/OrgPanel';
|
||||
import { OrgListCard, OrgRowActions } from './components/OrgListCard';
|
||||
import OrgModal from './components/OrgModal';
|
||||
|
||||
const getOrgHeaders = (orgId) => ({ 'X-Org-Id': String(orgId) });
|
||||
@@ -48,7 +54,7 @@ const subjectTypeLabel = (t, st) =>
|
||||
department: t('部门'),
|
||||
project: t('项目'),
|
||||
member: t('成员'),
|
||||
token: t('令牌'),
|
||||
token: t('密钥'),
|
||||
org: t('企业'),
|
||||
})[st] || st;
|
||||
|
||||
@@ -65,11 +71,9 @@ const cycleLabel = (t, c) =>
|
||||
const OrgBudgets = ({ orgId }) => {
|
||||
const { t } = useTranslation();
|
||||
const [list, setList] = useState([]);
|
||||
// null=未知(接口未返回该字段的旧后端),true/false=预算 cap 是否真正在扣费链路生效
|
||||
const [enforcementEnabled, setEnforcementEnabled] = useState(null);
|
||||
// 未生效的细分原因:平台级引擎急停(engine=false) vs 企业未开「预算实时拦截」
|
||||
const [engineEnabled, setEngineEnabled] = useState(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [updatingBudgetId, setUpdatingBudgetId] = useState(null);
|
||||
const updatingBudgetRef = useRef(false);
|
||||
const [depts, setDepts] = useState([]);
|
||||
const [projects, setProjects] = useState([]);
|
||||
const [modalVisible, setModalVisible] = useState(false);
|
||||
@@ -96,29 +100,17 @@ const OrgBudgets = ({ orgId }) => {
|
||||
API.get('/api/org/project', { headers: getOrgHeaders(orgId) }),
|
||||
]);
|
||||
if (b.data.success) {
|
||||
// 新后端返回 {items, enforcement_enabled, engine_enabled};兼容旧后端直接返回数组
|
||||
// 新后端返回 {items, enforcement_enabled, engine_enabled};兼容旧后端直接返回数组。
|
||||
// enforcement/engine 两个字段原只驱动表格上方旧提示栏,提示栏按原型移除后不再读取。
|
||||
const payload = b.data.data;
|
||||
if (Array.isArray(payload)) {
|
||||
setList(payload || []);
|
||||
setEnforcementEnabled(null);
|
||||
setEngineEnabled(null);
|
||||
} else {
|
||||
setList(payload?.items || []);
|
||||
setEnforcementEnabled(payload?.enforcement_enabled ?? null);
|
||||
setEngineEnabled(payload?.engine_enabled ?? null);
|
||||
}
|
||||
setList(Array.isArray(payload) ? payload || [] : payload?.items || []);
|
||||
} else {
|
||||
showError(b.data.message);
|
||||
// 拉取失败回到「未知」,避免 Banner 停留在陈旧状态
|
||||
setEnforcementEnabled(null);
|
||||
setEngineEnabled(null);
|
||||
}
|
||||
if (d.data.success) setDepts(d.data.data || []);
|
||||
if (p.data.success) setProjects(p.data.data || []);
|
||||
} catch (err) {
|
||||
showError(err.message);
|
||||
setEnforcementEnabled(null);
|
||||
setEngineEnabled(null);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -128,7 +120,7 @@ const OrgBudgets = ({ orgId }) => {
|
||||
fetchAll();
|
||||
}, [fetchAll]);
|
||||
|
||||
// 主体名称与存在性优先取后端 subject_* 字段(覆盖成员/令牌,且能区分「已删除」与「已停用」);
|
||||
// 主体名称与存在性优先取后端 subject_* 字段(覆盖成员/密钥,且能区分「已删除」与「已停用」);
|
||||
// 旧后端未返回时回落到本地部门/项目列表匹配。
|
||||
const subjectOf = useCallback(
|
||||
(r) => {
|
||||
@@ -156,7 +148,7 @@ const OrgBudgets = ({ orgId }) => {
|
||||
disabled: p?.status === 2,
|
||||
};
|
||||
}
|
||||
// 旧后端下成员/令牌无从解析,按存在处理,避免误标「已删除」
|
||||
// 旧后端下成员/密钥无从解析,按存在处理,避免误标「已删除」
|
||||
return { name: `#${r.subject_id}`, exists: true, disabled: false };
|
||||
},
|
||||
[depts, projects],
|
||||
@@ -252,6 +244,52 @@ const OrgBudgets = ({ orgId }) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleStatusChange = async (record, enabled) => {
|
||||
if (
|
||||
updatingBudgetRef.current ||
|
||||
(record.status === 1) === enabled ||
|
||||
!subjectOf(record).exists
|
||||
)
|
||||
return;
|
||||
updatingBudgetRef.current = true;
|
||||
setUpdatingBudgetId(record.id);
|
||||
try {
|
||||
// Reuse the edit upsert contract with raw quotas, without currency conversion.
|
||||
const res = await API.put(
|
||||
'/api/org/budget',
|
||||
{
|
||||
subject_type: record.subject_type,
|
||||
subject_id: record.subject_id,
|
||||
cycle_type: record.cycle_type,
|
||||
cycle_quota: record.cycle_quota,
|
||||
total_quota: record.total_quota,
|
||||
custom_cycle_days: record.custom_cycle_days || 0,
|
||||
over_limit_action: record.over_limit_action,
|
||||
status: enabled ? 1 : 2,
|
||||
},
|
||||
{ headers: getOrgHeaders(orgId), skipErrorHandler: true },
|
||||
);
|
||||
if (res.data.success) {
|
||||
Toast.success({
|
||||
content: t('状态已更新'),
|
||||
key: `org-budget-status-${orgId}-${record.id}`,
|
||||
});
|
||||
setList((items) =>
|
||||
items.map((item) =>
|
||||
item.id === record.id ? { ...item, status: enabled ? 1 : 2 } : item,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
showError(res.data.message);
|
||||
}
|
||||
} catch (err) {
|
||||
showError(err.message);
|
||||
} finally {
|
||||
updatingBudgetRef.current = false;
|
||||
setUpdatingBudgetId(null);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async (record) => {
|
||||
try {
|
||||
const res = await API.delete(`/api/org/budget/${record.id}`, {
|
||||
@@ -268,30 +306,32 @@ const OrgBudgets = ({ orgId }) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 列宽与渲染对齐原型 EnterpriseBudget(300/110/260/120/120/130,scroll.x 1040);取值与判定沿用原逻辑
|
||||
const columns = [
|
||||
{
|
||||
title: t('主体'),
|
||||
width: 300,
|
||||
render: (_, r) => {
|
||||
const subj = subjectOf(r);
|
||||
return (
|
||||
<span>
|
||||
<Tag color='blue' size='small'>
|
||||
<div className='oc-budget-subject'>
|
||||
<Tag color='gold' bordered={false}>
|
||||
{subjectTypeLabel(t, r.subject_type)}
|
||||
</Tag>{' '}
|
||||
<span className={subj.exists ? '' : 'text-gray-400 line-through'}>
|
||||
</Tag>
|
||||
<span className={subj.exists ? '' : 'oc-muted line-through'}>
|
||||
{subj.name}
|
||||
</span>{' '}
|
||||
</span>
|
||||
{!subj.exists && (
|
||||
<Tag color='red' size='small'>
|
||||
<Tag color='red' bordered={false}>
|
||||
{t('主体已删除')}
|
||||
</Tag>
|
||||
)}
|
||||
{subj.exists && subj.disabled && (
|
||||
<Tag color='grey' size='small'>
|
||||
<Tag color='grey' bordered={false}>
|
||||
{t('已停用')}
|
||||
</Tag>
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -299,31 +339,32 @@ const OrgBudgets = ({ orgId }) => {
|
||||
title: t('周期'),
|
||||
dataIndex: 'cycle_type',
|
||||
render: (v) => cycleLabel(t, v),
|
||||
width: 90,
|
||||
width: 110,
|
||||
},
|
||||
{
|
||||
title: t('周期用量 / cap'),
|
||||
width: 220,
|
||||
title: t('周期用量 / 上限'),
|
||||
width: 260,
|
||||
render: (_, r) => {
|
||||
if (!r.cycle_quota)
|
||||
return <span className='text-xs text-gray-400'>{t('不限')}</span>;
|
||||
return <span className='oc-budget-unlimited'>{t('不限')}</span>;
|
||||
const pct = Math.min(
|
||||
100,
|
||||
Math.round((r.used_in_cycle / r.cycle_quota) * 100),
|
||||
);
|
||||
return (
|
||||
<div>
|
||||
<div className='oc-budget-usage'>
|
||||
<Progress
|
||||
percent={pct}
|
||||
size='small'
|
||||
showInfo={false}
|
||||
stroke={pct >= 90 ? 'var(--ui-color-danger)' : undefined}
|
||||
/>
|
||||
<span className='text-xs text-gray-500'>
|
||||
<span>
|
||||
{renderQuota(r.used_in_cycle, 2)}
|
||||
{r.reserved_in_cycle > 0
|
||||
? ` (+${renderQuota(r.reserved_in_cycle, 2)} ${t('预留')})`
|
||||
: ''}
|
||||
{' / '}
|
||||
<i>/</i>
|
||||
{renderQuota(r.cycle_quota, 2)}
|
||||
</span>
|
||||
</div>
|
||||
@@ -333,36 +374,37 @@ const OrgBudgets = ({ orgId }) => {
|
||||
{
|
||||
title: t('超限动作'),
|
||||
dataIndex: 'over_limit_action',
|
||||
// 90px 是按中文两字标签定的,泰语最短的地道说法 "เมื่อเกินขีดจำกัด" 也要 ~150px;
|
||||
// 这一列没有更短的译法,只能让列让位(其余列头已在 kt_overrides_th.json 收敛用词)
|
||||
width: 150,
|
||||
// 原型 120px;表头 nowrap,较长译文(如泰语)由表格自动撑开列宽,不截断
|
||||
width: 120,
|
||||
render: () => t('拦截'),
|
||||
},
|
||||
{
|
||||
title: t('状态'),
|
||||
dataIndex: 'status',
|
||||
width: 80,
|
||||
render: (v) => (
|
||||
<Tag color={v === 1 ? 'green' : 'grey'}>
|
||||
{v === 1 ? t('启用') : t('停用')}
|
||||
</Tag>
|
||||
width: 120,
|
||||
render: (v, record) => (
|
||||
<Switch
|
||||
size='small'
|
||||
checked={v === 1}
|
||||
checkedChildren={t('启用')}
|
||||
unCheckedChildren={t('禁用')}
|
||||
aria-label={`${subjectOf(record).name} ${t('状态')}`}
|
||||
loading={updatingBudgetId === record.id}
|
||||
disabled={updatingBudgetId !== null || !subjectOf(record).exists}
|
||||
onChange={(checked) => handleStatusChange(record, checked)}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('操作'),
|
||||
width: 160,
|
||||
width: 130,
|
||||
render: (_, r) => {
|
||||
const subj = subjectOf(r);
|
||||
return (
|
||||
<div className='flex gap-1'>
|
||||
<OrgRowActions>
|
||||
{/* 主体已删除的孤儿行改不了(后端 upsert 会因主体不存在报错),只留删除 */}
|
||||
{subj.exists && (
|
||||
<Button
|
||||
size='small'
|
||||
theme='light'
|
||||
icon={<Pencil size={14} />}
|
||||
onClick={() => openEdit(r)}
|
||||
>
|
||||
<Button type='link' onClick={() => openEdit(r)}>
|
||||
{t('编辑')}
|
||||
</Button>
|
||||
)}
|
||||
@@ -373,31 +415,36 @@ const OrgBudgets = ({ orgId }) => {
|
||||
)}
|
||||
onConfirm={() => handleDelete(r)}
|
||||
>
|
||||
<Button
|
||||
size='small'
|
||||
theme='light'
|
||||
type='danger'
|
||||
icon={<Trash2 size={14} />}
|
||||
>
|
||||
<Button type='link' danger>
|
||||
{t('删除')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</div>
|
||||
</OrgRowActions>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div className='uc-page'>
|
||||
<div className='uc-page oc-page'>
|
||||
<OrgPageHeader
|
||||
title={t('预算中心')}
|
||||
subtitle={t('部门 / 项目 / 成员的额度上限')}
|
||||
actions={
|
||||
subtitle={t('管理部门、项目与成员的额度上限')}
|
||||
/>
|
||||
|
||||
{/* 原型 .eb-policy 说明条:替换原“预算实时拦截未生效”警告与 cap 说明两条 Banner */}
|
||||
<div className='oc-policy' role='note'>
|
||||
{t(
|
||||
'预算只设置「最多能花多少」的上限,不增加企业真实额度池;提额仅提高上限。',
|
||||
)}
|
||||
</div>
|
||||
|
||||
<OrgListCard
|
||||
title={t('预算列表')}
|
||||
tools={
|
||||
<>
|
||||
<Button
|
||||
theme='light'
|
||||
icon={<RefreshCw size={14} />}
|
||||
icon={<RefreshCw size={16} />}
|
||||
loading={loading}
|
||||
onClick={fetchAll}
|
||||
>
|
||||
@@ -405,51 +452,27 @@ const OrgBudgets = ({ orgId }) => {
|
||||
</Button>
|
||||
<Button
|
||||
theme='solid'
|
||||
icon={<Plus size={14} />}
|
||||
icon={<Plus size={16} />}
|
||||
onClick={openCreate}
|
||||
>
|
||||
{t('配置预算')}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
|
||||
{enforcementEnabled === false && (
|
||||
<Banner
|
||||
type='warning'
|
||||
closeIcon={null}
|
||||
description={
|
||||
engineEnabled === false
|
||||
? t(
|
||||
'预算引擎已被平台全局急停:所有企业的预算拦截与用量统计均暂停,恢复需平台管理员开启系统开关,与本企业配置无关。',
|
||||
)
|
||||
: t(
|
||||
'预算实时拦截当前未生效:这里的配置只会被保存,不会拦截超额调用,也不会累计用量统计。请联系平台管理员开启本企业的「预算实时拦截」功能。',
|
||||
)
|
||||
}
|
||||
className='mb-4'
|
||||
/>
|
||||
)}
|
||||
<Banner
|
||||
type='info'
|
||||
closeIcon={null}
|
||||
description={t(
|
||||
'预算只设置「最多能花多少」的上限(cap),不增加企业真实额度池;提额仅提高上限。',
|
||||
)}
|
||||
className='mb-4'
|
||||
/>
|
||||
|
||||
<OrgPanel padding='p-2'>
|
||||
>
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={list}
|
||||
loading={loading}
|
||||
pagination={false}
|
||||
rowKey='id'
|
||||
scroll={{ x: 1040 }}
|
||||
/>
|
||||
</OrgPanel>
|
||||
</OrgListCard>
|
||||
|
||||
<OrgModal
|
||||
className='oc-dialog oc-budget-dialog'
|
||||
width={560}
|
||||
title={editing ? t('编辑预算') : t('配置预算')}
|
||||
visible={modalVisible}
|
||||
onOk={submit}
|
||||
@@ -459,11 +482,11 @@ const OrgBudgets = ({ orgId }) => {
|
||||
>
|
||||
<Form getFormApi={setFormApi}>
|
||||
{editing ? (
|
||||
<div className='mb-3'>
|
||||
<Tag color='blue' size='small'>
|
||||
<div className='oc-budget-edit-subject'>
|
||||
<Tag color='gold' bordered={false}>
|
||||
{subjectTypeLabel(t, editing.subject_type)}
|
||||
</Tag>{' '}
|
||||
{subjectOf(editing).name}
|
||||
</Tag>
|
||||
<strong>{subjectOf(editing).name}</strong>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
|
||||
@@ -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>
|
||||
)}
|
||||
|
||||
{/* 成员用量明细抽屉 */}
|
||||
|
||||
@@ -242,7 +242,7 @@ const OrgDepartments = ({ orgId }) => {
|
||||
<div className='uc-page'>
|
||||
<OrgPageHeader
|
||||
icon={Network}
|
||||
title={t('部门管理')}
|
||||
title={t('组织架构')}
|
||||
subtitle={t('组织架构与部门预算')}
|
||||
actions={
|
||||
<>
|
||||
|
||||
+222
-263
@@ -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
|
||||
|
||||
@@ -33,13 +33,13 @@ import {
|
||||
RefreshCw,
|
||||
UserPlus,
|
||||
Upload as UploadIcon,
|
||||
KeyRound,
|
||||
IdCard,
|
||||
} from 'lucide-react';
|
||||
import { API } from '../../helpers/api';
|
||||
import { showError, collectPagedItems } from '../../helpers';
|
||||
import OrgPageHeader from './components/OrgPageHeader';
|
||||
import OrgPanel from './components/OrgPanel';
|
||||
import { OrgListCard, OrgRowActions } from './components/OrgListCard';
|
||||
import OrgModal from './components/OrgModal';
|
||||
import DeptTreeSelect from './components/DeptTreeSelect';
|
||||
import {
|
||||
@@ -383,16 +383,15 @@ const OrgMemberAccounts = ({
|
||||
},
|
||||
{
|
||||
title: t('操作'),
|
||||
width: 300,
|
||||
width: 260,
|
||||
render: (_, r) => {
|
||||
const managed = r.created_by_org_id === r.organization_id;
|
||||
const canReset = managed || isSuperAdmin;
|
||||
return (
|
||||
<div className='flex items-center gap-2'>
|
||||
<OrgRowActions>
|
||||
{deptEnabled && (
|
||||
<Button
|
||||
size='small'
|
||||
theme='light'
|
||||
type='link'
|
||||
onClick={() => {
|
||||
setDeptAssignFor(r);
|
||||
setDeptAssignVal(r.department_id || 0);
|
||||
@@ -413,22 +412,11 @@ const OrgMemberAccounts = ({
|
||||
}
|
||||
onConfirm={() => resetPassword(r)}
|
||||
>
|
||||
<Button
|
||||
size='small'
|
||||
theme='light'
|
||||
icon={<KeyRound size={14} />}
|
||||
>
|
||||
{t('重置密码')}
|
||||
</Button>
|
||||
<Button type='link'>{t('重置密码')}</Button>
|
||||
</Popconfirm>
|
||||
) : (
|
||||
<Tooltip content={t('个人平台账号,请由本人通过找回密码修改')}>
|
||||
<Button
|
||||
size='small'
|
||||
theme='light'
|
||||
disabled
|
||||
icon={<KeyRound size={14} />}
|
||||
>
|
||||
<Button type='link' disabled>
|
||||
{t('重置密码')}
|
||||
</Button>
|
||||
</Tooltip>
|
||||
@@ -441,25 +429,32 @@ const OrgMemberAccounts = ({
|
||||
)}
|
||||
onConfirm={() => offboard(r.id)}
|
||||
>
|
||||
<Button size='small' theme='light' type='danger'>
|
||||
<Button type='link' danger>
|
||||
{t('离职回收')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
)}
|
||||
</div>
|
||||
</OrgRowActions>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// 原型员工列表工具区:刷新 / 新建员工(主按钮)/ CSV 导入;回调不变
|
||||
const actions = (
|
||||
<>
|
||||
<Button theme='light' icon={<RefreshCw size={14} />} onClick={fetchAll}>
|
||||
<Button icon={<RefreshCw size={16} />} onClick={fetchAll}>
|
||||
{t('刷新')}
|
||||
</Button>
|
||||
<Button
|
||||
theme='light'
|
||||
icon={<UploadIcon size={14} />}
|
||||
theme='solid'
|
||||
icon={<UserPlus size={16} />}
|
||||
onClick={() => setCreateVisible(true)}
|
||||
>
|
||||
{t('创建员工账号')}
|
||||
</Button>
|
||||
<Button
|
||||
icon={<UploadIcon size={16} />}
|
||||
onClick={() => {
|
||||
setImportResult(null);
|
||||
setImportFile(null);
|
||||
@@ -468,38 +463,12 @@ const OrgMemberAccounts = ({
|
||||
>
|
||||
{t('CSV 导入')}
|
||||
</Button>
|
||||
<Button
|
||||
theme='solid'
|
||||
icon={<UserPlus size={14} />}
|
||||
onClick={() => setCreateVisible(true)}
|
||||
>
|
||||
{t('创建员工账号')}
|
||||
</Button>
|
||||
</>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={embedded ? 'space-y-4' : 'uc-page'}>
|
||||
{embedded ? (
|
||||
<div className='flex items-start justify-between gap-3 flex-wrap rounded-2xl border border-dashed border-brand/25 bg-brand/5 p-4 dark:border-brand/25 dark:bg-brand/10'>
|
||||
<div className='flex items-start gap-3'>
|
||||
<span className='inline-flex h-10 w-10 items-center justify-center rounded-2xl bg-white text-brand-deep shadow-sm dark:bg-white/10 dark:text-brand-from'>
|
||||
<IdCard size={18} />
|
||||
</span>
|
||||
<div>
|
||||
<div className='font-semibold text-gray-950 dark:text-white'>
|
||||
{t('员工账号')}
|
||||
</div>
|
||||
<Text type='tertiary' size='small'>
|
||||
{t('集中管理员工登录、批量导入、重置密码与离职回收')}
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
<div className='flex items-center gap-2 flex-wrap justify-end'>
|
||||
{actions}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className={embedded ? 'oc-member-accounts' : 'uc-page'}>
|
||||
{!embedded && (
|
||||
<OrgPageHeader
|
||||
icon={IdCard}
|
||||
title={t('员工账号')}
|
||||
@@ -518,15 +487,31 @@ const OrgMemberAccounts = ({
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
<OrgPanel padding='p-2'>
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={members}
|
||||
loading={loading}
|
||||
pagination={{ pageSize: 15, showSizeChanger: false }}
|
||||
rowKey='id'
|
||||
/>
|
||||
</OrgPanel>
|
||||
{embedded ? (
|
||||
<OrgListCard title={t('员工账号')} tools={actions}>
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={members}
|
||||
loading={loading}
|
||||
pagination={{
|
||||
pageSize: 15,
|
||||
showSizeChanger: false,
|
||||
showTotal: (n) => t('共 {{total}} 条', { total: n }),
|
||||
}}
|
||||
rowKey='id'
|
||||
/>
|
||||
</OrgListCard>
|
||||
) : (
|
||||
<OrgPanel padding='p-2'>
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={members}
|
||||
loading={loading}
|
||||
pagination={{ pageSize: 15, showSizeChanger: false }}
|
||||
rowKey='id'
|
||||
/>
|
||||
</OrgPanel>
|
||||
)}
|
||||
|
||||
{/* 创建账号 */}
|
||||
<OrgModal
|
||||
|
||||
@@ -18,17 +18,7 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React, { useEffect, useState, useCallback, useRef } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Users,
|
||||
Trash2,
|
||||
Settings,
|
||||
Ban,
|
||||
CheckCircle,
|
||||
RefreshCw,
|
||||
Layers,
|
||||
Pencil,
|
||||
ShieldCheck,
|
||||
} from 'lucide-react';
|
||||
import { Users, RefreshCw, Layers, Pencil, ShieldCheck } from 'lucide-react';
|
||||
import {
|
||||
Table,
|
||||
Button,
|
||||
@@ -38,8 +28,6 @@ import {
|
||||
Popconfirm,
|
||||
Toast,
|
||||
Tooltip,
|
||||
Tabs,
|
||||
TabPane,
|
||||
Switch,
|
||||
} from '@/components/ui';
|
||||
import { useOrgMembers } from '../../hooks/org/useOrgMembers';
|
||||
@@ -48,6 +36,8 @@ import { renderQuota } from '../../helpers/render';
|
||||
import QuotaInput from '../../components/common/ui/QuotaInput';
|
||||
import OrgPageHeader from './components/OrgPageHeader';
|
||||
import OrgPanel from './components/OrgPanel';
|
||||
import { Alert as AntAlert, Tabs as AntTabs } from 'antd';
|
||||
import { OrgListCard, OrgRowActions } from './components/OrgListCard';
|
||||
import OrgModal from './components/OrgModal';
|
||||
import OrgMemberAccounts from './OrgMemberAccounts';
|
||||
|
||||
@@ -323,116 +313,100 @@ const OrgMembers = ({
|
||||
[editingRemarkValue, updateMemberRemark, updateMemberInList, t],
|
||||
);
|
||||
|
||||
// 格式化加入时间
|
||||
// 格式化加入时间:原型显示绝对日期 YYYY/MM/DD(同一时间戳,仅格式化方式变化)
|
||||
const formatJoinTime = (timestamp) => {
|
||||
if (!timestamp) return '-';
|
||||
const date = new Date(timestamp * 1000);
|
||||
const now = new Date();
|
||||
const diffMs = now - date;
|
||||
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
|
||||
|
||||
if (diffDays === 0) return t('今天');
|
||||
if (diffDays === 1) return t('昨天');
|
||||
if (diffDays < 30) return `${diffDays} ${t('天前')}`;
|
||||
|
||||
return date.toLocaleDateString('zh-CN', {
|
||||
return new Date(timestamp * 1000).toLocaleDateString('zh-CN', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
});
|
||||
};
|
||||
|
||||
// 列与渲染对齐原型 EnterpriseEmployees:首列 / 操作列固定,状态用 Switch(onChange 走原 handleStatusChange),
|
||||
// 备注独立成列(沿用原就地编辑交互),操作为 link 按钮
|
||||
const renderRemark = (record) => {
|
||||
const isEditingRemark = editingRemarkId === record.id;
|
||||
if (canWrite && isEditingRemark) {
|
||||
return (
|
||||
<Input
|
||||
size='small'
|
||||
value={editingRemarkValue}
|
||||
onChange={setEditingRemarkValue}
|
||||
placeholder={t('Enter 保存,Esc 取消')}
|
||||
maxLength={100}
|
||||
autoFocus
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
handleRemarkSave(record.id);
|
||||
}
|
||||
if (e.key === 'Escape') {
|
||||
editingRemarkIdRef.current = null;
|
||||
setEditingRemarkId(null);
|
||||
}
|
||||
}}
|
||||
onBlur={() => handleRemarkSave(record.id)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
if (canWrite) {
|
||||
return (
|
||||
<Tooltip
|
||||
content={record.remark ? t('点击编辑备注') : t('点击添加备注')}
|
||||
>
|
||||
<button
|
||||
type='button'
|
||||
className='oc-member-remark'
|
||||
onClick={() => {
|
||||
const current = record.remark || '';
|
||||
editingRemarkIdRef.current = record.id;
|
||||
originalRemarkRef.current = current;
|
||||
setEditingRemarkId(record.id);
|
||||
setEditingRemarkValue(current);
|
||||
}}
|
||||
>
|
||||
{record.remark ? (
|
||||
<span>{record.remark}</span>
|
||||
) : (
|
||||
<span className='oc-muted'>{t('添加备注')}</span>
|
||||
)}
|
||||
<Pencil size={12} aria-hidden />
|
||||
</button>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
return record.remark || '-';
|
||||
};
|
||||
|
||||
const memberColumns = [
|
||||
{
|
||||
title: t('用户'),
|
||||
dataIndex: 'display_name',
|
||||
width: 240,
|
||||
render: (text, record) => {
|
||||
const isEditingRemark = editingRemarkId === record.id;
|
||||
return (
|
||||
<div className='flex items-center gap-2.5'>
|
||||
<div className='flex-shrink-0 w-8 h-8 rounded-full bg-gradient-to-br from-brand-from to-brand-to flex items-center justify-center text-white text-xs font-bold'>
|
||||
{(text || record.username || '?').charAt(0).toUpperCase()}
|
||||
</div>
|
||||
<div className='min-w-0 flex-1'>
|
||||
<div className='font-medium text-gray-900 dark:text-white truncate'>
|
||||
{text || record.username}
|
||||
</div>
|
||||
<div className='text-xs text-gray-500 dark:text-gray-400 truncate'>
|
||||
{record.email}
|
||||
</div>
|
||||
{/* 备注区域 */}
|
||||
{canWrite && isEditingRemark ? (
|
||||
<Input
|
||||
size='small'
|
||||
value={editingRemarkValue}
|
||||
onChange={setEditingRemarkValue}
|
||||
placeholder={t('Enter 保存,Esc 取消')}
|
||||
maxLength={100}
|
||||
autoFocus
|
||||
style={{ marginTop: 4 }}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
handleRemarkSave(record.id);
|
||||
}
|
||||
if (e.key === 'Escape') {
|
||||
editingRemarkIdRef.current = null;
|
||||
setEditingRemarkId(null);
|
||||
}
|
||||
}}
|
||||
onBlur={() => handleRemarkSave(record.id)}
|
||||
/>
|
||||
) : canWrite ? (
|
||||
<Tooltip
|
||||
content={
|
||||
record.remark ? t('点击编辑备注') : t('点击添加备注')
|
||||
}
|
||||
>
|
||||
<div
|
||||
className='flex items-center gap-1 mt-0.5 cursor-pointer'
|
||||
onClick={() => {
|
||||
const current = record.remark || '';
|
||||
editingRemarkIdRef.current = record.id;
|
||||
originalRemarkRef.current = current;
|
||||
setEditingRemarkId(record.id);
|
||||
setEditingRemarkValue(current);
|
||||
}}
|
||||
>
|
||||
<Pencil
|
||||
size={10}
|
||||
className='text-gray-300 dark:text-gray-500 flex-shrink-0'
|
||||
/>
|
||||
{record.remark ? (
|
||||
<span className='text-xs text-amber-600 dark:text-amber-400 truncate max-w-[160px]'>
|
||||
{record.remark}
|
||||
</span>
|
||||
) : (
|
||||
<span className='text-xs text-gray-300 dark:text-gray-500 italic'>
|
||||
{t('添加备注')}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</Tooltip>
|
||||
) : record.remark ? (
|
||||
<div className='text-xs text-amber-600 dark:text-amber-400 truncate mt-0.5'>
|
||||
{record.remark}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
width: 180,
|
||||
fixed: 'left',
|
||||
render: (text, record) => (
|
||||
<div className='oc-member-identity'>
|
||||
<strong>{text || record.username}</strong>
|
||||
{record.email && <span>{record.email}</span>}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('角色'),
|
||||
dataIndex: 'role',
|
||||
width: 110,
|
||||
width: 150,
|
||||
render: (role, record) => {
|
||||
if (role === 'owner') return <Tag color='red'>{t('所有者')}</Tag>;
|
||||
if (role === 'owner')
|
||||
return (
|
||||
<Tag color='blue' bordered={false}>
|
||||
{t('所有者')}
|
||||
</Tag>
|
||||
);
|
||||
if (!canWrite) {
|
||||
return (
|
||||
<Tag
|
||||
bordered={false}
|
||||
color={
|
||||
role === 'admin'
|
||||
? 'blue'
|
||||
@@ -454,7 +428,7 @@ const OrgMembers = ({
|
||||
size='small'
|
||||
value={role}
|
||||
onChange={(v) => handleRoleChange(record.id, v)}
|
||||
style={{ width: 100 }}
|
||||
style={{ width: 120 }}
|
||||
>
|
||||
<Select.Option value='admin'>{t('Admin')}</Select.Option>
|
||||
<Select.Option value='dept_admin'>{t('Dept Admin')}</Select.Option>
|
||||
@@ -466,24 +440,18 @@ const OrgMembers = ({
|
||||
{
|
||||
title: t('已用额度'),
|
||||
dataIndex: 'used_quota',
|
||||
width: 100,
|
||||
render: (v) => (
|
||||
<span className='text-gray-700 dark:text-gray-300'>
|
||||
{renderQuota(v, 2)}
|
||||
</span>
|
||||
),
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: (v) => <span className='oc-number'>{renderQuota(v, 2)}</span>,
|
||||
},
|
||||
{
|
||||
title: t('额度上限'),
|
||||
dataIndex: 'quota_limit',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: (v, record) => {
|
||||
if (!(v > 0)) {
|
||||
return (
|
||||
<span className='text-gray-400 dark:text-gray-500'>
|
||||
{t('不限')}
|
||||
</span>
|
||||
);
|
||||
return <span className='oc-number'>{t('不限')}</span>;
|
||||
}
|
||||
const periodic = ['daily', 'weekly', 'monthly'].includes(
|
||||
record.quota_period,
|
||||
@@ -497,15 +465,11 @@ const OrgMembers = ({
|
||||
? t('每月')
|
||||
: t('终身·不重置');
|
||||
return (
|
||||
<div>
|
||||
<div className='text-gray-700 dark:text-gray-300'>
|
||||
{renderQuota(v, 2)}
|
||||
</div>
|
||||
<div
|
||||
className={`text-[11px] ${periodic ? 'text-gray-400 dark:text-gray-500' : 'text-amber-500'}`}
|
||||
>
|
||||
<div className='oc-member-limit'>
|
||||
<span className='oc-number'>{renderQuota(v, 2)}</span>
|
||||
<small className={periodic ? '' : 'is-lifetime'}>
|
||||
{periodLabel}
|
||||
</div>
|
||||
</small>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
@@ -513,38 +477,27 @@ const OrgMembers = ({
|
||||
{
|
||||
title: t('模型限制'),
|
||||
dataIndex: 'model_limits_enabled',
|
||||
width: 90,
|
||||
render: (enabled, record) => (
|
||||
<span
|
||||
className={
|
||||
enabled
|
||||
? 'text-brand-deep dark:text-brand-from text-xs'
|
||||
: 'text-gray-400 dark:text-gray-500 text-xs'
|
||||
}
|
||||
>
|
||||
{enabled
|
||||
? `${record.model_limits.split(',').filter(Boolean).length} ${t('个模型')}`
|
||||
: t('不限')}
|
||||
</span>
|
||||
),
|
||||
width: 110,
|
||||
render: (enabled, record) =>
|
||||
enabled ? (
|
||||
`${record.model_limits.split(',').filter(Boolean).length} ${t('个模型')}`
|
||||
) : (
|
||||
<span className='oc-muted'>{t('不限')}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('分组'),
|
||||
dataIndex: 'groups',
|
||||
width: 120,
|
||||
width: 175,
|
||||
render: (_, record) => {
|
||||
const groups = parseMemberGroups(record);
|
||||
if (!groups.length) {
|
||||
return (
|
||||
<span className='text-xs text-gray-400 dark:text-gray-500'>
|
||||
{t('继承企业')}
|
||||
</span>
|
||||
);
|
||||
return <span className='oc-muted'>{t('无(继承企业)')}</span>;
|
||||
}
|
||||
return (
|
||||
<div className='flex flex-wrap gap-1'>
|
||||
<div className='oc-tags'>
|
||||
{groups.map((g) => (
|
||||
<Tag key={g} size='small' color='blue'>
|
||||
<Tag key={g} color='blue' bordered={false}>
|
||||
{g}
|
||||
</Tag>
|
||||
))}
|
||||
@@ -552,25 +505,50 @@ const OrgMembers = ({
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: t('备注'),
|
||||
dataIndex: 'remark',
|
||||
width: 165,
|
||||
render: (_, record) => renderRemark(record),
|
||||
},
|
||||
{
|
||||
title: t('状态'),
|
||||
dataIndex: 'status',
|
||||
width: 80,
|
||||
render: (status) => (
|
||||
<Tag color={status === 1 ? 'green' : 'red'}>
|
||||
{status === 1 ? t('正常') : t('禁用')}
|
||||
</Tag>
|
||||
),
|
||||
width: 92,
|
||||
render: (status, record) => {
|
||||
const locked = !canWrite || record.role === 'owner';
|
||||
return (
|
||||
<Tooltip
|
||||
content={
|
||||
record.role === 'owner'
|
||||
? t('所有者不可操作')
|
||||
: status === 1
|
||||
? t('禁用后该成员将无法使用企业资源')
|
||||
: t('启用该成员的企业访问权限')
|
||||
}
|
||||
>
|
||||
<Switch
|
||||
size='small'
|
||||
checked={status === 1}
|
||||
checkedText={t('启用')}
|
||||
uncheckedText={t('禁用')}
|
||||
disabled={locked}
|
||||
aria-label={`${record.display_name || record.username || ''}${t('状态')}`}
|
||||
onChange={(checked) =>
|
||||
handleStatusChange(record.id, checked ? 1 : 2)
|
||||
}
|
||||
/>
|
||||
</Tooltip>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: t('加入时间'),
|
||||
dataIndex: 'joined_at',
|
||||
width: 100,
|
||||
width: 125,
|
||||
render: (v) => (
|
||||
<Tooltip content={v ? new Date(v * 1000).toLocaleString('zh-CN') : '-'}>
|
||||
<span className='text-xs text-gray-500 dark:text-gray-400 cursor-default'>
|
||||
{formatJoinTime(v)}
|
||||
</span>
|
||||
<span className='oc-number'>{formatJoinTime(v)}</span>
|
||||
</Tooltip>
|
||||
),
|
||||
},
|
||||
@@ -580,23 +558,18 @@ const OrgMembers = ({
|
||||
if (canWrite) {
|
||||
memberColumns.push({
|
||||
title: t('操作'),
|
||||
width: 360,
|
||||
width: 260,
|
||||
fixed: 'right',
|
||||
render: (_, record) => {
|
||||
if (record.role === 'owner') {
|
||||
return (
|
||||
<span className='text-xs text-gray-400 dark:text-gray-500 italic'>
|
||||
{t('所有者不可操作')}
|
||||
</span>
|
||||
);
|
||||
return <span className='oc-muted'>{t('所有者不可操作')}</span>;
|
||||
}
|
||||
const isSelf = Number(record.user_id) === currentUserId;
|
||||
return (
|
||||
<div className='flex items-center gap-1.5 flex-wrap'>
|
||||
<OrgRowActions>
|
||||
<Tooltip content={t('设置该成员的个人额度上限')}>
|
||||
<Button
|
||||
size='small'
|
||||
theme='light'
|
||||
icon={<Settings size={14} />}
|
||||
type='link'
|
||||
onClick={() => {
|
||||
setQuotaMemberId(record.id);
|
||||
setQuotaMemberName(
|
||||
@@ -612,9 +585,7 @@ const OrgMembers = ({
|
||||
</Tooltip>
|
||||
<Tooltip content={t('设置该成员可用的模型范围')}>
|
||||
<Button
|
||||
size='small'
|
||||
theme='light'
|
||||
icon={<Layers size={14} />}
|
||||
type='link'
|
||||
onClick={async () => {
|
||||
setModelLimitsMemberId(record.id);
|
||||
setModelLimitsMemberName(
|
||||
@@ -657,9 +628,7 @@ const OrgMembers = ({
|
||||
}
|
||||
>
|
||||
<Button
|
||||
size='small'
|
||||
theme='light'
|
||||
icon={<Layers size={14} />}
|
||||
type='link'
|
||||
disabled={isSelf}
|
||||
onClick={() => {
|
||||
if (isSelf) return;
|
||||
@@ -677,9 +646,7 @@ const OrgMembers = ({
|
||||
{orgRole === 'owner' && record.role === 'admin' && (
|
||||
<Tooltip content={t('设置该管理员的细粒度权限')}>
|
||||
<Button
|
||||
size='small'
|
||||
theme='light'
|
||||
icon={<ShieldCheck size={14} />}
|
||||
type='link'
|
||||
onClick={() => {
|
||||
setPermMemberId(record.id);
|
||||
setPermMemberName(
|
||||
@@ -708,45 +675,17 @@ const OrgMembers = ({
|
||||
</Button>
|
||||
</Tooltip>
|
||||
)}
|
||||
{record.status === 1 ? (
|
||||
<Tooltip content={t('禁用后该成员将无法使用企业资源')}>
|
||||
<Button
|
||||
size='small'
|
||||
theme='light'
|
||||
type='warning'
|
||||
icon={<Ban size={14} />}
|
||||
onClick={() => handleStatusChange(record.id, 2)}
|
||||
>
|
||||
{t('禁用')}
|
||||
</Button>
|
||||
</Tooltip>
|
||||
) : (
|
||||
<Tooltip content={t('启用该成员的企业访问权限')}>
|
||||
<Button
|
||||
size='small'
|
||||
theme='light'
|
||||
type='primary'
|
||||
icon={<CheckCircle size={14} />}
|
||||
onClick={() => handleStatusChange(record.id, 1)}
|
||||
>
|
||||
{t('启用')}
|
||||
</Button>
|
||||
</Tooltip>
|
||||
)}
|
||||
<Tooltip content={t('从企业中移除该成员')}>
|
||||
<Popconfirm
|
||||
title={t('确定移除该成员?移除后该成员将失去企业访问权限。')}
|
||||
onConfirm={() => handleRemove(record.id)}
|
||||
>
|
||||
<Button
|
||||
size='small'
|
||||
theme='light'
|
||||
type='danger'
|
||||
icon={<Trash2 size={14} />}
|
||||
/>
|
||||
<Button type='link' danger>
|
||||
{t('移除')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</OrgRowActions>
|
||||
);
|
||||
},
|
||||
});
|
||||
@@ -754,27 +693,39 @@ const OrgMembers = ({
|
||||
|
||||
const memberListContent = (
|
||||
<>
|
||||
{/* 管理员提示:当只有一个成员时显示 */}
|
||||
{/* 管理员提示:当只有一个成员时显示(原型无此状态 → Ant Design Alert 默认样式) */}
|
||||
{canWrite &&
|
||||
!loading &&
|
||||
members.length === 1 &&
|
||||
members[0]?.role === 'owner' && (
|
||||
<div className='mb-4 p-4 rounded-2xl bg-amber-50/80 border border-amber-200/70 text-amber-900 dark:bg-amber-500/10 dark:border-amber-500/20 dark:text-amber-100'>
|
||||
<p className='text-sm'>
|
||||
💡{' '}
|
||||
{t(
|
||||
'当前企业仅有您一位成员。成员可使用企业代码自助加入,或由系统管理员创建成员账号后即可在此管理成员角色、额度上限和访问权限。',
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
<AntAlert
|
||||
className='oc-block-gap'
|
||||
type='info'
|
||||
showIcon
|
||||
message={t(
|
||||
'当前企业仅有您一位成员。成员可使用企业代码自助加入,或由系统管理员创建成员账号后即可在此管理成员角色、额度上限和访问权限。',
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
|
||||
<OrgPanel padding='p-2'>
|
||||
<OrgListCard
|
||||
title={t('员工列表')}
|
||||
tools={
|
||||
<Button
|
||||
icon={<RefreshCw size={16} />}
|
||||
onClick={() => fetch(page)}
|
||||
loading={loading}
|
||||
>
|
||||
{t('刷新')}
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
columns={memberColumns}
|
||||
dataSource={members}
|
||||
loading={loading}
|
||||
rowKey='id'
|
||||
scroll={{ x: 1500 }}
|
||||
empty={
|
||||
<div className='py-10 text-center'>
|
||||
<div className='inline-flex p-3 rounded-full bg-gray-100 dark:bg-neutral-800 mb-3'>
|
||||
@@ -790,49 +741,49 @@ const OrgMembers = ({
|
||||
pageSize: 20,
|
||||
total,
|
||||
onPageChange: setPage,
|
||||
showTotal: (n) => t('共 {{total}} 条', { total: n }),
|
||||
}}
|
||||
/>
|
||||
</OrgPanel>
|
||||
</OrgListCard>
|
||||
</>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className='uc-page'>
|
||||
<div className='uc-page oc-page'>
|
||||
<OrgPageHeader
|
||||
icon={Users}
|
||||
title={t('员工管理')}
|
||||
subtitle={t('成员权限、额度配额与托管账号生命周期')}
|
||||
actions={
|
||||
showMemberList && (
|
||||
<Button
|
||||
icon={<RefreshCw size={14} />}
|
||||
onClick={() => fetch(page)}
|
||||
loading={loading}
|
||||
>
|
||||
{t('刷新')}
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
||||
{showMemberList && showAccounts ? (
|
||||
<OrgPanel>
|
||||
<Tabs type='button' activeKey={activeTab} onChange={setActiveTab}>
|
||||
<TabPane tab={t('员工权限')} itemKey='members'>
|
||||
<div className='pt-4'>{memberListContent}</div>
|
||||
</TabPane>
|
||||
<TabPane tab={t('员工账号')} itemKey='accounts'>
|
||||
<div className='pt-4'>
|
||||
// 原型 platform-list-tabs;原 Tabs 预渲染全部页签(lazyRender=false),员工账号页签保持随页面挂载
|
||||
<AntTabs
|
||||
className='oc-list-tabs'
|
||||
activeKey={activeTab}
|
||||
onChange={setActiveTab}
|
||||
items={[
|
||||
{
|
||||
key: 'members',
|
||||
label: t('员工权限'),
|
||||
forceRender: true,
|
||||
children: memberListContent,
|
||||
},
|
||||
{
|
||||
key: 'accounts',
|
||||
label: t('员工账号'),
|
||||
forceRender: true,
|
||||
children: (
|
||||
<OrgMemberAccounts
|
||||
orgId={orgId}
|
||||
orgRole={orgRole}
|
||||
embedded
|
||||
featureFlags={featureFlags}
|
||||
/>
|
||||
</div>
|
||||
</TabPane>
|
||||
</Tabs>
|
||||
</OrgPanel>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
) : showMemberList ? (
|
||||
memberListContent
|
||||
) : showAccounts ? (
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import { Button, Empty, Tag } from '@/components/ui';
|
||||
import { Button, Card, Empty, Tag, Typography } from 'antd';
|
||||
import { Cable, LockKeyhole } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { API } from '../../helpers/api';
|
||||
@@ -26,8 +26,14 @@ import {
|
||||
PageGuideDrawer,
|
||||
PageGuideTrigger,
|
||||
} from '../../components/common/PageGuide';
|
||||
import './org-connectors.css';
|
||||
import OrgBreadcrumb from './components/OrgBreadcrumb';
|
||||
import OrgPageHeader from './components/OrgPageHeader';
|
||||
import './org-my-capabilities.css';
|
||||
|
||||
const confirmationLabels = {
|
||||
never: '无需确认',
|
||||
write: '写操作前确认',
|
||||
always: '每次调用都确认',
|
||||
};
|
||||
|
||||
const OrgMyConnectors = ({ orgId }) => {
|
||||
const { t } = useTranslation();
|
||||
@@ -109,33 +115,58 @@ const OrgMyConnectors = ({ orgId }) => {
|
||||
],
|
||||
});
|
||||
return (
|
||||
<main className='org-connector-page'>
|
||||
<header className='org-connector-hero'>
|
||||
<div>
|
||||
<OrgBreadcrumb current={t('我的业务系统授权')} />
|
||||
<h1>{t('我的业务系统授权')}</h1>
|
||||
<p>{t('查看专家在任务中可代表你调用的业务系统、方法和确认策略。')}</p>
|
||||
</div>
|
||||
<div className='org-connector-actions'>
|
||||
<PageGuideTrigger guide={guide} />
|
||||
</div>
|
||||
</header>
|
||||
<main className='uc-page org-capabilities-page'>
|
||||
<OrgPageHeader
|
||||
title={t('我的业务系统授权')}
|
||||
subtitle={t('查看专家在任务中可代表你调用的业务系统、方法和确认策略。')}
|
||||
actions={<PageGuideTrigger guide={guide} />}
|
||||
/>
|
||||
<PageGuideDrawer guide={guide} />
|
||||
{loadError ? (
|
||||
<Empty title={t('授权列表加载失败')} description={loadError} />
|
||||
<Card>
|
||||
<Empty
|
||||
description={
|
||||
<>
|
||||
<Typography.Text>{t('授权列表加载失败')}</Typography.Text>
|
||||
<Typography.Paragraph type='secondary'>
|
||||
{loadError}
|
||||
</Typography.Paragraph>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
) : items.length === 0 ? (
|
||||
<Empty
|
||||
title={t('当前没有 Connector 授权')}
|
||||
description={t('管理员发布授权并覆盖到你后会显示在这里。')}
|
||||
/>
|
||||
<Card>
|
||||
<Empty
|
||||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||||
description={
|
||||
<>
|
||||
<Typography.Text>
|
||||
{t('当前没有 Connector 授权')}
|
||||
</Typography.Text>
|
||||
<Typography.Paragraph type='secondary'>
|
||||
{t('管理员发布授权并覆盖到你后会显示在这里。')}
|
||||
</Typography.Paragraph>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
) : (
|
||||
<section className='org-connector-grid'>
|
||||
<section className='org-capability-grid'>
|
||||
{items.map((item) => (
|
||||
<article className='org-connector-card' key={item.grant.id}>
|
||||
<div className='org-connector-card-top'>
|
||||
<span className='org-connector-icon'>
|
||||
<Card className='org-capability-card' key={item.grant.id}>
|
||||
<div className='org-capability-card-head'>
|
||||
<span className='org-capability-icon'>
|
||||
<Cable size={20} />
|
||||
</span>
|
||||
<div className='org-capability-card-name'>
|
||||
<Typography.Title level={5}>
|
||||
{item.connector_name}
|
||||
</Typography.Title>
|
||||
<Typography.Text type='secondary'>
|
||||
{item.definition_name}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
<Tag
|
||||
color={
|
||||
item.grant.access_level === 'write' ? 'orange' : 'green'
|
||||
@@ -144,23 +175,29 @@ const OrgMyConnectors = ({ orgId }) => {
|
||||
{item.grant.access_level}
|
||||
</Tag>
|
||||
</div>
|
||||
<h3>{item.connector_name}</h3>
|
||||
<p>{item.definition_name}</p>
|
||||
<div className='org-connector-tags'>
|
||||
<div className='org-capability-methods'>
|
||||
{item.methods.map((method) => (
|
||||
<Tag key={method}>{method}</Tag>
|
||||
))}
|
||||
</div>
|
||||
<p>
|
||||
<LockKeyhole size={14} /> {t('确认策略')}:{' '}
|
||||
{item.grant.confirmation_policy}
|
||||
</p>
|
||||
<Button disabled={!item.revocable}>
|
||||
{item.revocable
|
||||
? t('撤销个人委托')
|
||||
: t('企业服务账号由管理员管理')}
|
||||
</Button>
|
||||
</article>
|
||||
<div className='org-capability-confirmation'>
|
||||
<LockKeyhole size={14} aria-hidden='true' />
|
||||
<Typography.Text type='secondary'>
|
||||
{t('确认策略')}:{' '}
|
||||
{t(
|
||||
confirmationLabels[item.grant.confirmation_policy] ||
|
||||
item.grant.confirmation_policy,
|
||||
)}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
<div className='org-capability-card-footer'>
|
||||
<Button disabled={!item.revocable}>
|
||||
{item.revocable
|
||||
? t('撤销个人委托')
|
||||
: t('企业服务账号由管理员管理')}
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</section>
|
||||
)}
|
||||
|
||||
@@ -18,25 +18,36 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { Switch, Toast, Typography } from '@/components/ui';
|
||||
import { LockKeyhole } from 'lucide-react';
|
||||
import { Card, Empty, Switch, Tag, Tooltip, Typography } from 'antd';
|
||||
import { Toast } from '@/components/ui';
|
||||
import { Link2, LockKeyhole, Sparkles } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { API } from '../../helpers';
|
||||
import {
|
||||
AssignmentModeTag,
|
||||
ScopeSourceBadge,
|
||||
SkillEmptyGuide,
|
||||
} from '../../components/skill';
|
||||
import {
|
||||
usePageGuide,
|
||||
PageGuideDrawer,
|
||||
PageGuideTrigger,
|
||||
} from '../../components/common/PageGuide';
|
||||
import './org-skills.css';
|
||||
import OrgBreadcrumb from './components/OrgBreadcrumb';
|
||||
import OrgPageHeader from './components/OrgPageHeader';
|
||||
import './org-my-capabilities.css';
|
||||
|
||||
const { Title, Paragraph, Text } = Typography;
|
||||
|
||||
const modes = {
|
||||
required_locked: { label: '必需锁定', color: 'warning' },
|
||||
default_on: { label: '默认开启', color: 'processing' },
|
||||
recommended: { label: '推荐', color: 'success' },
|
||||
optional: { label: '可选', color: 'default' },
|
||||
};
|
||||
const scopes = {
|
||||
org: '企业',
|
||||
department: '部门',
|
||||
dept: '部门',
|
||||
project: '项目',
|
||||
role: '角色',
|
||||
member: '成员',
|
||||
};
|
||||
|
||||
const OrgMySkills = ({ orgId }) => {
|
||||
const { t } = useTranslation();
|
||||
const headers = useMemo(() => ({ 'X-Org-Id': String(orgId) }), [orgId]);
|
||||
@@ -114,67 +125,93 @@ const OrgMySkills = ({ orgId }) => {
|
||||
],
|
||||
});
|
||||
return (
|
||||
<main className='org-skills-page'>
|
||||
<header className='org-skills-hero'>
|
||||
<div>
|
||||
<OrgBreadcrumb current={t('我的技能')} />
|
||||
<Title heading={3}>{t('我的技能')}</Title>
|
||||
<Paragraph>
|
||||
{t(
|
||||
'这里展示与任务运行时相同的有效能力集,以及每项技能为什么对你生效。',
|
||||
)}
|
||||
</Paragraph>
|
||||
</div>
|
||||
<div className='org-skills-hero-actions'>
|
||||
<PageGuideTrigger guide={guide} />
|
||||
</div>
|
||||
</header>
|
||||
<main className='uc-page org-capabilities-page'>
|
||||
<OrgPageHeader
|
||||
title={t('我的技能')}
|
||||
subtitle={t(
|
||||
'这里展示与任务运行时相同的有效能力集,以及每项技能为什么对你生效。',
|
||||
)}
|
||||
actions={<PageGuideTrigger guide={guide} />}
|
||||
/>
|
||||
<PageGuideDrawer guide={guide} />
|
||||
{items.length === 0 ? (
|
||||
<SkillEmptyGuide
|
||||
title={t('当前没有可用技能')}
|
||||
description={t('企业管理员启用并分发后会显示在这里。')}
|
||||
/>
|
||||
<Card>
|
||||
<Empty
|
||||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||||
description={
|
||||
<>
|
||||
<Text>{t('当前没有可用技能')}</Text>
|
||||
<Paragraph type='secondary'>
|
||||
{t('企业管理员启用并分发后会显示在这里。')}
|
||||
</Paragraph>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
) : (
|
||||
<section className='org-my-skills'>
|
||||
<section className='org-capability-grid'>
|
||||
{items
|
||||
.filter((item) => item.mode !== 'forbidden')
|
||||
.map((item) => {
|
||||
const locked = item.mode === 'required_locked';
|
||||
const mode = modes[item.mode] || {
|
||||
label: item.mode,
|
||||
color: 'default',
|
||||
};
|
||||
return (
|
||||
<article key={item.skill_id}>
|
||||
<div>
|
||||
<span className='org-my-skill-title'>
|
||||
{locked && <LockKeyhole size={16} />}
|
||||
<Text strong>
|
||||
{item.customization?.display_name || item.canonical_id}
|
||||
</Text>
|
||||
<AssignmentModeTag mode={item.mode} />
|
||||
<Card key={item.skill_id} className='org-capability-card'>
|
||||
<div className='org-capability-card-head'>
|
||||
<span className='org-capability-icon'>
|
||||
<Sparkles size={20} />
|
||||
</span>
|
||||
<Paragraph>
|
||||
{item.customization?.description_zh ||
|
||||
item.customization?.usage_boundary ||
|
||||
t('企业已审核的方法能力')}
|
||||
</Paragraph>
|
||||
<div className='org-my-skill-sources'>
|
||||
{(item.sources || []).map((source) => (
|
||||
<ScopeSourceBadge
|
||||
key={source.id}
|
||||
source={`${source.scope_type}:${source.scope_id || source.scope_value || 'all'}`}
|
||||
detail={`${source.mode} / ${source.activation}`}
|
||||
/>
|
||||
))}
|
||||
<div className='org-capability-card-name'>
|
||||
<Title level={5}>
|
||||
{item.customization?.display_name || item.canonical_id}
|
||||
</Title>
|
||||
<Text type='secondary'>v#{item.version_id}</Text>
|
||||
</div>
|
||||
<Tag
|
||||
color={mode.color}
|
||||
icon={locked ? <LockKeyhole size={12} /> : undefined}
|
||||
>
|
||||
{t(mode.label)}
|
||||
</Tag>
|
||||
</div>
|
||||
<div>
|
||||
<Text type='tertiary'>v#{item.version_id}</Text>
|
||||
<Paragraph
|
||||
type='secondary'
|
||||
className='org-capability-description'
|
||||
>
|
||||
{item.customization?.description_zh ||
|
||||
item.customization?.usage_boundary ||
|
||||
t('企业已审核的方法能力')}
|
||||
</Paragraph>
|
||||
<div className='org-capability-sources'>
|
||||
{(item.sources || []).map((source) => (
|
||||
<Tooltip
|
||||
key={source.id}
|
||||
title={`${t(modes[source.mode]?.label || source.mode)} / ${source.activation}`}
|
||||
>
|
||||
<Tag icon={<Link2 size={12} />}>
|
||||
{t(scopes[source.scope_type] || source.scope_type)} ·{' '}
|
||||
{source.scope_id || source.scope_value || t('全部')}
|
||||
</Tag>
|
||||
</Tooltip>
|
||||
))}
|
||||
</div>
|
||||
<div className='org-capability-card-footer'>
|
||||
<Text type='secondary'>
|
||||
{t(item.enabled ? '已启用' : '已停用')}
|
||||
</Text>
|
||||
<Switch
|
||||
aria-label={
|
||||
item.customization?.display_name || item.canonical_id
|
||||
}
|
||||
disabled={locked}
|
||||
checked={item.enabled}
|
||||
onChange={(enabled) => choose(item, enabled)}
|
||||
/>
|
||||
</div>
|
||||
</article>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</section>
|
||||
|
||||
@@ -19,22 +19,14 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
import React, { useCallback, useContext, useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Button,
|
||||
InputNumber,
|
||||
Spin,
|
||||
Tabs,
|
||||
TabPane,
|
||||
Typography,
|
||||
} from '@/components/ui';
|
||||
import {
|
||||
Bell,
|
||||
Building2,
|
||||
KeyRound,
|
||||
Pencil,
|
||||
UserRound,
|
||||
UserCog,
|
||||
Wallet,
|
||||
} from 'lucide-react';
|
||||
Avatar as AntAvatar,
|
||||
Card as AntCard,
|
||||
Progress as AntProgress,
|
||||
Tabs as AntTabs,
|
||||
Tag as AntTag,
|
||||
} from 'antd';
|
||||
import { Button, InputNumber, Spin, Typography } from '@/components/ui';
|
||||
import { UserCog } from 'lucide-react';
|
||||
import { API } from '../../helpers/api';
|
||||
import {
|
||||
showError,
|
||||
@@ -44,13 +36,16 @@ import {
|
||||
USER_AVATAR_TYPES,
|
||||
getAvatarPresetById,
|
||||
getDefaultAvatarPresetId,
|
||||
getUserAvatarUrl,
|
||||
} from '../../helpers';
|
||||
import { renderQuota } from '../../helpers/render';
|
||||
import { UserContext } from '../../context/User';
|
||||
import NotifyChannelForm from '../../components/settings/NotifyChannelForm';
|
||||
import OrgPageHeader from './components/OrgPageHeader';
|
||||
import OrgPanel from './components/OrgPanel';
|
||||
import OrgAvatarSection from './components/OrgAvatarSection';
|
||||
import AvatarSection from '../../components/settings/personal/sections/AvatarSection';
|
||||
import SectionHeader from '../../components/settings/personal/components/SectionHeader';
|
||||
import '../../components/settings/personal/personal-settings.css';
|
||||
import '../../styles/org-center.css';
|
||||
import OrgNicknameModal from './components/OrgNicknameModal';
|
||||
import OrgPasswordModal from './components/OrgPasswordModal';
|
||||
|
||||
@@ -82,20 +77,6 @@ const quotaPeriodHint = (t, period) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 信息行:label + 右侧内容(个人资料/企业身份卡片共用)
|
||||
const InfoRow = ({ label, children, last = false }) => (
|
||||
<div
|
||||
className={`flex items-center justify-between gap-3 py-3 ${
|
||||
last ? '' : 'border-b border-[var(--border-subtle)]'
|
||||
}`}
|
||||
>
|
||||
<Text type='tertiary' className='flex-shrink-0'>
|
||||
{label}
|
||||
</Text>
|
||||
<div className='flex items-center gap-2 min-w-0'>{children}</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
/*
|
||||
* 成员个人设置页(/org/personal-settings,全员可见)。
|
||||
* 企业中心是独立空间:改密/昵称走企业端接口,通知为企业维度的成员配额预警,
|
||||
@@ -302,8 +283,12 @@ const OrgPersonalSettings = ({ orgId }) => {
|
||||
),
|
||||
);
|
||||
// 进度条随用量升温:正常品牌色,≥80% 转琥珀,≥95% 转红,给成员用尽预警
|
||||
const quotaBarClass =
|
||||
usedPct >= 95 ? 'bg-red-500' : usedPct >= 80 ? 'bg-amber-500' : 'bg-brand';
|
||||
const quotaBarColor =
|
||||
usedPct >= 95
|
||||
? 'var(--ui-color-danger)'
|
||||
: usedPct >= 80
|
||||
? 'var(--ui-color-warning)'
|
||||
: 'var(--oc-brand)';
|
||||
const displayName =
|
||||
member.display_name ||
|
||||
userState?.user?.display_name ||
|
||||
@@ -318,189 +303,209 @@ const OrgPersonalSettings = ({ orgId }) => {
|
||||
);
|
||||
}
|
||||
|
||||
// 个人资料页签(原型 profile 面板):昵称 / 密码设置行 + 个人配额卡;企业身份信息归入资料头卡
|
||||
const profilePanel = (
|
||||
<div className='oc-ps-panel'>
|
||||
<SectionHeader
|
||||
title={t('基本资料')}
|
||||
description={t('管理企业内展示的个人信息')}
|
||||
/>
|
||||
<div className='ui-settings-rows'>
|
||||
<div className='ui-settings-row'>
|
||||
<div className='ui-settings-row-text'>
|
||||
<h3>{t('昵称管理')}</h3>
|
||||
<p>
|
||||
{t('当前昵称:')}
|
||||
{displayName || t('未设置')}
|
||||
</p>
|
||||
</div>
|
||||
<div className='ui-settings-row-actions'>
|
||||
<Button onClick={() => setNickModal(true)}>{t('修改昵称')}</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div className='ui-settings-row'>
|
||||
<div className='ui-settings-row-text'>
|
||||
<h3>{t('密码管理')}</h3>
|
||||
<p>{t('定期更改密码可以提高账户安全性')}</p>
|
||||
</div>
|
||||
<div className='ui-settings-row-actions'>
|
||||
<Button onClick={() => setPwdModal(true)}>{t('修改密码')}</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className='oc-ps-info-grid'>
|
||||
<AntCard size='small' title={t('个人配额')}>
|
||||
{quotaLimit > 0 ? (
|
||||
<>
|
||||
<div className='oc-ps-quota'>
|
||||
<span>{t('剩余可用')}</span>
|
||||
<strong>{renderQuota(remainQuota)}</strong>
|
||||
</div>
|
||||
<AntProgress
|
||||
percent={usedPct}
|
||||
showInfo={false}
|
||||
strokeColor={quotaBarColor}
|
||||
/>
|
||||
<div className='oc-ps-quota-meta'>
|
||||
<span>
|
||||
{t('已用')} {renderQuota(usedQuota)} / {t('总额')}{' '}
|
||||
{renderQuota(quotaLimit)}({usedPct}%)
|
||||
</span>
|
||||
{isPeriodic && (
|
||||
<span>{quotaPeriodHint(t, myQuota.quota_period)}</span>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div className='oc-ps-unlimited'>
|
||||
<AntTag color='gold' bordered={false}>
|
||||
{t('不限额')}
|
||||
</AntTag>
|
||||
<span>{t('企业未对你设置配额上限')}</span>
|
||||
</div>
|
||||
)}
|
||||
</AntCard>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
// 通知设置页签(原型 notice 面板):渠道表单 + 预警阈值;保存回调不变
|
||||
const notifyPanel = (
|
||||
<div className='oc-ps-panel'>
|
||||
<SectionHeader
|
||||
title={t('配额预警通知')}
|
||||
description={t(
|
||||
'企业分配给你的额度即将用尽或已用尽时,通过以下渠道提醒你',
|
||||
)}
|
||||
extra={
|
||||
<Button
|
||||
theme='solid'
|
||||
loading={savingNotify}
|
||||
onClick={saveNotifySettings}
|
||||
>
|
||||
{t('保存通知设置')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
<div className='oc-ps-notice-form'>
|
||||
<NotifyChannelForm
|
||||
value={notifyValue}
|
||||
onChange={setNotifyValue}
|
||||
channels={['email', 'webhook']}
|
||||
emailPlaceholder={t('必填,用于接收预警通知')}
|
||||
/>
|
||||
<div className='oc-ps-threshold'>
|
||||
<label>{t('预警阈值')}</label>
|
||||
{quotaLimit > 0 ? (
|
||||
<>
|
||||
<InputNumber
|
||||
value={alertThreshold}
|
||||
onChange={(v) => setAlertThreshold(v)}
|
||||
min={0}
|
||||
step={1000}
|
||||
style={{ width: '100%', maxWidth: 260 }}
|
||||
/>
|
||||
<Text type='tertiary' size='small'>
|
||||
{t('剩余额度低于该值时提醒,0 表示关闭')}
|
||||
{Number(alertThreshold) > 0 &&
|
||||
` · ${t('约合')} ${renderQuota(Number(alertThreshold))}`}
|
||||
{` · ${t('当前剩余')} ${renderQuota(remainQuota)}`}
|
||||
</Text>
|
||||
</>
|
||||
) : (
|
||||
<Text type='tertiary'>
|
||||
{t('企业未对你设置配额上限,无需配置预警')}
|
||||
</Text>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className='uc-page'>
|
||||
<div className='uc-page oc-page ui-personal-settings oc-personal-settings'>
|
||||
<OrgPageHeader
|
||||
icon={UserCog}
|
||||
title={t('个人设置')}
|
||||
subtitle={t('管理你的头像、昵称、密码与通知偏好')}
|
||||
/>
|
||||
|
||||
<Tabs type='line' className='mt-2'>
|
||||
<TabPane tab={t('个人资料')} itemKey='profile'>
|
||||
{/* 头像设置上移至页面上半部分,作为视觉锚点,保存走企业端接口 */}
|
||||
<div className='mt-4'>
|
||||
<OrgAvatarSection
|
||||
t={t}
|
||||
userState={userState}
|
||||
avatarSettings={avatarSettings}
|
||||
handleAvatarSettingChange={handleAvatarSettingChange}
|
||||
saveAvatarSettings={saveAvatarSettings}
|
||||
saving={savingAvatar}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 基本资料 / 企业身份 / 个人配额:三栏均分,卡片等高,避免高度失衡 */}
|
||||
<div className='mt-4 grid grid-cols-1 lg:grid-cols-3 gap-4'>
|
||||
{/* 基本资料:昵称 + 登录密码(复用工作台同款弹窗与企业端接口) */}
|
||||
<OrgPanel title={t('基本资料')} icon={UserRound} padding='px-5 py-2'>
|
||||
<InfoRow label={t('昵称')}>
|
||||
<Text className='truncate'>{displayName || t('未设置')}</Text>
|
||||
<Button
|
||||
theme='light'
|
||||
size='small'
|
||||
icon={<Pencil size={13} />}
|
||||
onClick={() => setNickModal(true)}
|
||||
>
|
||||
{t('编辑')}
|
||||
</Button>
|
||||
</InfoRow>
|
||||
<InfoRow label={t('登录密码')} last>
|
||||
<Text type='tertiary'>••••••••</Text>
|
||||
<Button
|
||||
theme='light'
|
||||
size='small'
|
||||
icon={<KeyRound size={13} />}
|
||||
onClick={() => setPwdModal(true)}
|
||||
>
|
||||
{t('修改密码')}
|
||||
</Button>
|
||||
</InfoRow>
|
||||
</OrgPanel>
|
||||
|
||||
{/* 企业身份只读信息(数据源 /api/org/me/summary,与工作台一致) */}
|
||||
<OrgPanel title={t('企业身份')} icon={Building2} padding='px-5 py-2'>
|
||||
<InfoRow label={t('所属企业')}>
|
||||
<Text className='truncate'>
|
||||
{summary?.organization?.name || '-'}
|
||||
</Text>
|
||||
</InfoRow>
|
||||
<InfoRow label={t('我的角色')}>
|
||||
<span className='inline-flex items-center rounded-full bg-brand/10 text-brand px-2.5 py-0.5 text-xs font-medium'>
|
||||
{roleLabel(t, member.role)}
|
||||
</span>
|
||||
</InfoRow>
|
||||
<InfoRow label={t('所属部门')} last>
|
||||
<Text className='truncate'>
|
||||
{member.department_name || t('未分配')}
|
||||
</Text>
|
||||
</InfoRow>
|
||||
</OrgPanel>
|
||||
|
||||
{/* 个人配额:成员高频关注项,抽成带进度条的重点块 */}
|
||||
<OrgPanel title={t('个人配额')} icon={Wallet} padding='p-5'>
|
||||
{quotaLimit > 0 ? (
|
||||
<div>
|
||||
<div className='flex items-end justify-between gap-3'>
|
||||
<div className='min-w-0'>
|
||||
<div className='text-xs text-[var(--text-secondary)]'>
|
||||
{t('剩余可用')}
|
||||
</div>
|
||||
<div className='mt-0.5 text-2xl font-semibold text-[var(--text-primary)] truncate'>
|
||||
{renderQuota(remainQuota)}
|
||||
</div>
|
||||
</div>
|
||||
<div className='shrink-0 text-right text-xs text-gray-500 dark:text-gray-400 leading-relaxed'>
|
||||
<div>
|
||||
{t('已用')} {renderQuota(usedQuota)}
|
||||
</div>
|
||||
<div>
|
||||
{t('总额')} {renderQuota(quotaLimit)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className='mt-3 h-2 w-full overflow-hidden rounded-full bg-gray-100 dark:bg-white/[0.08]'>
|
||||
<div
|
||||
className={`h-full rounded-full transition-all duration-300 ${quotaBarClass}`}
|
||||
style={{ width: `${usedPct}%` }}
|
||||
/>
|
||||
</div>
|
||||
<div className='mt-2 flex items-center justify-between text-xs'>
|
||||
<span className='text-gray-500 dark:text-gray-400'>
|
||||
{t('已用')} {usedPct}%
|
||||
</span>
|
||||
{isPeriodic && (
|
||||
<span className='text-brand font-medium'>
|
||||
{quotaPeriodHint(t, myQuota.quota_period)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className='flex items-center gap-2 py-1.5'>
|
||||
<span className='inline-flex items-center rounded-full bg-brand/10 text-brand px-2.5 py-0.5 text-xs font-medium'>
|
||||
{t('不限额')}
|
||||
</span>
|
||||
<Text type='tertiary' size='small'>
|
||||
{t('企业未对你设置配额上限')}
|
||||
</Text>
|
||||
</div>
|
||||
)}
|
||||
</OrgPanel>
|
||||
</div>
|
||||
</TabPane>
|
||||
|
||||
<TabPane
|
||||
tab={t('通知设置')}
|
||||
itemKey='notify'
|
||||
disabled={isSuperAdminView}
|
||||
>
|
||||
<OrgPanel
|
||||
title={t('配额预警通知')}
|
||||
subtitle={t(
|
||||
'企业分配给你的额度即将用尽或已用尽时,通过以下渠道提醒你',
|
||||
)}
|
||||
icon={Bell}
|
||||
padding='p-5'
|
||||
className='mt-4'
|
||||
actions={
|
||||
<Button
|
||||
theme='solid'
|
||||
loading={savingNotify}
|
||||
onClick={saveNotifySettings}
|
||||
>
|
||||
{t('保存通知设置')}
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<NotifyChannelForm
|
||||
value={notifyValue}
|
||||
onChange={setNotifyValue}
|
||||
channels={['email', 'webhook']}
|
||||
emailPlaceholder={t('必填,用于接收预警通知')}
|
||||
/>
|
||||
|
||||
<div className='mt-5 pt-4 border-t border-[var(--border-subtle)]'>
|
||||
<label className='block text-sm font-medium text-[var(--text-primary)] mb-2'>
|
||||
{t('预警阈值')}
|
||||
</label>
|
||||
{quotaLimit > 0 ? (
|
||||
<>
|
||||
<InputNumber
|
||||
value={alertThreshold}
|
||||
onChange={(v) => setAlertThreshold(v)}
|
||||
min={0}
|
||||
step={1000}
|
||||
style={{ width: '100%', maxWidth: 260 }}
|
||||
/>
|
||||
<div className='mt-2'>
|
||||
<Text type='tertiary' size='small'>
|
||||
{t('剩余额度低于该值时提醒,0 表示关闭')}
|
||||
{Number(alertThreshold) > 0 &&
|
||||
` · ${t('约合')} ${renderQuota(Number(alertThreshold))}`}
|
||||
{` · ${t('当前剩余')} ${renderQuota(remainQuota)}`}
|
||||
</Text>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<Text type='tertiary'>
|
||||
{t('企业未对你设置配额上限,无需配置预警')}
|
||||
</Text>
|
||||
)}
|
||||
{/* 资料头卡(原型 .ps-profile):头像 / 昵称 / 角色 / 企业 · 部门 + 配额概览,数据源 /api/org/me/summary */}
|
||||
<AntCard className='ui-personal-profile'>
|
||||
<div className='ui-profile-identity'>
|
||||
<span className='ui-profile-avatar'>
|
||||
<AntAvatar
|
||||
shape='square'
|
||||
size={54}
|
||||
src={getUserAvatarUrl(userState?.user)}
|
||||
>
|
||||
{(displayName || '?').slice(0, 2).toUpperCase()}
|
||||
</AntAvatar>
|
||||
</span>
|
||||
<div className='ui-profile-meta'>
|
||||
<div className='ui-profile-name'>
|
||||
<strong>{displayName || t('未设置')}</strong>
|
||||
<AntTag color='gold' bordered={false}>
|
||||
{roleLabel(t, member.role)}
|
||||
</AntTag>
|
||||
</div>
|
||||
</OrgPanel>
|
||||
</TabPane>
|
||||
</Tabs>
|
||||
<div className='ui-profile-sub'>
|
||||
<span>{summary?.organization?.name || '-'}</span>
|
||||
<span aria-hidden='true'>·</span>
|
||||
<span>{member.department_name || t('部门未分配')}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className='ui-profile-stats'>
|
||||
<div>
|
||||
<span>{t('剩余配额')}</span>
|
||||
<strong>
|
||||
{quotaLimit > 0 ? renderQuota(remainQuota) : t('不限额')}
|
||||
</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>{t('已用额度')}</span>
|
||||
<strong>{renderQuota(usedQuota)}</strong>
|
||||
</div>
|
||||
</div>
|
||||
</AntCard>
|
||||
|
||||
{/* 设置卡(原型 .ps-workspace):头像设置 / 个人资料 / 通知设置 */}
|
||||
<AntCard className='ui-personal-content'>
|
||||
<AntTabs
|
||||
defaultActiveKey='avatar'
|
||||
items={[
|
||||
{
|
||||
key: 'avatar',
|
||||
label: t('头像设置'),
|
||||
forceRender: true,
|
||||
children: (
|
||||
<AvatarSection
|
||||
t={t}
|
||||
userState={userState}
|
||||
avatarSettings={avatarSettings}
|
||||
handleAvatarSettingChange={handleAvatarSettingChange}
|
||||
saveAvatarSettings={saveAvatarSettings}
|
||||
savingAvatarSettings={savingAvatar}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'profile',
|
||||
label: t('个人资料'),
|
||||
forceRender: true,
|
||||
children: profilePanel,
|
||||
},
|
||||
{
|
||||
key: 'notify',
|
||||
label: t('通知设置'),
|
||||
disabled: isSuperAdminView,
|
||||
forceRender: true,
|
||||
children: notifyPanel,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</AntCard>
|
||||
|
||||
<OrgNicknameModal
|
||||
visible={nickModal}
|
||||
|
||||
@@ -18,6 +18,7 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Switch } from 'antd';
|
||||
import {
|
||||
Table,
|
||||
Button,
|
||||
@@ -27,11 +28,11 @@ import {
|
||||
Tag,
|
||||
Select,
|
||||
} from '@/components/ui';
|
||||
import { RefreshCw, Plus, Users } from 'lucide-react';
|
||||
import { RefreshCw, Plus } from 'lucide-react';
|
||||
import { API } from '../../helpers/api';
|
||||
import { showError, collectPagedItems } from '../../helpers';
|
||||
import OrgPageHeader from './components/OrgPageHeader';
|
||||
import OrgPanel from './components/OrgPanel';
|
||||
import { OrgListCard, OrgRowActions } from './components/OrgListCard';
|
||||
import OrgModal from './components/OrgModal';
|
||||
import OrgScopedLimitButtons from './components/OrgScopedLimitButtons';
|
||||
|
||||
@@ -42,6 +43,7 @@ const OrgProjects = ({ orgId }) => {
|
||||
const { t } = useTranslation();
|
||||
const [list, setList] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [updatingProjectId, setUpdatingProjectId] = useState(null);
|
||||
const [members, setMembers] = useState([]); // 企业全部成员(用于成员选择)
|
||||
|
||||
const [modalVisible, setModalVisible] = useState(false);
|
||||
@@ -53,7 +55,7 @@ const OrgProjects = ({ orgId }) => {
|
||||
const [addMemberIds, setAddMemberIds] = useState([]); // 支持一次添加多个成员
|
||||
const [addMemberRole, setAddMemberRole] = useState('project_member');
|
||||
|
||||
const [tokenModal, setTokenModal] = useState(null); // 当前管理令牌的项目
|
||||
const [tokenModal, setTokenModal] = useState(null); // 当前管理密钥的项目
|
||||
const [orgTokens, setOrgTokens] = useState([]);
|
||||
|
||||
const fetchList = useCallback(async () => {
|
||||
@@ -158,19 +160,34 @@ const OrgProjects = ({ orgId }) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleDisable = async (record) => {
|
||||
const handleStatusChange = async (record, enabled) => {
|
||||
if (updatingProjectId !== null) return;
|
||||
setUpdatingProjectId(record.id);
|
||||
try {
|
||||
const res = await API.delete(`/api/org/project/${record.id}`, {
|
||||
headers: getOrgHeaders(orgId),
|
||||
});
|
||||
const url = `/api/org/project/${record.id}`;
|
||||
const config = { headers: getOrgHeaders(orgId) };
|
||||
const res = enabled
|
||||
? await API.put(
|
||||
url,
|
||||
{ code: record.code, name: record.name, status: 1 },
|
||||
config,
|
||||
)
|
||||
: await API.delete(url, config);
|
||||
if (res.data.success) {
|
||||
Toast.success(t('项目已停用'));
|
||||
fetchList();
|
||||
Toast.success(t('项目已更新'));
|
||||
setList((items) =>
|
||||
items.map((item) =>
|
||||
item.id === record.id ? { ...item, status: enabled ? 1 : 2 } : item,
|
||||
),
|
||||
);
|
||||
await fetchList();
|
||||
} else {
|
||||
showError(res.data.message);
|
||||
}
|
||||
} catch (err) {
|
||||
showError(err.message);
|
||||
} finally {
|
||||
setUpdatingProjectId(null);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -287,104 +304,116 @@ const OrgProjects = ({ orgId }) => {
|
||||
}));
|
||||
}, [members, projectMembers]);
|
||||
|
||||
// 列宽与渲染对齐原型 EnterpriseProjects(150/350/120/140/300,scroll.x 1060);
|
||||
const columns = [
|
||||
{ title: t('项目编码'), dataIndex: 'code' },
|
||||
{ title: t('项目名称'), dataIndex: 'name' },
|
||||
{
|
||||
title: t('项目编码'),
|
||||
dataIndex: 'code',
|
||||
width: 150,
|
||||
render: (v) => <span className='oc-number'>{v}</span>,
|
||||
},
|
||||
{ title: t('项目名称'), dataIndex: 'name', width: 350 },
|
||||
{
|
||||
title: t('状态'),
|
||||
dataIndex: 'status',
|
||||
width: 90,
|
||||
render: (v) => (
|
||||
<Tag color={v === 1 ? 'green' : 'grey'}>
|
||||
{v === 1 ? t('启用') : t('停用')}
|
||||
</Tag>
|
||||
width: 120,
|
||||
render: (v, record) => (
|
||||
<Popconfirm
|
||||
title={t('确认停用该项目?')}
|
||||
content={t('停用后保留历史,不再接受新调用绑定')}
|
||||
disabled={v !== 1 || updatingProjectId !== null}
|
||||
onConfirm={() => handleStatusChange(record, false)}
|
||||
>
|
||||
<Switch
|
||||
size='small'
|
||||
checked={v === 1}
|
||||
checkedChildren={t('启用')}
|
||||
unCheckedChildren={t('禁用')}
|
||||
aria-label={`${record.name} ${t('状态')}`}
|
||||
loading={updatingProjectId === record.id}
|
||||
disabled={updatingProjectId !== null}
|
||||
onChange={(checked) => {
|
||||
if (checked) handleStatusChange(record, true);
|
||||
}}
|
||||
/>
|
||||
</Popconfirm>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('到期时间'),
|
||||
dataIndex: 'expired_at',
|
||||
width: 120,
|
||||
width: 140,
|
||||
render: (v) => (v ? new Date(v * 1000).toLocaleDateString() : '-'),
|
||||
},
|
||||
{
|
||||
title: t('操作'),
|
||||
width: 420,
|
||||
width: 300,
|
||||
render: (_, record) => (
|
||||
<div className='flex items-center gap-2 flex-wrap'>
|
||||
<OrgRowActions>
|
||||
<OrgScopedLimitButtons
|
||||
orgId={orgId}
|
||||
record={record}
|
||||
apiBase='/api/org/project'
|
||||
scopeLabel='项目'
|
||||
onSaved={fetchList}
|
||||
variant='link'
|
||||
/>
|
||||
<Button
|
||||
size='small'
|
||||
theme='light'
|
||||
icon={<Users size={14} />}
|
||||
onClick={() => openMembers(record)}
|
||||
>
|
||||
<Button type='link' onClick={() => openMembers(record)}>
|
||||
{t('成员')}
|
||||
</Button>
|
||||
<Button size='small' theme='light' onClick={() => openTokens(record)}>
|
||||
{t('令牌')}
|
||||
<Button type='link' onClick={() => openTokens(record)}>
|
||||
{t('密钥')}
|
||||
</Button>
|
||||
<Button size='small' theme='light' onClick={() => openEdit(record)}>
|
||||
<Button type='link' onClick={() => openEdit(record)}>
|
||||
{t('编辑')}
|
||||
</Button>
|
||||
{record.status === 1 && (
|
||||
<Popconfirm
|
||||
title={t('确认停用该项目?')}
|
||||
content={t('停用后保留历史,不再接受新调用绑定')}
|
||||
onConfirm={() => handleDisable(record)}
|
||||
>
|
||||
<Button size='small' theme='light' type='danger'>
|
||||
{t('停用')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
)}
|
||||
</div>
|
||||
</OrgRowActions>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div className='uc-page'>
|
||||
<div className='uc-page oc-page'>
|
||||
<OrgPageHeader
|
||||
title={t('项目管理')}
|
||||
subtitle={t('项目成员与项目预算')}
|
||||
actions={
|
||||
subtitle={t('管理项目成员、模型范围与密钥归属')}
|
||||
/>
|
||||
|
||||
<OrgListCard
|
||||
title={t('项目列表')}
|
||||
tools={
|
||||
<>
|
||||
<Button
|
||||
theme='light'
|
||||
icon={<RefreshCw size={14} />}
|
||||
onClick={fetchList}
|
||||
>
|
||||
<Button icon={<RefreshCw size={16} />} onClick={fetchList}>
|
||||
{t('刷新')}
|
||||
</Button>
|
||||
<Button
|
||||
theme='solid'
|
||||
icon={<Plus size={14} />}
|
||||
icon={<Plus size={16} />}
|
||||
onClick={openCreate}
|
||||
>
|
||||
{t('新建项目')}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
|
||||
<OrgPanel padding='p-2'>
|
||||
>
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={list}
|
||||
loading={loading}
|
||||
pagination={{ pageSize: 15, showSizeChanger: false }}
|
||||
pagination={{
|
||||
pageSize: 15,
|
||||
showSizeChanger: false,
|
||||
showTotal: (total) => t('共 {{total}} 条', { total }),
|
||||
}}
|
||||
rowKey='id'
|
||||
scroll={{ x: 1060 }}
|
||||
/>
|
||||
</OrgPanel>
|
||||
</OrgListCard>
|
||||
|
||||
{/* 项目创建/编辑 */}
|
||||
<OrgModal
|
||||
className='oc-dialog'
|
||||
width={560}
|
||||
title={editing ? t('编辑项目') : t('新建项目')}
|
||||
visible={modalVisible}
|
||||
onOk={handleSubmit}
|
||||
@@ -420,6 +449,8 @@ const OrgProjects = ({ orgId }) => {
|
||||
|
||||
{/* 项目成员管理 */}
|
||||
<OrgModal
|
||||
className='oc-dialog oc-dialog-table'
|
||||
width={760}
|
||||
title={`${t('项目成员')} - ${memberModal?.name || ''}`}
|
||||
visible={!!memberModal}
|
||||
onCancel={() => setMemberModal(null)}
|
||||
@@ -489,17 +520,18 @@ const OrgProjects = ({ orgId }) => {
|
||||
/>
|
||||
</OrgModal>
|
||||
|
||||
{/* 项目令牌绑定 */}
|
||||
{/* 项目密钥绑定 */}
|
||||
<OrgModal
|
||||
title={`${t('项目令牌')} - ${tokenModal?.name || ''}`}
|
||||
className='oc-dialog oc-dialog-table'
|
||||
title={`${t('项目密钥')} - ${tokenModal?.name || ''}`}
|
||||
visible={!!tokenModal}
|
||||
onCancel={() => setTokenModal(null)}
|
||||
footer={null}
|
||||
width={560}
|
||||
width={760}
|
||||
>
|
||||
<Table
|
||||
columns={[
|
||||
{ title: t('令牌'), dataIndex: 'name' },
|
||||
{ title: t('密钥'), dataIndex: 'name' },
|
||||
{
|
||||
title: t('当前归属'),
|
||||
dataIndex: 'project_id',
|
||||
|
||||
@@ -118,7 +118,7 @@ const PromptCallDetails = ({ orgId, groupKey }) => {
|
||||
{calls.length >= 200 ? '+' : ''})
|
||||
<span className='ml-2 font-normal text-gray-400 dark:text-gray-500'>
|
||||
{t(
|
||||
'明细为该提示词的全部调用;跨 30 分钟统计桶或多令牌时,条数可能多于本行调用次数',
|
||||
'明细为该提示词的全部调用;跨 30 分钟统计桶或多密钥时,条数可能多于本行调用次数',
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -28,17 +28,8 @@ import {
|
||||
InputNumber,
|
||||
Select,
|
||||
} from '@/components/ui';
|
||||
import {
|
||||
CreditCard,
|
||||
Wallet,
|
||||
TrendingUp,
|
||||
Coins,
|
||||
History,
|
||||
CheckCircle,
|
||||
Clock,
|
||||
XCircle,
|
||||
Pencil,
|
||||
} from 'lucide-react';
|
||||
import { Check, CheckCircle, Clock, XCircle } from 'lucide-react';
|
||||
import { Button as AntButton } from 'antd';
|
||||
import {
|
||||
API,
|
||||
showError,
|
||||
@@ -48,10 +39,11 @@ import {
|
||||
getQuotaPerUnit,
|
||||
} from '../../helpers';
|
||||
import AmountCard from '../Recharge/AmountCard';
|
||||
import usePayPalQuote from '../../hooks/common/usePayPalQuote';
|
||||
import WechatQRModal from '../../components/topup/modals/WechatQRModal';
|
||||
import PaymentConfirmModal from '../../components/topup/modals/PaymentConfirmModal';
|
||||
import OrgPageHeader from './components/OrgPageHeader';
|
||||
import OrgPanel from './components/OrgPanel';
|
||||
import '../../styles/org-center.css';
|
||||
import { orgStatusColor } from './components/orgStatus';
|
||||
import {
|
||||
formatPayPalUSD,
|
||||
@@ -61,7 +53,7 @@ import {
|
||||
removePayPalReturnState,
|
||||
} from '../../helpers/paypalPayment';
|
||||
|
||||
const { Text, Title } = Typography;
|
||||
const { Text } = Typography;
|
||||
|
||||
const OrgRecharge = ({ orgId }) => {
|
||||
const { t } = useTranslation();
|
||||
@@ -85,7 +77,6 @@ const OrgRecharge = ({ orgId }) => {
|
||||
const [confirmOpen, setConfirmOpen] = useState(false);
|
||||
const [confirmLoading, setConfirmLoading] = useState(false);
|
||||
const [amountLoading, setAmountLoading] = useState(false);
|
||||
const [payPalQuote, setPayPalQuote] = useState(null);
|
||||
|
||||
// 自定义充值(与预设档位互斥;自定义金额无折扣,原价到账)
|
||||
const [isCustomMode, setIsCustomMode] = useState(false);
|
||||
@@ -108,6 +99,22 @@ const OrgRecharge = ({ orgId }) => {
|
||||
: selectedPresetObj?.discount || 1.0;
|
||||
const effectiveBonus = isCustomMode ? 0 : selectedPresetObj?.bonus || 0;
|
||||
|
||||
const {
|
||||
quote: payPalQuote,
|
||||
setQuote: setPayPalQuote,
|
||||
loading: quoteLoading,
|
||||
refresh: refreshPayPalQuote,
|
||||
} = usePayPalQuote(
|
||||
'/api/org/topup/paypal/amount',
|
||||
isCustomMode
|
||||
? { custom_amount: customEffectiveAmount }
|
||||
: { amount_option_id: selectedPresetObj?.id },
|
||||
payWay === 'paypal' &&
|
||||
effectiveAmountYuan > 0 &&
|
||||
(!isCustomMode || customValid),
|
||||
orgId,
|
||||
);
|
||||
|
||||
// 微信二维码
|
||||
const [wechatQRVisible, setWechatQRVisible] = useState(false);
|
||||
const [wechatOrderData, setWechatOrderData] = useState(null);
|
||||
@@ -292,15 +299,7 @@ const OrgRecharge = ({ orgId }) => {
|
||||
}
|
||||
setAmountLoading(true);
|
||||
try {
|
||||
const response = await API.post(
|
||||
'/api/org/topup/paypal/amount',
|
||||
buildPayBody(),
|
||||
{ headers: orgHeaders },
|
||||
);
|
||||
if (!response.data.success) {
|
||||
throw new Error(response.data.message || t('获取金额失败'));
|
||||
}
|
||||
setPayPalQuote(parsePayPalQuote(response));
|
||||
if (!(await refreshPayPalQuote())) return;
|
||||
} catch (error) {
|
||||
showError(error?.message || t('获取金额失败'));
|
||||
return;
|
||||
@@ -456,8 +455,8 @@ const OrgRecharge = ({ orgId }) => {
|
||||
return (
|
||||
<Tag
|
||||
color={orgStatusColor(status)}
|
||||
size='small'
|
||||
className='flex items-center gap-1'
|
||||
bordered={false}
|
||||
className='oc-recharge-status'
|
||||
>
|
||||
{s.icon}
|
||||
{s.text}
|
||||
@@ -469,341 +468,317 @@ const OrgRecharge = ({ orgId }) => {
|
||||
{
|
||||
title: t('订单号'),
|
||||
dataIndex: 'trade_no',
|
||||
render: (v) => (
|
||||
<Text size='small' className='font-mono'>
|
||||
{v}
|
||||
</Text>
|
||||
),
|
||||
width: 320,
|
||||
ellipsis: true,
|
||||
render: (v) => <span className='oc-rc-order-id'>{v}</span>,
|
||||
},
|
||||
{
|
||||
title: t('金额'),
|
||||
dataIndex: 'money',
|
||||
render: (v) => <Text size='small'>¥{Number(v).toFixed(2)}</Text>,
|
||||
width: 90,
|
||||
width: 140,
|
||||
render: (v) => `¥${Number(v).toFixed(2)}`,
|
||||
},
|
||||
{
|
||||
title: t('获得额度'),
|
||||
dataIndex: 'amount',
|
||||
render: (v) => <Text size='small'>{renderQuota(v)}</Text>,
|
||||
width: 110,
|
||||
width: 140,
|
||||
render: (v) => renderQuota(v),
|
||||
},
|
||||
{
|
||||
title: t('支付方式'),
|
||||
dataIndex: 'payment_channel',
|
||||
render: (v) => (
|
||||
<Text size='small'>
|
||||
{v === 'paypal_checkout' ? 'PayPal' : v || '-'}
|
||||
</Text>
|
||||
),
|
||||
width: 110,
|
||||
width: 120,
|
||||
render: (v) => (v === 'paypal_checkout' ? 'PayPal' : v || '-'),
|
||||
},
|
||||
{
|
||||
title: t('状态'),
|
||||
dataIndex: 'status',
|
||||
width: 110,
|
||||
render: (v) => renderStatus(v),
|
||||
width: 90,
|
||||
},
|
||||
{
|
||||
title: t('时间'),
|
||||
dataIndex: 'create_time',
|
||||
render: (v) => <Text size='small'>{timestamp2string(v)}</Text>,
|
||||
width: 160,
|
||||
width: 190,
|
||||
render: (v) => timestamp2string(v),
|
||||
},
|
||||
];
|
||||
|
||||
const hasAnyPayment =
|
||||
enableWechatTopUp || enableAlipayTopUp || enablePayPalTopUp;
|
||||
|
||||
// 充值订单卡(原型 .rp-checkout):展示当前选择的到账额度 / 支付方式 / 应付金额;
|
||||
// “立即充值”与点击支付方式相同,进入原有 handlePreTopUp 预充值校验与确认弹窗
|
||||
const selectedMethod = payMethods.find((m) => m.type === payWay);
|
||||
const quotaPerUnit = getQuotaPerUnit() || 500000;
|
||||
// 到账额度:自定义沿用原实时预览 customPreviewQuota;档位与确认弹窗 renderQuotaWithAmount 同口径
|
||||
const arrivalQuota =
|
||||
effectiveAmountYuan <= 0
|
||||
? '-'
|
||||
: isCustomMode
|
||||
? renderQuota(customPreviewQuota)
|
||||
: renderQuota(effectiveAmountYuan * quotaPerUnit + effectiveBonus);
|
||||
const payableYuan = effectiveAmountYuan * effectiveDiscount;
|
||||
const payableValue =
|
||||
payWay === 'paypal' ? payPalQuote?.payAmount : payableYuan;
|
||||
const canCheckout =
|
||||
effectiveAmountYuan > 0 &&
|
||||
(!isCustomMode || customValid) &&
|
||||
Boolean(selectedMethod) &&
|
||||
!amountLoading &&
|
||||
!quoteLoading &&
|
||||
(payWay !== 'paypal' || Boolean(payPalQuote));
|
||||
const customInvalid = customEffectiveAmount > 0 && !customValid;
|
||||
|
||||
const renderPayIcon = (type) =>
|
||||
type === 'wxpay' ? (
|
||||
<i className='oc-pay-dot' aria-hidden='true' />
|
||||
) : type === 'paypal' ? (
|
||||
<strong className='oc-pay-pal' aria-hidden='true'>
|
||||
P
|
||||
</strong>
|
||||
) : null;
|
||||
|
||||
return (
|
||||
<div className='uc-page space-y-6'>
|
||||
<div className='uc-page oc-page oc-recharge'>
|
||||
<OrgPageHeader title={t('企业充值')} subtitle={t('为企业账户充值额度')} />
|
||||
|
||||
{/* 签名时刻:余额展示区(本页唯一的品牌渐变区,渐变走 --brand-* token 随预设切换) */}
|
||||
<div className='relative overflow-hidden bg-gradient-to-r from-brand-from via-brand-via to-brand-to rounded-xl p-5 shadow-[var(--elevation-md)]'>
|
||||
<div className='flex items-center justify-between gap-4 flex-wrap'>
|
||||
<div className='flex items-center gap-3'>
|
||||
<div className='p-2 bg-white/15 rounded-lg'>
|
||||
<Wallet size={20} className='text-white' />
|
||||
<div className='oc-rc-layout'>
|
||||
{/* 企业钱包(原型 .rlc-account-rail) */}
|
||||
<aside className='oc-rc-rail'>
|
||||
<h2>{t('企业钱包')}</h2>
|
||||
<div className='oc-rc-rule' />
|
||||
<div className='oc-rc-account'>
|
||||
<div>
|
||||
<span>{t('企业可用余额')}</span>
|
||||
<strong className='oc-rc-balance'>{renderQuota(orgQuota)}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<Text className='!text-white/80 text-xs font-medium block'>
|
||||
{t('企业可用余额')}
|
||||
</Text>
|
||||
<Title heading={4} className='!text-white !mb-0 tabular-nums'>
|
||||
{renderQuota(orgQuota)}
|
||||
</Title>
|
||||
<span>{t('累计消耗')}</span>
|
||||
<strong>{renderQuota(orgUsedQuota)}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div className='w-px h-10 bg-white/20 flex-shrink-0' />
|
||||
<div className='flex items-center gap-3'>
|
||||
<div className='p-2 bg-white/10 rounded-lg'>
|
||||
<TrendingUp size={18} className='text-white/80' />
|
||||
</div>
|
||||
<div>
|
||||
<Text className='!text-white/60 text-xs block'>
|
||||
{t('累计消耗')}
|
||||
</Text>
|
||||
<Text className='!text-white font-semibold text-sm tabular-nums'>
|
||||
{renderQuota(orgUsedQuota)}
|
||||
</Text>
|
||||
</div>
|
||||
<div className='oc-rc-rail-foot'>
|
||||
<i aria-hidden='true' />
|
||||
<span>{t('余额用于模型调用')}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
{/* 充值区域 */}
|
||||
<OrgPanel icon={Coins} title={t('选择充值档位')}>
|
||||
{infoLoading ? (
|
||||
<div className='py-10 flex justify-center'>
|
||||
<Spin />
|
||||
</div>
|
||||
) : presetAmounts.length > 0 ? (
|
||||
<>
|
||||
<div className='grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-2.5 mb-4'>
|
||||
{presetAmounts.map((preset, idx) => (
|
||||
<AmountCard
|
||||
key={idx}
|
||||
preset={preset}
|
||||
selected={selectedPreset === preset.id}
|
||||
onClick={() => selectPreset(preset)}
|
||||
topupInfo={{ amount_options: [], discount: {} }}
|
||||
priceRatio={1}
|
||||
t={t}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
{/* 充值工作区(原型 .rlc-workspace) */}
|
||||
<section className='oc-rc-workspace'>
|
||||
<header className='oc-rc-workspace-head'>
|
||||
<h2>{t('为下一次调用补充能量')}</h2>
|
||||
<p>{t('为企业账户补充额度,支持团队持续调用模型。')}</p>
|
||||
</header>
|
||||
|
||||
{/* 自定义充值(与档位互斥;自定义金额无折扣,原价到账) */}
|
||||
<div
|
||||
className={`mb-5 rounded-xl border-2 border-dashed transition-all ${
|
||||
isCustomMode
|
||||
? 'border-emerald-400 bg-gradient-to-br from-emerald-50/60 to-emerald-50/25 dark:from-emerald-900/15 dark:to-emerald-900/10 dark:border-emerald-600 shadow-sm shadow-emerald-500/5'
|
||||
: 'border-gray-200 dark:border-neutral-700 hover:border-emerald-300 dark:hover:border-emerald-700'
|
||||
}`}
|
||||
>
|
||||
{/* 头部 */}
|
||||
<div className='px-4 pt-3.5 pb-2.5 flex items-center justify-between flex-wrap gap-1.5'>
|
||||
<div className='flex items-center gap-1.5'>
|
||||
<div className='p-1 rounded-md bg-emerald-100 dark:bg-emerald-900/40'>
|
||||
<Pencil
|
||||
size={12}
|
||||
className='text-emerald-600 dark:text-emerald-400'
|
||||
{infoLoading ? (
|
||||
<div className='oc-rc-loading'>
|
||||
<Spin />
|
||||
</div>
|
||||
) : presetAmounts.length > 0 ? (
|
||||
<div className='oc-rc-purchase'>
|
||||
<div className='oc-rc-content'>
|
||||
<div className='oc-rc-section-heading'>
|
||||
<h3>{t('选择充值额度')}</h3>
|
||||
<p>{t('为企业账户充值,额度用于团队模型调用。')}</p>
|
||||
</div>
|
||||
<div className='oc-rc-amount-grid'>
|
||||
{presetAmounts.map((preset, idx) => (
|
||||
<AmountCard
|
||||
key={idx}
|
||||
preset={preset}
|
||||
selected={selectedPreset === preset.id}
|
||||
onClick={() => selectPreset(preset)}
|
||||
topupInfo={{ amount_options: [], discount: {} }}
|
||||
priceRatio={1}
|
||||
t={t}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* 自定义充值(与档位互斥;自定义金额无折扣,原价到账) */}
|
||||
<div
|
||||
className={`oc-rc-custom${isCustomMode ? ' selected' : ''}`}
|
||||
>
|
||||
<h3>
|
||||
{t('自定义充值')}
|
||||
{isCustomMode && (
|
||||
<Tag color='green' bordered={false}>
|
||||
{t('已选')}
|
||||
</Tag>
|
||||
)}
|
||||
</h3>
|
||||
<div className='oc-rc-custom-input'>
|
||||
<InputNumber
|
||||
value={customAmount}
|
||||
onChange={handleCustomAmountChange}
|
||||
min={1}
|
||||
precision={0}
|
||||
hideButtons
|
||||
placeholder={t('请输入整数,如 1、5、10')}
|
||||
status={customInvalid ? 'error' : undefined}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
<Select
|
||||
value={customUnit}
|
||||
onChange={handleCustomUnitChange}
|
||||
optionList={[
|
||||
{ label: t('千'), value: 1000 },
|
||||
{ label: t('万'), value: 10000 },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
<Text
|
||||
strong
|
||||
className='text-gray-800 dark:text-gray-200 text-sm'
|
||||
<div className='oc-rc-quick'>
|
||||
<span>{t('快速选择:')}</span>
|
||||
{customQuickPicks.map((pick) => {
|
||||
const active =
|
||||
isCustomMode &&
|
||||
Number(customAmount) === pick.amount &&
|
||||
customUnit === pick.unit;
|
||||
return (
|
||||
<AntButton
|
||||
key={`${pick.amount}-${pick.unit}`}
|
||||
size='small'
|
||||
aria-pressed={active}
|
||||
className={active ? 'is-active' : ''}
|
||||
onClick={() =>
|
||||
applyCustomQuickPick(pick.amount, pick.unit)
|
||||
}
|
||||
>
|
||||
{`${pick.amount}${pick.unit === 1000 ? t('千') : t('万')}`}
|
||||
</AntButton>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{/* 底部说明(金额不达标时变为错误提示) */}
|
||||
<p
|
||||
className={customInvalid ? 'oc-rc-error' : ''}
|
||||
role={customInvalid ? 'alert' : undefined}
|
||||
>
|
||||
{t('自定义充值')}
|
||||
</Text>
|
||||
{isCustomMode && (
|
||||
<Tag color='green' size='small'>
|
||||
{t('已选')}
|
||||
</Tag>
|
||||
{customInvalid
|
||||
? `${t('当前 ¥')}${customEffectiveAmount.toLocaleString()}${t(',未达到最低 ¥1,000')}`
|
||||
: `${t('最少 1000 元,必须为 1000 元的整倍数')};${t('原价到账,不参与折扣')}`}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* 支付方式(点击沿用 handlePreTopUp:校验后进入确认弹窗) */}
|
||||
<div className='oc-rc-pay'>
|
||||
<h3>{t('支付方式')}</h3>
|
||||
{hasAnyPayment ? (
|
||||
<div className='oc-rc-pay-methods'>
|
||||
{payMethods.map((method) => {
|
||||
const isWechat = method.type === 'wxpay';
|
||||
const isAlipay = method.type === 'alipay';
|
||||
const isPayPal = method.type === 'paypal';
|
||||
const disabled =
|
||||
(isWechat && !enableWechatTopUp) ||
|
||||
(isAlipay && !enableAlipayTopUp) ||
|
||||
(isPayPal && !enablePayPalTopUp);
|
||||
const selected = payWay === method.type;
|
||||
return (
|
||||
<AntButton
|
||||
key={method.type}
|
||||
disabled={disabled}
|
||||
loading={amountLoading && selected}
|
||||
aria-pressed={selected}
|
||||
icon={renderPayIcon(method.type)}
|
||||
className={`oc-rc-pay-method${selected ? ' is-selected' : ''}`}
|
||||
onClick={() => handlePreTopUp(method.type)}
|
||||
>
|
||||
{method.name}
|
||||
{selected && <Check size={14} />}
|
||||
</AntButton>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<p className='oc-rc-pay-empty'>
|
||||
{t('暂无可用的支付方式,请联系管理员配置')}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<Text type='tertiary' size='small'>
|
||||
{t('原价到账,不参与折扣')}
|
||||
</Text>
|
||||
</div>
|
||||
|
||||
{/* 输入区 */}
|
||||
<div className='px-4 pb-3'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<InputNumber
|
||||
value={customAmount}
|
||||
onChange={handleCustomAmountChange}
|
||||
min={1}
|
||||
precision={0}
|
||||
hideButtons
|
||||
size='large'
|
||||
placeholder={t('请输入整数,如 1、5、10')}
|
||||
className='!flex-1'
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
<Select
|
||||
value={customUnit}
|
||||
onChange={handleCustomUnitChange}
|
||||
size='large'
|
||||
style={{ width: 96 }}
|
||||
optionList={[
|
||||
{ label: t('千'), value: 1000 },
|
||||
{ label: t('万'), value: 10000 },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 快速选择 */}
|
||||
<div className='mt-2.5 flex items-center gap-1.5 flex-wrap'>
|
||||
<Text
|
||||
type='tertiary'
|
||||
size='small'
|
||||
className='!text-xs flex-shrink-0'
|
||||
>
|
||||
{t('快速选择:')}
|
||||
</Text>
|
||||
{customQuickPicks.map((pick) => {
|
||||
const active =
|
||||
isCustomMode &&
|
||||
Number(customAmount) === pick.amount &&
|
||||
customUnit === pick.unit;
|
||||
const label = `${pick.amount}${pick.unit === 1000 ? t('千') : t('万')}`;
|
||||
return (
|
||||
<button
|
||||
key={`${pick.amount}-${pick.unit}`}
|
||||
type='button'
|
||||
onClick={() =>
|
||||
applyCustomQuickPick(pick.amount, pick.unit)
|
||||
}
|
||||
className={`px-2.5 py-0.5 rounded-md text-xs font-medium transition-colors border ${
|
||||
active
|
||||
? 'bg-emerald-500 text-white border-emerald-500 shadow-sm shadow-emerald-500/20'
|
||||
: 'bg-white dark:bg-neutral-800 text-gray-600 dark:text-gray-300 border-gray-200 dark:border-neutral-700 hover:border-emerald-300 hover:text-emerald-600 dark:hover:border-emerald-700 dark:hover:text-emerald-400'
|
||||
}`}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 实时预览(仅在金额合法时显示) */}
|
||||
{customEffectiveAmount > 0 && customValid && (
|
||||
<div className='mx-4 mb-3 rounded-lg p-3 bg-[var(--surface-card)] border border-[var(--border-subtle)]'>
|
||||
<div className='flex items-center justify-between gap-3 flex-wrap'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<div className='w-7 h-7 rounded-lg bg-rose-500/10 text-rose-600 dark:text-rose-400 flex items-center justify-center'>
|
||||
<Wallet size={14} />
|
||||
</div>
|
||||
<div>
|
||||
<Text
|
||||
type='tertiary'
|
||||
size='small'
|
||||
className='!text-xs block leading-tight'
|
||||
>
|
||||
{t('实付金额')}
|
||||
</Text>
|
||||
<Text
|
||||
strong
|
||||
className='!text-rose-600 dark:!text-rose-400 text-base leading-tight'
|
||||
>
|
||||
¥{customEffectiveAmount.toLocaleString()}
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
<div className='flex items-center gap-2'>
|
||||
<div className='w-7 h-7 rounded-lg bg-amber-500/10 text-amber-600 dark:text-amber-400 flex items-center justify-center'>
|
||||
<Coins size={14} />
|
||||
</div>
|
||||
<div className='text-right'>
|
||||
<Text
|
||||
type='tertiary'
|
||||
size='small'
|
||||
className='!text-xs block leading-tight'
|
||||
>
|
||||
{t('获得额度')}
|
||||
</Text>
|
||||
<Text
|
||||
strong
|
||||
className='!text-amber-600 dark:!text-amber-400 text-base leading-tight'
|
||||
>
|
||||
{renderQuota(customPreviewQuota)}
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
{/* 企业充值订单(原型 .rlc-checkout-card) */}
|
||||
<aside className='oc-rc-checkout'>
|
||||
<h3>{t('企业充值订单')}</h3>
|
||||
<dl>
|
||||
<div>
|
||||
<dt>{t('到账额度')}</dt>
|
||||
<dd>{arrivalQuota}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>{t('优惠金额')}</dt>
|
||||
<dd>¥{(effectiveAmountYuan - payableYuan).toFixed(2)}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>{t('支付方式')}</dt>
|
||||
<dd>{selectedMethod?.name || '-'}</dd>
|
||||
</div>
|
||||
{payWay === 'paypal' && payPalQuote && (
|
||||
<div>
|
||||
<dt>{t('支付服务费')}</dt>
|
||||
<dd>{formatPayPalUSD(payPalQuote.serviceFee)}</dd>
|
||||
</div>
|
||||
)}
|
||||
</dl>
|
||||
<div className='oc-rc-payable'>
|
||||
<span>{t('应付金额')}</span>
|
||||
<strong>
|
||||
{payableValue > 0 ? (
|
||||
<>
|
||||
<span>{payWay === 'paypal' ? '$' : '¥'}</span>
|
||||
<b>
|
||||
{payableValue.toLocaleString('en-US', {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
})}
|
||||
</b>
|
||||
{payWay === 'paypal' && <span> USD</span>}
|
||||
</>
|
||||
) : (
|
||||
'-'
|
||||
)}
|
||||
</strong>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 底部说明(金额不达标时变橙色) */}
|
||||
<div className='px-4 pb-3'>
|
||||
<Text
|
||||
size='small'
|
||||
className={`!text-xs ${
|
||||
customEffectiveAmount > 0 && !customValid
|
||||
? '!text-amber-600 dark:!text-amber-400'
|
||||
: '!text-gray-400 dark:!text-gray-500'
|
||||
}`}
|
||||
<Button
|
||||
type='primary'
|
||||
size='large'
|
||||
block
|
||||
disabled={!canCheckout}
|
||||
loading={amountLoading || quoteLoading}
|
||||
onClick={() => handlePreTopUp(payWay)}
|
||||
>
|
||||
{customEffectiveAmount > 0 && !customValid
|
||||
? `${t('当前 ¥')}${customEffectiveAmount.toLocaleString()}${t(',未达到最低 ¥1,000')}`
|
||||
: t('最少 1000 元,必须为 1000 元的整倍数')}
|
||||
</Text>
|
||||
</div>
|
||||
{t('立即充值')}
|
||||
</Button>
|
||||
</aside>
|
||||
</div>
|
||||
) : (
|
||||
<p className='oc-rc-pay-empty'>
|
||||
{t('暂无充值档位,请联系管理员配置')}
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
{/* 支付方式 */}
|
||||
<div className='flex items-center gap-2 mb-3'>
|
||||
<div className='p-1.5 rounded-lg bg-brand/10 text-brand'>
|
||||
<CreditCard size={14} />
|
||||
</div>
|
||||
<Text strong className='text-gray-800 dark:text-gray-200'>
|
||||
{t('支付方式')}
|
||||
</Text>
|
||||
</div>
|
||||
|
||||
{hasAnyPayment ? (
|
||||
<div className='flex flex-wrap gap-3'>
|
||||
{payMethods.map((method) => {
|
||||
const isWechat = method.type === 'wxpay';
|
||||
const isAlipay = method.type === 'alipay';
|
||||
const isPayPal = method.type === 'paypal';
|
||||
const disabled =
|
||||
(isWechat && !enableWechatTopUp) ||
|
||||
(isAlipay && !enableAlipayTopUp) ||
|
||||
(isPayPal && !enablePayPalTopUp);
|
||||
return (
|
||||
<Button
|
||||
key={method.type}
|
||||
theme={payWay === method.type ? 'solid' : 'light'}
|
||||
type={payWay === method.type ? 'primary' : 'tertiary'}
|
||||
disabled={disabled}
|
||||
loading={amountLoading && payWay === method.type}
|
||||
onClick={() => handlePreTopUp(method.type)}
|
||||
className={`!rounded-lg !px-5 !py-2.5 !h-auto transition-colors ${
|
||||
payWay === method.type
|
||||
? ''
|
||||
: 'hover:!bg-brand/5 dark:hover:!bg-brand-deep/20 hover:!border-brand-from'
|
||||
}`}
|
||||
>
|
||||
{method.name}
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<Text type='tertiary' size='small'>
|
||||
{t('暂无可用的支付方式,请联系管理员配置')}
|
||||
</Text>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<Text type='tertiary'>{t('暂无充值档位,请联系管理员配置')}</Text>
|
||||
)}
|
||||
</OrgPanel>
|
||||
|
||||
{/* 充值记录 */}
|
||||
<OrgPanel
|
||||
icon={History}
|
||||
title={t('充值记录')}
|
||||
bodyClassName='overflow-x-auto'
|
||||
>
|
||||
{/* 充值记录(原型 .rlc-history) */}
|
||||
<section className='oc-rc-history' aria-label={t('充值记录')}>
|
||||
<Table
|
||||
rowKey={(record) => record.id ?? record.trade_no}
|
||||
columns={historyColumns}
|
||||
dataSource={history}
|
||||
loading={historyLoading}
|
||||
scroll={{ x: 900 }}
|
||||
pagination={{
|
||||
currentPage: historyPage,
|
||||
total: historyTotal,
|
||||
pageSize: 10,
|
||||
onPageChange: setHistoryPage,
|
||||
showTotal: (n) => t('共 {{total}} 条', { total: n }),
|
||||
}}
|
||||
size='small'
|
||||
empty={<Text type='tertiary'>{t('暂无充值记录')}</Text>}
|
||||
/>
|
||||
</OrgPanel>
|
||||
</section>
|
||||
|
||||
{/* 支付确认弹窗 */}
|
||||
<PaymentConfirmModal
|
||||
@@ -823,7 +798,7 @@ const OrgRecharge = ({ orgId }) => {
|
||||
const baseQuota = effectiveAmountYuan * quotaPerUnit;
|
||||
return renderQuota(baseQuota + effectiveBonus);
|
||||
}}
|
||||
amountLoading={amountLoading}
|
||||
amountLoading={amountLoading || quoteLoading}
|
||||
renderAmount={renderAmount}
|
||||
payWay={payWay}
|
||||
payMethods={payMethods}
|
||||
|
||||
@@ -18,21 +18,14 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Table,
|
||||
Button,
|
||||
Tag,
|
||||
Toast,
|
||||
Input,
|
||||
Empty,
|
||||
Popconfirm,
|
||||
} from '@/components/ui';
|
||||
import { RefreshCw, Check, X } from 'lucide-react';
|
||||
import { Form as AntForm, Tabs as AntTabs } from 'antd';
|
||||
import { Table, Button, Tag, Toast, Input, Popconfirm } from '@/components/ui';
|
||||
import { RefreshCw } from 'lucide-react';
|
||||
import { API } from '../../helpers/api';
|
||||
import { showError, collectPagedItems } from '../../helpers';
|
||||
import { renderQuota } from '../../helpers/render';
|
||||
import OrgPageHeader from './components/OrgPageHeader';
|
||||
import OrgPanel from './components/OrgPanel';
|
||||
import { OrgListCard, OrgRowActions } from './components/OrgListCard';
|
||||
import OrgModal from './components/OrgModal';
|
||||
import { orgStatusColor } from './components/orgStatus';
|
||||
|
||||
@@ -56,7 +49,11 @@ const statusTag = (t, s) => {
|
||||
expired: { x: t('已过期') },
|
||||
};
|
||||
const v = m[s] || { x: s };
|
||||
return <Tag color={orgStatusColor(s)}>{v.x}</Tag>;
|
||||
return (
|
||||
<Tag color={orgStatusColor(s)} bordered={false}>
|
||||
{v.x}
|
||||
</Tag>
|
||||
);
|
||||
};
|
||||
|
||||
const parseDelta = (payload) => {
|
||||
@@ -135,8 +132,9 @@ const OrgRequests = ({ orgId, orgRole, featureFlags }) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 列宽与渲染对齐原型 EnterpriseApprovals(80/90/210/140/300/120/130,scroll.x 1080)
|
||||
const columns = [
|
||||
{ title: 'ID', dataIndex: 'id', width: 60 },
|
||||
{ title: 'ID', dataIndex: 'id', width: 80 },
|
||||
{
|
||||
title: t('类型'),
|
||||
dataIndex: 'request_type',
|
||||
@@ -145,7 +143,7 @@ const OrgRequests = ({ orgId, orgRole, featureFlags }) => {
|
||||
},
|
||||
{
|
||||
title: t('对象'),
|
||||
width: 160,
|
||||
width: 210,
|
||||
ellipsis: true,
|
||||
render: (_, r) => {
|
||||
const label =
|
||||
@@ -153,7 +151,7 @@ const OrgRequests = ({ orgId, orgRole, featureFlags }) => {
|
||||
project: t('项目'),
|
||||
department: t('部门'),
|
||||
member: t('成员'),
|
||||
token: t('令牌'),
|
||||
token: t('密钥'),
|
||||
org: t('企业'),
|
||||
}[r.subject_type] || r.subject_type;
|
||||
// 后端已富化 subject_name;主体被删除等极端情况回退为 #ID
|
||||
@@ -164,25 +162,34 @@ const OrgRequests = ({ orgId, orgRole, featureFlags }) => {
|
||||
},
|
||||
{
|
||||
title: t('提额'),
|
||||
width: 110,
|
||||
render: (_, r) =>
|
||||
r.request_type === 'quota'
|
||||
? renderQuota(parseDelta(r.payload), 2)
|
||||
: '-',
|
||||
width: 140,
|
||||
render: (_, r) => (
|
||||
<span className='oc-number'>
|
||||
{r.request_type === 'quota'
|
||||
? renderQuota(parseDelta(r.payload), 2)
|
||||
: '-'}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('理由'),
|
||||
dataIndex: 'reason',
|
||||
width: 300,
|
||||
ellipsis: true,
|
||||
render: (v) => v || '-',
|
||||
},
|
||||
{ title: t('理由'), dataIndex: 'reason', ellipsis: true },
|
||||
{
|
||||
title: t('状态'),
|
||||
dataIndex: 'status',
|
||||
width: 90,
|
||||
width: 120,
|
||||
render: (v) => statusTag(t, v),
|
||||
},
|
||||
{
|
||||
title: t('操作'),
|
||||
width: 220,
|
||||
width: 130,
|
||||
render: (_, r) =>
|
||||
isApprover && r.status === 'pending' ? (
|
||||
<div className='flex items-center gap-2'>
|
||||
<OrgRowActions>
|
||||
<Popconfirm
|
||||
title={t('确认通过该提额申请?')}
|
||||
content={
|
||||
@@ -206,27 +213,14 @@ const OrgRequests = ({ orgId, orgRole, featureFlags }) => {
|
||||
position='topRight'
|
||||
onConfirm={() => decide(r.id, 'approved')}
|
||||
>
|
||||
<Button
|
||||
size='small'
|
||||
theme='solid'
|
||||
type='primary'
|
||||
icon={<Check size={14} />}
|
||||
>
|
||||
{t('通过')}
|
||||
</Button>
|
||||
<Button type='link'>{t('通过')}</Button>
|
||||
</Popconfirm>
|
||||
<Button
|
||||
size='small'
|
||||
theme='light'
|
||||
type='danger'
|
||||
icon={<X size={14} />}
|
||||
onClick={() => setRejectFor(r.id)}
|
||||
>
|
||||
<Button type='link' danger onClick={() => setRejectFor(r.id)}>
|
||||
{t('拒绝')}
|
||||
</Button>
|
||||
</div>
|
||||
</OrgRowActions>
|
||||
) : (
|
||||
<span className='text-xs text-gray-400'>-</span>
|
||||
'-'
|
||||
),
|
||||
},
|
||||
];
|
||||
@@ -234,56 +228,60 @@ const OrgRequests = ({ orgId, orgRole, featureFlags }) => {
|
||||
const filters = ['pending', 'approved', 'rejected', ''];
|
||||
|
||||
return (
|
||||
<div className='uc-page'>
|
||||
<div className='uc-page oc-page'>
|
||||
<OrgPageHeader
|
||||
title={isApprover ? t('审批中心') : t('我的申请')}
|
||||
subtitle={t('提额申请与审批')}
|
||||
actions={
|
||||
/>
|
||||
|
||||
{/* 原型 platform-list-tabs:状态筛选页签(只切换筛选,不承载内容),回调沿用 setStatusFilter */}
|
||||
<AntTabs
|
||||
className='oc-list-tabs oc-tabs-nav-only'
|
||||
activeKey={statusFilter || 'all'}
|
||||
onChange={(key) => setStatusFilter(key === 'all' ? '' : key)}
|
||||
items={filters.map((f) => ({
|
||||
key: f || 'all',
|
||||
label:
|
||||
f === 'pending'
|
||||
? t('待审批')
|
||||
: f === 'approved'
|
||||
? t('已通过')
|
||||
: f === 'rejected'
|
||||
? t('已拒绝')
|
||||
: t('全部'),
|
||||
}))}
|
||||
/>
|
||||
|
||||
<OrgListCard
|
||||
title={t('申请列表')}
|
||||
tools={
|
||||
<Button
|
||||
theme='light'
|
||||
icon={<RefreshCw size={14} />}
|
||||
icon={<RefreshCw size={16} />}
|
||||
loading={loading}
|
||||
onClick={fetchList}
|
||||
>
|
||||
{t('刷新')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
|
||||
<div className='flex items-center gap-2 mb-3'>
|
||||
{filters.map((f) => (
|
||||
<Button
|
||||
key={f || 'all'}
|
||||
size='small'
|
||||
theme={statusFilter === f ? 'solid' : 'light'}
|
||||
onClick={() => setStatusFilter(f)}
|
||||
>
|
||||
{f === 'pending'
|
||||
? t('待审批')
|
||||
: f === 'approved'
|
||||
? t('已通过')
|
||||
: f === 'rejected'
|
||||
? t('已拒绝')
|
||||
: t('全部')}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<OrgPanel padding='p-2'>
|
||||
{list.length === 0 && !loading ? (
|
||||
<Empty description={t('暂无申请')} style={{ padding: 40 }} />
|
||||
) : (
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={list}
|
||||
loading={loading}
|
||||
pagination={{ pageSize: 15, showSizeChanger: false }}
|
||||
rowKey='id'
|
||||
/>
|
||||
)}
|
||||
</OrgPanel>
|
||||
>
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={list}
|
||||
loading={loading}
|
||||
empty={t('暂无申请')}
|
||||
pagination={{
|
||||
pageSize: 15,
|
||||
showSizeChanger: false,
|
||||
showTotal: (total) => t('共 {{total}} 条', { total }),
|
||||
}}
|
||||
rowKey='id'
|
||||
scroll={{ x: 1080 }}
|
||||
/>
|
||||
</OrgListCard>
|
||||
|
||||
<OrgModal
|
||||
className='oc-dialog oc-reject-dialog'
|
||||
width={520}
|
||||
title={t('拒绝申请')}
|
||||
visible={!!rejectFor}
|
||||
onOk={() => decide(rejectFor, 'rejected', rejectComment)}
|
||||
@@ -294,11 +292,16 @@ const OrgRequests = ({ orgId, orgRole, featureFlags }) => {
|
||||
okText={t('确认拒绝')}
|
||||
cancelText={t('取消')}
|
||||
>
|
||||
<Input
|
||||
placeholder={t('拒绝理由(可选)')}
|
||||
value={rejectComment}
|
||||
onChange={setRejectComment}
|
||||
/>
|
||||
{/* 原型:竖排表单项“拒绝理由(可选)”;仅布局,取值与提交沿用 rejectComment / decide */}
|
||||
<AntForm layout='vertical' requiredMark={false} component='div'>
|
||||
<AntForm.Item label={t('拒绝理由(可选)')}>
|
||||
<Input
|
||||
placeholder={t('请输入拒绝理由')}
|
||||
value={rejectComment}
|
||||
onChange={setRejectComment}
|
||||
/>
|
||||
</AntForm.Item>
|
||||
</AntForm>
|
||||
</OrgModal>
|
||||
</div>
|
||||
);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -20,8 +20,7 @@ import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { Link, useLocation } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
BarChart2,
|
||||
Users,
|
||||
BarChart3,
|
||||
Key,
|
||||
FileSearch,
|
||||
Receipt,
|
||||
@@ -29,15 +28,11 @@ import {
|
||||
ChevronDown,
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
Building2,
|
||||
Search,
|
||||
X,
|
||||
CreditCard,
|
||||
Network,
|
||||
FolderKanban,
|
||||
Folder,
|
||||
LayoutGrid,
|
||||
Wallet,
|
||||
FileClock,
|
||||
UserRound,
|
||||
BrainCircuit,
|
||||
LibraryBig,
|
||||
@@ -47,7 +42,8 @@ import {
|
||||
ShieldCheck,
|
||||
Cable,
|
||||
Gauge,
|
||||
Sparkles,
|
||||
Zap,
|
||||
Check,
|
||||
Activity,
|
||||
} from 'lucide-react';
|
||||
import { useSidebarCollapsed } from '../../hooks/common/useSidebarCollapsed';
|
||||
@@ -176,7 +172,7 @@ const OrgSidebar = ({
|
||||
// 让「AI 能力管理」成为纯管理员分组。
|
||||
itemKey: '/org/my-capabilities',
|
||||
text: t('我的 AI 能力'),
|
||||
icon: Sparkles,
|
||||
icon: Zap,
|
||||
group: 'overview',
|
||||
},
|
||||
{
|
||||
@@ -237,14 +233,14 @@ const OrgSidebar = ({
|
||||
{
|
||||
itemKey: '/org/dashboard',
|
||||
text: t('数据看板'),
|
||||
icon: BarChart2,
|
||||
icon: BarChart3,
|
||||
group: 'overview',
|
||||
adminOnly: true,
|
||||
},
|
||||
{
|
||||
itemKey: '/org/members',
|
||||
text: t('员工管理'),
|
||||
icon: Users,
|
||||
icon: UserRound,
|
||||
group: 'org',
|
||||
adminOnly: true,
|
||||
},
|
||||
@@ -258,13 +254,13 @@ const OrgSidebar = ({
|
||||
{
|
||||
itemKey: '/org/project-manage',
|
||||
text: t('我的项目'),
|
||||
icon: FolderKanban,
|
||||
icon: Folder,
|
||||
group: 'org',
|
||||
projectScope: true,
|
||||
},
|
||||
{
|
||||
itemKey: '/org/departments',
|
||||
text: t('部门管理'),
|
||||
text: t('组织架构'),
|
||||
icon: Network,
|
||||
group: 'org',
|
||||
adminOnly: true,
|
||||
@@ -272,7 +268,7 @@ const OrgSidebar = ({
|
||||
{
|
||||
itemKey: '/org/projects',
|
||||
text: t('项目管理'),
|
||||
icon: FolderKanban,
|
||||
icon: Folder,
|
||||
group: 'org',
|
||||
adminOnly: true,
|
||||
},
|
||||
@@ -286,12 +282,12 @@ const OrgSidebar = ({
|
||||
{
|
||||
itemKey: '/org/requests',
|
||||
text: isAdmin ? t('审批中心') : t('我的申请'),
|
||||
icon: FileClock,
|
||||
icon: Check,
|
||||
group: 'governance',
|
||||
},
|
||||
{
|
||||
itemKey: '/org/tokens',
|
||||
text: t('令牌管理'),
|
||||
text: t('密钥管理'),
|
||||
icon: Key,
|
||||
group: 'governance',
|
||||
},
|
||||
@@ -448,20 +444,7 @@ const OrgSidebar = ({
|
||||
[groups, items],
|
||||
);
|
||||
|
||||
// 菜单搜索:命中项按分组展示;搜索中忽略折叠状态,保证结果可见
|
||||
const [searchText, setSearchText] = useState('');
|
||||
const searchInputRef = useRef(null);
|
||||
const navRef = useRef(null);
|
||||
const query = searchText.trim().toLowerCase();
|
||||
const visibleGroups = useMemo(() => {
|
||||
if (!query) return groupedItems;
|
||||
return groupedItems
|
||||
.map((g) => ({
|
||||
...g,
|
||||
items: g.items.filter((it) => it.text.toLowerCase().includes(query)),
|
||||
}))
|
||||
.filter((g) => g.items.length > 0);
|
||||
}, [groupedItems, query]);
|
||||
|
||||
// 二级分组折叠:仅记录用户手动收起的组,跨会话记忆
|
||||
const FOLDED_GROUPS_KEY = 'org_sidebar_folded_groups';
|
||||
@@ -519,265 +502,92 @@ const OrgSidebar = ({
|
||||
el?.scrollIntoView({ block: 'nearest' });
|
||||
}, [selectedKey]);
|
||||
|
||||
// 搜索命中片段高亮
|
||||
const renderItemText = (text) => {
|
||||
if (!query) return text;
|
||||
const idx = text.toLowerCase().indexOf(query);
|
||||
if (idx === -1) return text;
|
||||
return (
|
||||
<>
|
||||
{text.slice(0, idx)}
|
||||
<mark className='rounded-sm bg-brand/20 px-0.5 text-inherit'>
|
||||
{text.slice(idx, idx + query.length)}
|
||||
</mark>
|
||||
{text.slice(idx + query.length)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`
|
||||
relative flex flex-col h-full transition-all duration-300 ease-out
|
||||
bg-[var(--surface-sidebar)]
|
||||
border-r border-[var(--border-subtle)]
|
||||
${collapsed ? 'w-[64px]' : 'w-[216px]'}
|
||||
`}
|
||||
<aside
|
||||
className='ui-center-sidebar ui-org-sidebar'
|
||||
data-collapsed={collapsed}
|
||||
data-mobile={mobile || undefined}
|
||||
>
|
||||
{/* 标题区域 */}
|
||||
{!collapsed && (
|
||||
<div className='px-4 pt-5 pb-3'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<div className='p-1.5 rounded-lg bg-brand/10 text-brand'>
|
||||
<Building2 size={16} />
|
||||
</div>
|
||||
<div className='min-w-0'>
|
||||
<span className='font-bold text-gray-900 dark:text-white block truncate text-sm'>
|
||||
{orgName || t('企业中心')}
|
||||
</span>
|
||||
{orgRole && (
|
||||
<span className='text-[10px] text-gray-500 dark:text-gray-400'>
|
||||
{roleLabel}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className='ui-org-identity'>
|
||||
<LayoutGrid size={22} strokeWidth={1.5} aria-hidden='true' />
|
||||
<div className='ui-org-identity-copy'>
|
||||
<span className='ui-org-name' title={orgName || t('企业中心')}>
|
||||
{orgName || t('企业中心')}
|
||||
</span>
|
||||
{orgRole && <span className='ui-org-role'>{roleLabel}</span>}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 菜单搜索(折叠态显示放大镜按钮,点击先展开侧栏再聚焦输入框) */}
|
||||
{!collapsed ? (
|
||||
<div className='px-3 pb-1'>
|
||||
<div className='relative'>
|
||||
<Search
|
||||
size={14}
|
||||
className='pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 text-gray-400 dark:text-gray-500'
|
||||
/>
|
||||
<input
|
||||
ref={searchInputRef}
|
||||
type='text'
|
||||
value={searchText}
|
||||
onChange={(e) => setSearchText(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Escape') setSearchText('');
|
||||
}}
|
||||
placeholder={t('搜索菜单')}
|
||||
aria-label={t('搜索菜单')}
|
||||
className='h-8 w-full rounded-lg border border-transparent bg-[var(--ui-color-fill-0)] pl-8 pr-7 text-sm text-[var(--text-primary)] outline-none transition-colors duration-200 placeholder:text-gray-400 focus:border-brand/40 focus:bg-[var(--surface-card)] dark:placeholder:text-gray-500'
|
||||
/>
|
||||
{searchText && (
|
||||
<button
|
||||
type='button'
|
||||
onClick={() => setSearchText('')}
|
||||
aria-label={t('清空搜索')}
|
||||
className='absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-gray-400 transition-colors hover:text-gray-700 dark:hover:text-gray-200'
|
||||
>
|
||||
<X size={13} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className='px-3 pb-1 pt-3'>
|
||||
<button
|
||||
type='button'
|
||||
onClick={() => {
|
||||
toggleCollapsed();
|
||||
setTimeout(() => searchInputRef.current?.focus(), 350);
|
||||
}}
|
||||
aria-label={t('搜索菜单')}
|
||||
className='flex w-full items-center justify-center rounded-lg p-2 text-gray-500 transition-colors duration-200 hover:bg-brand/10 hover:text-brand-deep dark:text-gray-400 dark:hover:bg-brand/15 dark:hover:text-brand-from'
|
||||
>
|
||||
<Search size={16} />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 导航区域 */}
|
||||
<nav
|
||||
ref={navRef}
|
||||
className='app-scrollbar relative flex-1 px-3 pt-1 pb-2 overflow-y-auto overflow-x-hidden'
|
||||
>
|
||||
{query && visibleGroups.length === 0 && (
|
||||
<div className='px-2 py-8 text-center text-xs text-gray-400 dark:text-gray-500'>
|
||||
{t('没有匹配的菜单')}
|
||||
</div>
|
||||
)}
|
||||
{visibleGroups.map((group, gi) => {
|
||||
// 搜索中强制展开,保证命中项可见;平时遵循用户的折叠选择
|
||||
const folded = !query && foldedGroups.includes(group.key);
|
||||
<nav ref={navRef} className='ui-center-sidebar-nav'>
|
||||
{groupedItems.map((group) => {
|
||||
const folded = foldedGroups.includes(group.key);
|
||||
return (
|
||||
<div key={group.key} className={gi > 0 ? 'mt-3' : ''}>
|
||||
{/* 分组标题(展开态,可点击折叠)/ 分隔线(折叠态) */}
|
||||
{!collapsed ? (
|
||||
<div key={group.key} className='ui-org-nav-group'>
|
||||
{!collapsed && (
|
||||
<button
|
||||
type='button'
|
||||
onClick={() => toggleGroup(group.key)}
|
||||
aria-expanded={!folded}
|
||||
className='mb-1 flex w-full select-none items-center gap-1.5 rounded-md px-2 py-1 text-[11px] font-semibold uppercase tracking-wider text-gray-400 transition-colors duration-200 hover:bg-[var(--ui-color-fill-0)] hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-300'
|
||||
className='ui-org-group-toggle'
|
||||
>
|
||||
<span className='truncate'>{group.label}</span>
|
||||
<span className='ml-auto text-[10px] font-normal tabular-nums opacity-70'>
|
||||
{group.items.length}
|
||||
</span>
|
||||
<span>{group.label}</span>
|
||||
<ChevronDown
|
||||
size={13}
|
||||
className={`shrink-0 transition-transform duration-200 ${folded ? '-rotate-90' : ''}`}
|
||||
className={folded ? 'is-folded' : ''}
|
||||
aria-hidden='true'
|
||||
/>
|
||||
</button>
|
||||
) : (
|
||||
gi > 0 && (
|
||||
<div className='mx-2 mb-3 h-px bg-gray-200/50 dark:bg-neutral-700/50' />
|
||||
)
|
||||
)}
|
||||
|
||||
{/* grid-rows 0fr→1fr 实现平滑的折叠动画 */}
|
||||
<div
|
||||
className={`grid transition-[grid-template-rows] duration-200 ease-out ${
|
||||
folded && !collapsed ? 'grid-rows-[0fr]' : 'grid-rows-[1fr]'
|
||||
}`}
|
||||
>
|
||||
<div className='overflow-hidden'>
|
||||
<div className='space-y-1.5 pb-0.5'>
|
||||
{group.items.map((item) => {
|
||||
const isSelected = selectedKey === item.itemKey;
|
||||
const IconComponent = item.icon;
|
||||
|
||||
return (
|
||||
<Link
|
||||
key={item.itemKey}
|
||||
to={item.itemKey}
|
||||
onClick={() => onNavigate?.()}
|
||||
data-active={isSelected || undefined}
|
||||
className={`
|
||||
group relative flex items-center gap-3 rounded-lg transition-colors duration-200
|
||||
${collapsed ? 'justify-center p-3' : 'px-3 py-2'}
|
||||
${
|
||||
isSelected
|
||||
? 'bg-brand/10 dark:bg-brand/15'
|
||||
: 'hover:bg-brand/5 dark:hover:bg-brand/10'
|
||||
}
|
||||
`}
|
||||
>
|
||||
{isSelected && (
|
||||
<div className='absolute left-0 top-1/2 -translate-y-1/2 w-0.5 h-5 rounded-r-full bg-brand transition-all duration-200' />
|
||||
<div className='ui-org-group-items' hidden={folded && !collapsed}>
|
||||
{group.items.map((item) => {
|
||||
const isSelected = selectedKey === item.itemKey;
|
||||
const IconComponent = item.icon;
|
||||
return (
|
||||
<Link
|
||||
key={item.itemKey}
|
||||
to={item.itemKey}
|
||||
onClick={() => onNavigate?.()}
|
||||
data-active={isSelected || undefined}
|
||||
aria-current={isSelected ? 'page' : undefined}
|
||||
title={collapsed ? item.text : undefined}
|
||||
className='ui-center-menu-item'
|
||||
>
|
||||
<IconComponent
|
||||
size={16}
|
||||
strokeWidth={1.5}
|
||||
aria-hidden='true'
|
||||
/>
|
||||
{!collapsed && (
|
||||
<>
|
||||
<span className='ui-center-menu-label'>
|
||||
{item.text}
|
||||
</span>
|
||||
{item.beta && (
|
||||
<span className='ui-org-beta'>BETA</span>
|
||||
)}
|
||||
|
||||
<div
|
||||
className={`
|
||||
relative flex-shrink-0 p-1.5 rounded-lg transition-colors duration-200
|
||||
${
|
||||
isSelected
|
||||
? 'bg-brand text-white'
|
||||
: 'text-gray-500 dark:text-gray-400 group-hover:text-brand-deep dark:group-hover:text-brand-from'
|
||||
}
|
||||
`}
|
||||
>
|
||||
<IconComponent size={18} strokeWidth={2} />
|
||||
</div>
|
||||
|
||||
{!collapsed && (
|
||||
<span className='flex min-w-0 items-center gap-2'>
|
||||
<span
|
||||
className={`
|
||||
text-sm transition-colors truncate
|
||||
${
|
||||
isSelected
|
||||
? 'text-brand-deep dark:text-brand-from font-semibold'
|
||||
: 'font-medium text-gray-600 dark:text-gray-300 group-hover:text-brand-deep dark:group-hover:text-brand-from'
|
||||
}
|
||||
`}
|
||||
>
|
||||
{renderItemText(item.text)}
|
||||
</span>
|
||||
{item.beta && (
|
||||
<span className='shrink-0 rounded-full border border-orange-300/70 bg-orange-50 px-1.5 py-0.5 font-mono text-[8px] font-bold tracking-wider text-orange-700 dark:border-orange-700/50 dark:bg-orange-950/40 dark:text-orange-300'>
|
||||
BETA
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
|
||||
{collapsed && (
|
||||
<div
|
||||
className='
|
||||
absolute left-full ml-2 px-2.5 py-1.5
|
||||
bg-gray-900 dark:bg-white text-white dark:text-gray-900
|
||||
text-xs font-medium rounded-lg shadow-lg
|
||||
opacity-0 invisible group-hover:opacity-100 group-hover:visible
|
||||
transition-all duration-200 whitespace-nowrap z-50
|
||||
'
|
||||
>
|
||||
{item.text}
|
||||
<div
|
||||
className='absolute left-0 top-1/2 -translate-x-1 -translate-y-1/2
|
||||
border-4 border-transparent border-r-gray-900 dark:border-r-white'
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
|
||||
{/* 底部分隔线 */}
|
||||
{!mobile && (
|
||||
<div className='mx-4 h-px bg-gradient-to-r from-transparent via-gray-200/60 dark:via-neutral-700/60 to-transparent' />
|
||||
<button
|
||||
type='button'
|
||||
onClick={toggleCollapsed}
|
||||
className='ui-center-sidebar-collapse'
|
||||
aria-label={collapsed ? t('展开导航') : t('收起导航')}
|
||||
>
|
||||
{collapsed ? <ChevronRight size={16} /> : <ChevronLeft size={16} />}
|
||||
{!collapsed && <span>{t('收起导航')}</span>}
|
||||
</button>
|
||||
)}
|
||||
|
||||
{/* 折叠按钮(移动端抽屉里不显示) */}
|
||||
{!mobile && (
|
||||
<div className='relative p-3'>
|
||||
<button
|
||||
onClick={toggleCollapsed}
|
||||
className={`
|
||||
flex items-center justify-center gap-2 w-full py-2 rounded-lg
|
||||
text-gray-500 dark:text-gray-400 text-sm font-medium
|
||||
border border-[var(--border-subtle)]
|
||||
hover:bg-brand/10 dark:hover:bg-brand/15
|
||||
hover:text-brand-deep dark:hover:text-brand-from
|
||||
hover:border-brand/30 transition-colors duration-200
|
||||
${collapsed ? 'px-2' : 'px-3'}
|
||||
`}
|
||||
>
|
||||
{collapsed ? (
|
||||
<ChevronRight size={16} strokeWidth={2.5} />
|
||||
) : (
|
||||
<>
|
||||
<ChevronLeft size={16} strokeWidth={2.5} />
|
||||
<span>{t('收起')}</span>
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</aside>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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>
|
||||
|
||||
|
||||
@@ -19,30 +19,23 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Table,
|
||||
Button,
|
||||
Select,
|
||||
Empty,
|
||||
Spin,
|
||||
Progress,
|
||||
Typography,
|
||||
} from '@/components/ui';
|
||||
import OrgPanel from './OrgPanel';
|
||||
Button as AntButton,
|
||||
Card as AntCard,
|
||||
Segmented,
|
||||
Select as AntSelect,
|
||||
Tabs as AntTabs,
|
||||
Tag as AntTag,
|
||||
} from 'antd';
|
||||
import { Table, Empty, Spin, Progress } from '@/components/ui';
|
||||
import '../../../styles/org-center.css';
|
||||
import { VChart } from '@visactor/react-vchart';
|
||||
import { initVChartTheme } from '@/components/ui/chartTheme';
|
||||
import {
|
||||
RefreshCw,
|
||||
PieChart,
|
||||
TrendingUp,
|
||||
BarChart3,
|
||||
Crown,
|
||||
} from 'lucide-react';
|
||||
import { RefreshCw } from 'lucide-react';
|
||||
import { API } from '../../../helpers/api';
|
||||
import { showError } from '../../../helpers';
|
||||
import { renderQuota } from '../../../helpers/render';
|
||||
import { useActualTheme } from '../../../context/Theme';
|
||||
|
||||
const { Text } = Typography;
|
||||
const getOrgHeaders = (orgId) => ({ 'X-Org-Id': String(orgId) });
|
||||
|
||||
/* 系列色运行时读取品牌 token(--brand-*),随主题预设整套切换。
|
||||
@@ -95,37 +88,20 @@ const chartGrid = (tokens) => ({
|
||||
style: { stroke: tokens.grid, lineDash: [4, 4] },
|
||||
});
|
||||
|
||||
// 环比徽标:本期 vs 上期。增长绿、下降红;无上期数据时灰显。
|
||||
// 状态色统一走 Semi 语义 token(与页面各处使用进度条同一套红绿,且随明暗主题自适应)。
|
||||
// 环比徽标:本期 vs 上期。增长绿、下降红;无上期数据时灰显(语义色沿用原实现)。
|
||||
const DeltaBadge = ({ cur, prev, t }) => {
|
||||
if (!prev || prev <= 0) {
|
||||
return <span className='text-xs text-gray-400'>{t('无上期对比')}</span>;
|
||||
return <small>{t('无上期对比')}</small>;
|
||||
}
|
||||
const pct = ((cur - prev) / prev) * 100;
|
||||
const up = pct >= 0;
|
||||
return (
|
||||
<span
|
||||
className='text-xs font-medium'
|
||||
style={{
|
||||
color: up ? 'var(--ui-color-success)' : 'var(--ui-color-danger)',
|
||||
}}
|
||||
>
|
||||
{up ? '▲' : '▼'} {Math.abs(pct).toFixed(1)}%
|
||||
<span className='text-gray-400 ml-1'>{t('较上期')}</span>
|
||||
</span>
|
||||
<small className={up ? 'is-up' : 'is-down'}>
|
||||
{up ? '↑' : '↓'} {Math.abs(pct).toFixed(1)}%<em>{t('较上期')}</em>
|
||||
</small>
|
||||
);
|
||||
};
|
||||
|
||||
const KpiCard = ({ label, value, sub }) => (
|
||||
<div className='px-4 py-3 rounded-xl bg-[var(--ui-color-fill-0)]'>
|
||||
<div className='text-xs text-gray-500 mb-1'>{label}</div>
|
||||
<div className='text-lg font-semibold text-gray-900 dark:text-white truncate'>
|
||||
{value}
|
||||
</div>
|
||||
{sub ? <div className='mt-0.5'>{sub}</div> : null}
|
||||
</div>
|
||||
);
|
||||
|
||||
// 把 time 维度的小时行聚合成趋势序列:>7 天按天汇总,否则按小时。
|
||||
const buildTrend = (rows, rangeDays, field) => {
|
||||
if (!rows || rows.length === 0) return [];
|
||||
@@ -156,20 +132,28 @@ const localizeAnalyticsRows = (rows, dimension, t) =>
|
||||
department: t('未分配部门'),
|
||||
project: t('未绑定项目'),
|
||||
member: t('未归属成员'),
|
||||
token: t('未绑定令牌'),
|
||||
token: t('未绑定密钥'),
|
||||
}[dimension];
|
||||
if (zeroName) name = zeroName;
|
||||
} else if (dimension === 'member' && name === `成员#${row.key}`) {
|
||||
name = `${t('成员')}#${row.key}`;
|
||||
} else if (dimension === 'token' && name === `令牌#${row.key}`) {
|
||||
name = `${t('令牌')}#${row.key}`;
|
||||
} else if (dimension === 'token' && name === `\u4ee4\u724c#${row.key}`) {
|
||||
name = `${t('密钥')}#${row.key}`;
|
||||
}
|
||||
return name === row.name ? row : { ...row, name };
|
||||
});
|
||||
|
||||
// 多维用量分析面板(§5.6):经营看板视角——KPI+环比、消耗趋势折线、维度分布柱状、明细表。
|
||||
// 仅 admin + analytics 特性开启时挂载(前端门控),后端接口仍 admin+feature 鉴权。
|
||||
const OrgAnalyticsPanel = ({ orgId }) => {
|
||||
// memberUsage:数据看板传入的“成员用量明细”卡,作为明细页签之一(原型 .ea-detail-tabs);
|
||||
// detailTab / onDetailTabChange:明细页签受控(数据看板“成员用量”按钮切换并定位)。
|
||||
const OrgAnalyticsPanel = ({
|
||||
orgId,
|
||||
memberUsage = null,
|
||||
detailTab,
|
||||
onDetailTabChange,
|
||||
detailsRef,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const actualTheme = useActualTheme();
|
||||
const isDarkMode = actualTheme === 'dark';
|
||||
@@ -189,6 +173,11 @@ const OrgAnalyticsPanel = ({ orgId }) => {
|
||||
const [trendRows, setTrendRows] = useState([]);
|
||||
const [prevRows, setPrevRows] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [detailPage, setDetailPage] = useState(1);
|
||||
|
||||
useEffect(() => {
|
||||
setDetailPage(1);
|
||||
}, [breakdownRows, dimension, rangeDays]);
|
||||
|
||||
useEffect(() => {
|
||||
initVChartTheme({ isWatchingThemeSwitch: true });
|
||||
@@ -200,7 +189,7 @@ const OrgAnalyticsPanel = ({ orgId }) => {
|
||||
{ label: t('项目'), value: 'project' },
|
||||
{ label: t('部门'), value: 'department' },
|
||||
{ label: t('成员'), value: 'member' },
|
||||
{ label: t('令牌'), value: 'token' },
|
||||
{ label: t('密钥'), value: 'token' },
|
||||
{ label: t('时间'), value: 'time' },
|
||||
],
|
||||
[t],
|
||||
@@ -298,7 +287,11 @@ const OrgAnalyticsPanel = ({ orgId }) => {
|
||||
data: [{ id: 'trend', values: trendData }],
|
||||
xField: 'date',
|
||||
yField: 'value',
|
||||
point: { visible: trendData.length <= 60, size: 3 },
|
||||
point: {
|
||||
visible: trendData.length <= 60,
|
||||
size: 3,
|
||||
style: { fill: brandColors.brand },
|
||||
},
|
||||
line: { style: { lineWidth: 2, stroke: brandColors.brand } },
|
||||
area: {
|
||||
style: {
|
||||
@@ -375,7 +368,7 @@ const OrgAnalyticsPanel = ({ orgId }) => {
|
||||
direction: 'horizontal',
|
||||
xField: 'value',
|
||||
yField: 'name',
|
||||
color: [brandColors.brand2],
|
||||
color: [brandColors.brand],
|
||||
barMaxWidth: 22,
|
||||
label: {
|
||||
visible: true,
|
||||
@@ -428,33 +421,52 @@ const OrgAnalyticsPanel = ({ orgId }) => {
|
||||
);
|
||||
const columns = useMemo(
|
||||
() => [
|
||||
{ title: dimLabel, dataIndex: 'name', width: 200 },
|
||||
{
|
||||
title: t('消耗占比'),
|
||||
title: dimLabel,
|
||||
dataIndex: 'name',
|
||||
width: 228,
|
||||
render: (v) => <span className='oc-ea-model-name'>{v}</span>,
|
||||
},
|
||||
{
|
||||
title: t('消费占比'),
|
||||
width: 300,
|
||||
render: (_, r) => {
|
||||
const pct =
|
||||
breakdownTotal > 0 ? ((r.quota || 0) / breakdownTotal) * 100 : 0;
|
||||
return (
|
||||
<div className='flex items-center gap-2'>
|
||||
<div className='oc-ea-cost-share'>
|
||||
<div>
|
||||
<strong>{renderQuota(r.quota || 0, 2)}</strong>
|
||||
<span>{pct.toFixed(1)}%</span>
|
||||
</div>
|
||||
<Progress
|
||||
percent={Math.round(pct)}
|
||||
style={{ flex: 1 }}
|
||||
stroke={brandColors.brand2}
|
||||
size='small'
|
||||
stroke={brandColors.brand}
|
||||
showInfo={false}
|
||||
/>
|
||||
<span className='text-xs text-gray-500 whitespace-nowrap'>
|
||||
{renderQuota(r.quota || 0, 2)} ({pct.toFixed(1)}%)
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
{ title: t('请求数'), dataIndex: 'request_count', width: 100 },
|
||||
{
|
||||
title: t('Token (入/出)'),
|
||||
width: 160,
|
||||
render: (_, r) =>
|
||||
`${r.prompt_tokens || 0} / ${r.completion_tokens || 0}`,
|
||||
title: t('请求数'),
|
||||
dataIndex: 'request_count',
|
||||
width: 110,
|
||||
align: 'right',
|
||||
render: (v) => Number(v || 0).toLocaleString(),
|
||||
},
|
||||
{
|
||||
title: t('Token(入 / 出)'),
|
||||
width: 240,
|
||||
align: 'right',
|
||||
render: (_, r) => (
|
||||
<span className='oc-ea-token-pair'>
|
||||
{Number(r.prompt_tokens || 0).toLocaleString()}
|
||||
<small> / </small>
|
||||
{Number(r.completion_tokens || 0).toLocaleString()}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
],
|
||||
[dimLabel, breakdownTotal, t, brandColors],
|
||||
@@ -466,180 +478,215 @@ const OrgAnalyticsPanel = ({ orgId }) => {
|
||||
{ label: t('近 90 天'), value: 90 },
|
||||
];
|
||||
|
||||
const [innerTab, setInnerTab] = useState('models');
|
||||
const activeDetail = detailTab ?? innerTab;
|
||||
const changeDetail = (key) => {
|
||||
setInnerTab(key);
|
||||
onDetailTabChange?.(key);
|
||||
};
|
||||
|
||||
const detailCard = (
|
||||
<AntCard className='oc-ea-detail-card'>
|
||||
<div className='oc-ea-table-toolbar'>
|
||||
<h2>{t('{{dim}}明细', { dim: dimLabel })}</h2>
|
||||
</div>
|
||||
{loading ? (
|
||||
<div className='oc-ea-loading'>
|
||||
<Spin size='large' />
|
||||
</div>
|
||||
) : breakdownRows.length === 0 ? (
|
||||
<Empty
|
||||
description={t('该时间范围暂无用量数据')}
|
||||
style={{ padding: 40 }}
|
||||
/>
|
||||
) : (
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={breakdownRows}
|
||||
rowKey='key'
|
||||
scroll={{ x: 880 }}
|
||||
pagination={{
|
||||
currentPage: Math.min(
|
||||
detailPage,
|
||||
Math.max(1, Math.ceil(breakdownRows.length / 10)),
|
||||
),
|
||||
pageSize: 10,
|
||||
showSizeChanger: false,
|
||||
onPageChange: setDetailPage,
|
||||
showTotal: (n) => t('共 {{total}} 条', { total: n }),
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</AntCard>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className='space-y-4'>
|
||||
{/* 控制区 */}
|
||||
<OrgPanel>
|
||||
<div className='flex flex-wrap items-center justify-between gap-3'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<PieChart size={18} className='text-brand-deep' />
|
||||
<Text strong>{t('企业用量分析')}</Text>
|
||||
<Text type='tertiary' size='small'>
|
||||
{t('趋势 · 结构 · 与消耗明细一致')}
|
||||
</Text>
|
||||
<>
|
||||
{/* 多维用量分析(原型 .ea-analysis):标题 + 维度 / 时间 / 刷新 */}
|
||||
<section className='oc-ea-analysis'>
|
||||
<div className='oc-ea-analysis-heading'>
|
||||
<div>
|
||||
<h2>{t('多维用量分析')}</h2>
|
||||
<p>{t('趋势、结构与调用明细')}</p>
|
||||
</div>
|
||||
<div className='flex items-center gap-2'>
|
||||
<Select
|
||||
<div className='oc-ea-filters'>
|
||||
<AntSelect
|
||||
className='oc-ea-dimension-select'
|
||||
aria-label={t('维度')}
|
||||
value={dimension}
|
||||
onChange={setDimension}
|
||||
optionList={dimensions}
|
||||
style={{ width: 110 }}
|
||||
options={dimensions}
|
||||
/>
|
||||
<Select
|
||||
<AntSelect
|
||||
className='oc-ea-range-select'
|
||||
aria-label={t('时间范围')}
|
||||
value={rangeDays}
|
||||
onChange={setRangeDays}
|
||||
optionList={rangeOptions}
|
||||
style={{ width: 110 }}
|
||||
options={rangeOptions}
|
||||
/>
|
||||
<Button
|
||||
theme='light'
|
||||
icon={<RefreshCw size={14} />}
|
||||
<AntButton
|
||||
className='oc-ea-refresh'
|
||||
aria-label={t('刷新分析')}
|
||||
icon={<RefreshCw size={16} />}
|
||||
loading={loading}
|
||||
onClick={() => fetchAll(true)}
|
||||
>
|
||||
{t('刷新')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* KPI + 环比 */}
|
||||
<div className='grid grid-cols-2 lg:grid-cols-4 gap-4 mt-4'>
|
||||
<KpiCard
|
||||
label={t('本期总消耗')}
|
||||
value={renderQuota(curQuota, 2)}
|
||||
sub={<DeltaBadge cur={curQuota} prev={prevQuota} t={t} />}
|
||||
/>
|
||||
<KpiCard
|
||||
label={t('本期总请求')}
|
||||
value={curReq.toLocaleString()}
|
||||
sub={<DeltaBadge cur={curReq} prev={prevReq} t={t} />}
|
||||
/>
|
||||
<KpiCard
|
||||
label={t('日均消耗')}
|
||||
value={renderQuota(rangeDays > 0 ? curQuota / rangeDays : 0, 2)}
|
||||
sub={
|
||||
<span className='text-xs text-gray-400'>
|
||||
{t('近 {{n}} 天均值', { n: rangeDays })}
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
<KpiCard
|
||||
label={t('消耗最高')}
|
||||
value={topRow ? topRow.name : '-'}
|
||||
sub={
|
||||
topRow ? (
|
||||
<span className='text-xs text-amber-500 inline-flex items-center gap-1'>
|
||||
<Crown size={11} /> {renderQuota(topRow.quota || 0, 2)}
|
||||
</span>
|
||||
) : (
|
||||
<span className='text-xs text-gray-400'>
|
||||
{dimension === 'time' ? t('按时间维度无排名') : '-'}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</OrgPanel>
|
||||
|
||||
{/* 消耗趋势折线 */}
|
||||
<OrgPanel>
|
||||
<div className='flex items-center justify-between mb-3'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<TrendingUp size={16} className='text-brand-deep' />
|
||||
<Text strong>{t('用量趋势')}</Text>
|
||||
</div>
|
||||
<Select
|
||||
value={trendMetric}
|
||||
onChange={setTrendMetric}
|
||||
optionList={[
|
||||
{ label: t('消耗'), value: 'quota' },
|
||||
{ label: t('请求数'), value: 'requests' },
|
||||
]}
|
||||
style={{ width: 100 }}
|
||||
size='small'
|
||||
/>
|
||||
</div>
|
||||
{loading ? (
|
||||
<div className='flex justify-center py-12'>
|
||||
<Spin size='large' />
|
||||
</div>
|
||||
) : trendSpec ? (
|
||||
<div className='rounded-2xl border border-gray-100/70 dark:border-white/5 bg-white/60 dark:bg-slate-950/25 p-2'>
|
||||
<VChart
|
||||
key={`trend-${actualTheme}`}
|
||||
spec={trendSpec}
|
||||
option={{ mode: 'desktop-browser' }}
|
||||
style={{ height: 280 }}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<Empty
|
||||
description={t('该时间范围暂无用量数据')}
|
||||
style={{ padding: 40 }}
|
||||
/>
|
||||
)}
|
||||
</OrgPanel>
|
||||
</div>
|
||||
|
||||
{/* 维度分布柱状(time 维度不展示,趋势图已覆盖) */}
|
||||
{dimension !== 'time' && (
|
||||
<OrgPanel>
|
||||
<div className='flex items-center gap-2 mb-3'>
|
||||
<BarChart3 size={16} className='text-brand-deep' />
|
||||
<Text strong>{t('{{dim}}消耗分布', { dim: dimLabel })}</Text>
|
||||
<Text type='tertiary' size='small'>
|
||||
{t('Top 10')}
|
||||
</Text>
|
||||
{/* 汇总指标(原型 .ea-summary) */}
|
||||
<div className='oc-ea-summary'>
|
||||
<div>
|
||||
<span>{t('本期总消费')}</span>
|
||||
<strong>{renderQuota(curQuota, 2)}</strong>
|
||||
<DeltaBadge cur={curQuota} prev={prevQuota} t={t} />
|
||||
</div>
|
||||
{loading ? (
|
||||
<div className='flex justify-center py-12'>
|
||||
<Spin size='large' />
|
||||
</div>
|
||||
) : barSpec ? (
|
||||
<div className='rounded-2xl border border-gray-100/70 dark:border-white/5 bg-white/60 dark:bg-slate-950/25 p-2'>
|
||||
<VChart
|
||||
key={`bar-${actualTheme}`}
|
||||
spec={barSpec}
|
||||
option={{ mode: 'desktop-browser' }}
|
||||
style={{ height: Math.max(220, barData.length * 34 + 60) }}
|
||||
<div>
|
||||
<span>{t('本期总请求')}</span>
|
||||
<strong>{curReq.toLocaleString()}</strong>
|
||||
<DeltaBadge cur={curReq} prev={prevReq} t={t} />
|
||||
</div>
|
||||
<div>
|
||||
<span>{t('日均消费')}</span>
|
||||
<strong>
|
||||
{renderQuota(rangeDays > 0 ? curQuota / rangeDays : 0, 2)}
|
||||
</strong>
|
||||
<small>{t('近 {{n}} 天均值', { n: rangeDays })}</small>
|
||||
</div>
|
||||
<div>
|
||||
<span>{t('消费最高')}</span>
|
||||
<strong className='oc-ea-top'>{topRow ? topRow.name : '-'}</strong>
|
||||
<small>
|
||||
{topRow
|
||||
? renderQuota(topRow.quota || 0, 2)
|
||||
: dimension === 'time'
|
||||
? t('按时间维度无排名')
|
||||
: '-'}
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className={`oc-ea-charts${dimension === 'time' ? ' is-single' : ''}`}
|
||||
>
|
||||
{/* 用量趋势 */}
|
||||
<AntCard className='oc-ea-trend'>
|
||||
<div className='oc-ea-panel-heading'>
|
||||
<div>
|
||||
<h2>{t('用量趋势')}</h2>
|
||||
<span>
|
||||
{rangeDays > 7
|
||||
? t('按天查看企业调用消耗')
|
||||
: t('逐小时查看企业调用消耗')}
|
||||
</span>
|
||||
</div>
|
||||
<Segmented
|
||||
size='small'
|
||||
value={trendMetric}
|
||||
onChange={setTrendMetric}
|
||||
options={[
|
||||
{ label: t('消费'), value: 'quota' },
|
||||
{ label: t('请求数'), value: 'requests' },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<Empty
|
||||
description={t('该时间范围暂无用量数据')}
|
||||
style={{ padding: 40 }}
|
||||
/>
|
||||
)}
|
||||
</OrgPanel>
|
||||
)}
|
||||
{loading ? (
|
||||
<div className='oc-ea-loading'>
|
||||
<Spin size='large' />
|
||||
</div>
|
||||
) : trendSpec ? (
|
||||
<VChart
|
||||
key={`trend-${actualTheme}`}
|
||||
spec={trendSpec}
|
||||
option={{ mode: 'desktop-browser' }}
|
||||
style={{ height: 306 }}
|
||||
/>
|
||||
) : (
|
||||
<Empty
|
||||
description={t('该时间范围暂无用量数据')}
|
||||
style={{ padding: 40 }}
|
||||
/>
|
||||
)}
|
||||
</AntCard>
|
||||
|
||||
{/* 明细表 */}
|
||||
<OrgPanel>
|
||||
<div className='flex items-center gap-2 mb-3'>
|
||||
<Text strong>{t('{{dim}}明细', { dim: dimLabel })}</Text>
|
||||
{/* 维度分布柱状(time 维度不展示,趋势图已覆盖) */}
|
||||
{dimension !== 'time' && (
|
||||
<AntCard className='oc-ea-rank'>
|
||||
<div className='oc-ea-panel-heading'>
|
||||
<div>
|
||||
<h2>{t('{{dim}}消费分布', { dim: dimLabel })}</h2>
|
||||
<span>{t('Top 10')}</span>
|
||||
</div>
|
||||
<AntTag bordered={false}>{t('按消费排序')}</AntTag>
|
||||
</div>
|
||||
{loading ? (
|
||||
<div className='oc-ea-loading'>
|
||||
<Spin size='large' />
|
||||
</div>
|
||||
) : barSpec ? (
|
||||
<VChart
|
||||
key={`bar-${actualTheme}`}
|
||||
spec={barSpec}
|
||||
option={{ mode: 'desktop-browser' }}
|
||||
style={{ height: Math.max(306, barData.length * 34 + 60) }}
|
||||
/>
|
||||
) : (
|
||||
<Empty
|
||||
description={t('该时间范围暂无用量数据')}
|
||||
style={{ padding: 40 }}
|
||||
/>
|
||||
)}
|
||||
</AntCard>
|
||||
)}
|
||||
</div>
|
||||
{loading ? (
|
||||
<div className='flex justify-center py-12'>
|
||||
<Spin size='large' />
|
||||
</div>
|
||||
) : breakdownRows.length === 0 ? (
|
||||
<Empty
|
||||
description={t('该时间范围暂无用量数据')}
|
||||
style={{ padding: 40 }}
|
||||
/>
|
||||
) : (
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={breakdownRows}
|
||||
rowKey='key'
|
||||
pagination={
|
||||
breakdownRows.length > 20
|
||||
? { pageSize: 20, showSizeChanger: false }
|
||||
: false
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</OrgPanel>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* 明细(原型 .ea-details:维度明细 / 成员用量 页签) */}
|
||||
<section className='oc-ea-details' ref={detailsRef}>
|
||||
<AntTabs
|
||||
className='oc-ea-detail-tabs'
|
||||
activeKey={memberUsage ? activeDetail : 'models'}
|
||||
onChange={changeDetail}
|
||||
items={[
|
||||
{
|
||||
key: 'models',
|
||||
label: t('{{dim}}明细', { dim: dimLabel }),
|
||||
children: detailCard,
|
||||
},
|
||||
...(memberUsage
|
||||
? [
|
||||
{
|
||||
key: 'members',
|
||||
label: t('成员用量'),
|
||||
forceRender: true,
|
||||
children: memberUsage,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
]}
|
||||
/>
|
||||
</section>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,221 +0,0 @@
|
||||
/*
|
||||
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 { Button, Input, Radio, RadioGroup } from '@/components/ui';
|
||||
import { Check, Image as ImageIcon, Palette, Type, UserRound } from 'lucide-react';
|
||||
import OrgPanel from './OrgPanel';
|
||||
import {
|
||||
CARTOON_AVATAR_PRESETS,
|
||||
USER_AVATAR_TYPES,
|
||||
getCartoonAvatarDataUrl,
|
||||
getInitialAvatarDataUrl,
|
||||
} from '../../../helpers';
|
||||
|
||||
const AVATAR_TYPE_OPTIONS = [
|
||||
{
|
||||
value: USER_AVATAR_TYPES.PRESET,
|
||||
label: '卡通形象',
|
||||
desc: '从系统内置卡通头像中选择,适合默认展示',
|
||||
icon: Palette,
|
||||
},
|
||||
{
|
||||
value: USER_AVATAR_TYPES.INITIAL,
|
||||
label: '姓名首字',
|
||||
desc: '根据用户名自动生成简洁文字头像',
|
||||
icon: Type,
|
||||
},
|
||||
{
|
||||
value: USER_AVATAR_TYPES.CUSTOM,
|
||||
label: '图片链接',
|
||||
desc: '填写公网图片 URL,使用自己的头像',
|
||||
icon: ImageIcon,
|
||||
},
|
||||
];
|
||||
|
||||
/*
|
||||
* 企业中心头像设置区块。
|
||||
* 与个人中心的 AvatarSection 分开:企业空间是实底卡片 + 品牌色体系(OrgPanel),
|
||||
* 而非个人中心的毛玻璃 + 玫红渐变,避免颜色与整站主体色冲突。
|
||||
*/
|
||||
const OrgAvatarSection = ({
|
||||
t,
|
||||
userState,
|
||||
avatarSettings,
|
||||
handleAvatarSettingChange,
|
||||
saveAvatarSettings,
|
||||
saving,
|
||||
}) => {
|
||||
const username =
|
||||
userState?.user?.display_name || userState?.user?.username || 'User';
|
||||
|
||||
const previewUrl =
|
||||
avatarSettings.avatarType === USER_AVATAR_TYPES.CUSTOM &&
|
||||
avatarSettings.customAvatarUrl
|
||||
? avatarSettings.customAvatarUrl
|
||||
: avatarSettings.avatarType === USER_AVATAR_TYPES.INITIAL
|
||||
? getInitialAvatarDataUrl(username, 128)
|
||||
: getCartoonAvatarDataUrl(avatarSettings.avatarPreset, 128);
|
||||
|
||||
const customAvatarInvalid =
|
||||
avatarSettings.avatarType === USER_AVATAR_TYPES.CUSTOM &&
|
||||
!avatarSettings.customAvatarUrl?.trim();
|
||||
|
||||
const activeDesc =
|
||||
AVATAR_TYPE_OPTIONS.find(
|
||||
(item) => item.value === avatarSettings.avatarType,
|
||||
)?.desc || '';
|
||||
|
||||
return (
|
||||
<OrgPanel
|
||||
title={t('头像设置')}
|
||||
subtitle={t('选择你在平台内展示的头像样式')}
|
||||
icon={UserRound}
|
||||
padding='p-5'
|
||||
actions={
|
||||
<Button
|
||||
theme='solid'
|
||||
loading={saving}
|
||||
disabled={customAvatarInvalid}
|
||||
onClick={saveAvatarSettings}
|
||||
>
|
||||
{t('保存头像')}
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<div className='grid grid-cols-1 xl:grid-cols-[240px_1fr] gap-5 items-start'>
|
||||
{/* 实时预览:品牌色描边,实底卡面 */}
|
||||
<div className='flex flex-col items-center text-center rounded-xl border border-[var(--border-subtle)] bg-brand/[0.04] px-5 py-6'>
|
||||
<div className='relative mb-4'>
|
||||
<img
|
||||
src={previewUrl}
|
||||
alt={t('头像预览')}
|
||||
className='w-24 h-24 rounded-2xl object-cover ring-2 ring-brand/30'
|
||||
/>
|
||||
<span className='absolute -bottom-0.5 -right-0.5 h-5 w-5 rounded-full bg-emerald-500 border-2 border-[var(--surface-card)]' />
|
||||
</div>
|
||||
<div className='text-sm font-semibold text-[var(--text-primary)] truncate max-w-full'>
|
||||
{username}
|
||||
</div>
|
||||
<div className='mt-1.5 text-xs text-gray-500 dark:text-gray-400 leading-relaxed'>
|
||||
{t('该头像会同步展示在右上角用户入口和体验中心文本对话中。')}
|
||||
</div>
|
||||
<span className='mt-3 inline-flex items-center rounded-full bg-brand/10 text-brand px-2.5 py-0.5 text-xs font-medium'>
|
||||
{t('实时预览')}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 头像类型 + 具体选择 */}
|
||||
<div>
|
||||
<label className='block text-xs font-medium text-[var(--text-secondary)] mb-2'>
|
||||
{t('头像类型')}
|
||||
</label>
|
||||
<RadioGroup
|
||||
type='button'
|
||||
value={avatarSettings.avatarType}
|
||||
onChange={(e) =>
|
||||
handleAvatarSettingChange('avatarType', e.target.value)
|
||||
}
|
||||
className='!flex !flex-wrap !gap-2'
|
||||
>
|
||||
{AVATAR_TYPE_OPTIONS.map((option) => {
|
||||
const Icon = option.icon;
|
||||
return (
|
||||
<Radio key={option.value} value={option.value}>
|
||||
<span className='inline-flex items-center gap-1.5'>
|
||||
<Icon size={14} />
|
||||
{t(option.label)}
|
||||
</span>
|
||||
</Radio>
|
||||
);
|
||||
})}
|
||||
</RadioGroup>
|
||||
<p className='mt-2 text-xs text-gray-500 dark:text-gray-400'>
|
||||
{t(activeDesc)}
|
||||
</p>
|
||||
|
||||
{avatarSettings.avatarType === USER_AVATAR_TYPES.PRESET && (
|
||||
<div className='mt-5'>
|
||||
<label className='block text-xs font-medium text-[var(--text-secondary)] mb-2.5'>
|
||||
{t('选择卡通形象')}
|
||||
</label>
|
||||
<div className='grid grid-cols-2 sm:grid-cols-4 gap-3'>
|
||||
{CARTOON_AVATAR_PRESETS.map((preset) => {
|
||||
const selected = avatarSettings.avatarPreset === preset.id;
|
||||
return (
|
||||
<button
|
||||
key={preset.id}
|
||||
type='button'
|
||||
onClick={() => {
|
||||
handleAvatarSettingChange(
|
||||
'avatarType',
|
||||
USER_AVATAR_TYPES.PRESET,
|
||||
);
|
||||
handleAvatarSettingChange('avatarPreset', preset.id);
|
||||
}}
|
||||
className={`group relative flex flex-col items-center rounded-xl border p-3 transition-colors duration-150 ${
|
||||
selected
|
||||
? 'border-brand bg-brand/[0.06]'
|
||||
: 'border-[var(--border-subtle)] bg-[var(--surface-card)] hover:border-brand/40'
|
||||
}`}
|
||||
>
|
||||
<img
|
||||
src={getCartoonAvatarDataUrl(preset.id, 96)}
|
||||
alt={preset.label}
|
||||
className='w-14 h-14 rounded-xl object-cover transition-transform group-hover:scale-105'
|
||||
/>
|
||||
<div className='mt-2 text-xs font-medium text-[var(--text-primary)] truncate max-w-full'>
|
||||
{t(preset.label)}
|
||||
</div>
|
||||
{selected && (
|
||||
<span className='absolute top-1.5 right-1.5 inline-flex h-4 w-4 items-center justify-center rounded-full bg-brand text-white'>
|
||||
<Check size={11} strokeWidth={3} />
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{avatarSettings.avatarType === USER_AVATAR_TYPES.CUSTOM && (
|
||||
<div className='mt-5 rounded-xl border border-[var(--border-subtle)] bg-brand/[0.04] p-4'>
|
||||
<Input
|
||||
value={avatarSettings.customAvatarUrl}
|
||||
onChange={(value) =>
|
||||
handleAvatarSettingChange('customAvatarUrl', value)
|
||||
}
|
||||
placeholder={t(
|
||||
'请输入图片 URL,例如 https://example.com/avatar.png',
|
||||
)}
|
||||
prefix={<ImageIcon size={15} className='text-brand ml-1' />}
|
||||
showClear
|
||||
/>
|
||||
<p className='mt-2 text-xs text-gray-500 dark:text-gray-400'>
|
||||
{t('支持公网图片链接。若图片加载失败,会回退到默认卡通头像。')}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</OrgPanel>
|
||||
);
|
||||
};
|
||||
|
||||
export default OrgAvatarSection;
|
||||
@@ -36,19 +36,39 @@ const orgPageTitles = {
|
||||
quality: '调用质量',
|
||||
'agent-audit': 'Agent 任务审计',
|
||||
dashboard: '数据看板',
|
||||
departments: '部门管理',
|
||||
departments: '组织架构',
|
||||
'dept-manage': '部门管理',
|
||||
'project-manage': '我的项目',
|
||||
projects: '项目管理',
|
||||
budgets: '预算中心',
|
||||
tokens: '令牌管理',
|
||||
tokens: '密钥管理',
|
||||
recharge: '企业充值',
|
||||
audit: '审计日志',
|
||||
'personal-settings': '个人设置',
|
||||
settings: '企业设置',
|
||||
};
|
||||
|
||||
/** 企业端统一面包屑:“企业中心 / 当前页面”,样式与用户中心一致。current 仅在路径未登记时兜底。 */
|
||||
// 分组页显示“分组 / 当前页面”,其他页面保留“企业中心 / 当前页面”。
|
||||
// 分组名与 OrgSidebar 的 groups 一致。
|
||||
const orgPageGroups = {
|
||||
members: '组织管理',
|
||||
'member-accounts': '组织管理',
|
||||
departments: '组织管理',
|
||||
'dept-manage': '组织管理',
|
||||
'project-manage': '组织管理',
|
||||
projects: '组织管理',
|
||||
budgets: '额度与治理',
|
||||
requests: '额度与治理',
|
||||
tokens: '额度与治理',
|
||||
recharge: '财务与日志',
|
||||
logs: '财务与日志',
|
||||
audit: '财务与日志',
|
||||
'agent-audit': '财务与日志',
|
||||
'personal-settings': '系统设置',
|
||||
settings: '系统设置',
|
||||
};
|
||||
|
||||
/** 企业端统一两级面包屑,current 仅在路径未登记时兜底。 */
|
||||
export default function OrgBreadcrumb({ current }) {
|
||||
const { pathname } = useLocation();
|
||||
const { t } = useTranslation();
|
||||
@@ -56,10 +76,11 @@ export default function OrgBreadcrumb({ current }) {
|
||||
const mapped = orgPageTitles[key];
|
||||
const title = mapped ? t(mapped) : current;
|
||||
if (!title) return null;
|
||||
const group = orgPageGroups[key];
|
||||
return (
|
||||
<Breadcrumb
|
||||
className='ui-dashboard-breadcrumb ui-user-center-breadcrumb'
|
||||
items={[{ title: t('企业中心') }, { title }]}
|
||||
items={[{ title: t(group || '企业中心') }, { title }]}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
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 } from 'antd';
|
||||
import '../../../styles/org-center.css';
|
||||
|
||||
/**
|
||||
* 企业中心目标页列表卡(原型 .ee-list-card):卡头 h2 标题 + 右侧工具区,正文放表格 / 分页。
|
||||
* 只负责呈现;工具按钮、表格、分页的数据与回调由页面原样传入。
|
||||
*
|
||||
* @param {React.ReactNode} title 卡头标题(如“预算列表”)
|
||||
* @param {React.ReactNode} [tools] 卡头右侧操作(刷新 / 新建等原有按钮)
|
||||
* @param {string} [className] 追加类名
|
||||
*/
|
||||
export const OrgListCard = ({ title, tools, className = '', children }) => (
|
||||
<Card className={`oc-list-card ${className}`}>
|
||||
{(title || tools) && (
|
||||
<div className='oc-list-toolbar'>
|
||||
{title ? <h2>{title}</h2> : <span />}
|
||||
{tools && <div className='oc-list-tools'>{tools}</div>}
|
||||
</div>
|
||||
)}
|
||||
{children}
|
||||
</Card>
|
||||
);
|
||||
|
||||
/**
|
||||
* 企业中心目标页筛选卡(原型 .ee-filter-card):三列表单网格 + 右对齐操作。
|
||||
* 字段、取值与“重置 / 搜索”处理函数由页面原样传入。
|
||||
*/
|
||||
export const OrgFilterCard = ({ actions, className = '', children }) => (
|
||||
<Card className={`oc-filter-card ${className}`}>
|
||||
<div className='oc-filter-grid'>{children}</div>
|
||||
{actions && <div className='oc-filter-actions'>{actions}</div>}
|
||||
</Card>
|
||||
);
|
||||
|
||||
/** 行内操作容器(原型 .ee-row-actions):link 按钮 13px、间距 10px。 */
|
||||
export const OrgRowActions = ({ children }) => (
|
||||
<div className='oc-row-actions'>{children}</div>
|
||||
);
|
||||
|
||||
export default OrgListCard;
|
||||
@@ -22,7 +22,7 @@ import OrgBreadcrumb from './OrgBreadcrumb';
|
||||
|
||||
/**
|
||||
* 企业中心统一页面标题区(/org/*):与个人端共用 UserCenterPageHeader 的样式,
|
||||
* 面包屑为“企业中心 / 当前页面”,标题 28px、副标题 14px。
|
||||
* 面包屑为“分组(或企业中心)/ 当前页面”,标题 28px、副标题 14px。
|
||||
*
|
||||
* @param {React.ReactNode} title 主标题
|
||||
* @param {React.ReactNode} [subtitle] 副标题(一句话说明本页用途)
|
||||
|
||||
@@ -51,7 +51,15 @@ const parseGroups = (raw) => {
|
||||
* - scopeLabel: '部门' | '项目'(用于弹窗标题与文案)
|
||||
* - onSaved: 保存成功后回调(刷新列表)
|
||||
*/
|
||||
const OrgScopedLimitButtons = ({ orgId, record, apiBase, scopeLabel, onSaved }) => {
|
||||
// variant='link':企业中心已按原型对齐的列表页使用 link 按钮(无图标、13px);默认保持原描边按钮
|
||||
const OrgScopedLimitButtons = ({
|
||||
orgId,
|
||||
record,
|
||||
apiBase,
|
||||
scopeLabel,
|
||||
onSaved,
|
||||
variant = 'default',
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [modelModalVisible, setModelModalVisible] = useState(false);
|
||||
@@ -155,10 +163,14 @@ const OrgScopedLimitButtons = ({ orgId, record, apiBase, scopeLabel, onSaved })
|
||||
<>
|
||||
<Tooltip content={t('设置该{{scope}}成员默认可用的模型范围(与成员/项目/部门限制取交集)', { scope: t(scopeLabel) })}>
|
||||
<Button
|
||||
size='small'
|
||||
theme='light'
|
||||
type={modelConfigured ? 'primary' : 'tertiary'}
|
||||
icon={<Layers size={14} />}
|
||||
{...(variant === 'link'
|
||||
? { type: 'link' }
|
||||
: {
|
||||
size: 'small',
|
||||
theme: 'light',
|
||||
type: modelConfigured ? 'primary' : 'tertiary',
|
||||
icon: <Layers size={14} />,
|
||||
})}
|
||||
onClick={openModelModal}
|
||||
>
|
||||
{t('模型')}
|
||||
@@ -166,10 +178,14 @@ const OrgScopedLimitButtons = ({ orgId, record, apiBase, scopeLabel, onSaved })
|
||||
</Tooltip>
|
||||
<Tooltip content={t('设置该{{scope}}成员默认可调用的分组(与成员/项目/部门限制取交集)', { scope: t(scopeLabel) })}>
|
||||
<Button
|
||||
size='small'
|
||||
theme='light'
|
||||
type={groupConfigured ? 'primary' : 'tertiary'}
|
||||
icon={<Layers size={14} />}
|
||||
{...(variant === 'link'
|
||||
? { type: 'link' }
|
||||
: {
|
||||
size: 'small',
|
||||
theme: 'light',
|
||||
type: groupConfigured ? 'primary' : 'tertiary',
|
||||
icon: <Layers size={14} />,
|
||||
})}
|
||||
onClick={openGroupsModal}
|
||||
>
|
||||
{t('分组')}
|
||||
|
||||
@@ -21,13 +21,13 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
// 统一各页面 Tag 颜色口径,避免「pending 一会 amber 一会 orange」「停用一会红一会灰」。
|
||||
const ORG_STATUS_COLOR = {
|
||||
// 审批 / 流程
|
||||
pending: 'amber',
|
||||
pending: 'gold',
|
||||
approved: 'green',
|
||||
rejected: 'red',
|
||||
canceled: 'grey',
|
||||
expired: 'grey',
|
||||
processing: 'blue',
|
||||
// 启停 / 成员 / 令牌
|
||||
// 启停 / 成员 / 密钥
|
||||
active: 'green',
|
||||
enabled: 'green',
|
||||
normal: 'green',
|
||||
|
||||
@@ -461,7 +461,7 @@ const Organization = () => {
|
||||
</div>
|
||||
|
||||
{/* Main Content */}
|
||||
<div className='flex-1 h-full overflow-hidden relative flex flex-col'>
|
||||
<div className='min-w-0 flex-1 h-full overflow-hidden relative flex flex-col'>
|
||||
{/* 移动端顶栏:汉堡菜单 + 当前企业名(窄屏唯一的菜单入口) */}
|
||||
<div className='md:hidden flex items-center gap-2 px-3 h-12 flex-shrink-0 border-b border-[var(--border-subtle)] bg-[var(--surface-header)] relative z-20'>
|
||||
<Button
|
||||
@@ -498,6 +498,7 @@ const Organization = () => {
|
||||
<OrgDashboard
|
||||
orgId={orgId}
|
||||
orgRole={orgRole}
|
||||
orgName={orgInfo?.name}
|
||||
featureFlags={orgFeatureFlags}
|
||||
/>,
|
||||
)
|
||||
@@ -863,7 +864,7 @@ const Organization = () => {
|
||||
/>
|
||||
}
|
||||
/>
|
||||
{/* 令牌管理 - 所有成员可访问 */}
|
||||
{/* 密钥管理 - 所有成员可访问 */}
|
||||
<Route
|
||||
path='tokens'
|
||||
element={guardOrgRoute(
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
.org-capabilities-page {
|
||||
--cap-border: var(--border-subtle);
|
||||
--cap-muted-bg: var(--ui-color-fill-0);
|
||||
--cap-brand: var(--ui-color-primary);
|
||||
}
|
||||
|
||||
.org-capability-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.org-capability-card .ant-card-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.org-capability-card-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.org-capability-icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex: 0 0 40px;
|
||||
height: 40px;
|
||||
border-radius: 8px;
|
||||
color: var(--cap-brand);
|
||||
background: var(--cap-muted-bg);
|
||||
}
|
||||
|
||||
.org-capability-card-name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.org-capability-card-name .ant-typography {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.org-capability-card-name > span {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.org-capability-card .org-capability-description {
|
||||
margin: 0;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.org-capability-sources,
|
||||
.org-capability-methods {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.org-capability-card .ant-tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
margin-inline-end: 0;
|
||||
white-space: normal;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.org-capability-card .ant-tag svg,
|
||||
.org-capability-confirmation > svg {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* SVGs are block elements after the global reset; flex keeps the icon on the text baseline. */
|
||||
.org-capability-confirmation {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.org-capability-card-footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
margin-top: auto;
|
||||
padding-top: 16px;
|
||||
border-top: 1px solid var(--cap-border);
|
||||
}
|
||||
|
||||
@media (max-width: 850px) {
|
||||
.org-capability-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.org-capability-card-head {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.org-capability-card-head > .ant-tag {
|
||||
margin-left: 52px;
|
||||
}
|
||||
.org-capability-card .ant-card-body {
|
||||
padding: 16px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
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
|
||||
*/
|
||||
// Use raw quota values so rounding the progress percentage cannot hide low credit.
|
||||
export function getOrgQuotaAvailability(data) {
|
||||
if (data?.quota == null || data.quota === '') return null;
|
||||
const remaining = Number(data.quota);
|
||||
const used = Number(data.used_quota ?? 0);
|
||||
if (!Number.isFinite(remaining) || !Number.isFinite(used) || used < 0)
|
||||
return null;
|
||||
if (remaining <= 0) return { type: 'danger', label: '可用额度已用尽' };
|
||||
if (remaining / (remaining + used) <= 0.2)
|
||||
return { type: 'warning', label: '可用额度偏低' };
|
||||
return { type: 'success', label: '可用额度充足' };
|
||||
}
|
||||
Reference in New Issue
Block a user