feat: 参考原型图 ui优化提交 企业端-企业中心 相关的页面
This commit is contained in:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user