feat(org): expose enterprise drawing and task logs

(cherry picked from commit b80afd273c)
This commit is contained in:
qiubaishen
2026-11-06 18:52:10 +08:00
committed by zhanjunhao
parent d58e468969
commit 72bec4f8f1
9 changed files with 359 additions and 221 deletions
@@ -55,7 +55,6 @@ export const exportTaskLogsPageCsv = (logs, isAdminUser, t) => {
{ key: 'channel_name', title: t('渠道名称') }, { key: 'channel_name', title: t('渠道名称') },
] ]
: []), : []),
{ key: 'platform', title: t('平台') },
{ key: 'action', title: t('类型') }, { key: 'action', title: t('类型') },
{ {
key: 'model', key: 'model',
@@ -35,7 +35,6 @@ import {
Video, Video,
Sparkles, Sparkles,
Timer, Timer,
Image as ImageIcon,
ImagePlus, ImagePlus,
Coins, Coins,
Cpu, Cpu,
@@ -48,7 +47,6 @@ import {
IMAGE_ACTION_GENERATE, IMAGE_ACTION_GENERATE,
IMAGE_ACTION_EDIT, IMAGE_ACTION_EDIT,
} from '../../../constants/common.constant'; } from '../../../constants/common.constant';
import { CHANNEL_OPTIONS } from '../../../constants/channel.constants';
import { renderQuota } from '../../../helpers'; import { renderQuota } from '../../../helpers';
// 仅保留与下方 COLOR_CONFIG 一一对应的色值,避免 amber/lime/violet/teal/indigo/light-blue // 仅保留与下方 COLOR_CONFIG 一一对应的色值,避免 amber/lime/violet/teal/indigo/light-blue
@@ -231,34 +229,6 @@ const renderType = (type, t) => {
); );
}; };
const renderPlatform = (platform, t) => {
let option = CHANNEL_OPTIONS.find(
(opt) => String(opt.value) === String(platform),
);
if (option) {
return (
<CustomTag
icon={Video}
label={option.label}
colorKey={option.color || 'cyan'}
/>
);
}
if (platform === 'suno') {
return <CustomTag icon={Music} label='Suno' colorKey='green' />;
}
if (platform === 'image') {
return <CustomTag icon={ImageIcon} label={t('图片')} colorKey='cyan' />;
}
if (platform === 'video') {
return <CustomTag icon={Video} label={t('视频')} colorKey='blue' />;
}
if (platform === 'mj') {
return <CustomTag icon={Sparkles} label='Midjourney' colorKey='purple' />;
}
return <CustomTag icon={HelpCircle} label={t('未知')} colorKey='grey' />;
};
const renderStatus = (type, t) => { const renderStatus = (type, t) => {
const statusConfig = { const statusConfig = {
SUCCESS: { icon: CheckCircle, label: t('成功'), color: 'green' }, SUCCESS: { icon: CheckCircle, label: t('成功'), color: 'green' },
@@ -356,12 +326,6 @@ const applyTaskRecordPresentation = (columns, { COLUMN_KEYS }) =>
); );
}, },
}; };
case COLUMN_KEYS.PLATFORM:
return {
...column,
render: (text, record, index) =>
unwrap(text, record, index)?.props?.label ?? '-',
};
case COLUMN_KEYS.TYPE: case COLUMN_KEYS.TYPE:
return { return {
...column, ...column,
@@ -429,6 +393,7 @@ export const getTaskLogsColumns = ({
copyText, copyText,
openContentModal, openContentModal,
isAdminUser, isAdminUser,
isRootUser = false,
openVideoModal, openVideoModal,
usageRecordMode = false, usageRecordMode = false,
}) => { }) => {
@@ -482,14 +447,6 @@ export const getTaskLogsColumns = ({
); );
}, },
}, },
{
key: COLUMN_KEYS.PLATFORM,
title: t('平台'),
dataIndex: 'platform',
render: (text, record, index) => {
return <div>{renderPlatform(text, t)}</div>;
},
},
{ {
key: COLUMN_KEYS.TYPE, key: COLUMN_KEYS.TYPE,
title: t('类型'), title: t('类型'),
@@ -532,10 +489,16 @@ export const getTaskLogsColumns = ({
return ( return (
<Typography.Text <Typography.Text
ellipsis={{ showTooltip: true }} ellipsis={{ showTooltip: true }}
onClick={() => { onClick={
openContentModal(JSON.stringify(record, null, 2)); isRootUser
}} ? () => openContentModal(JSON.stringify(record, null, 2))
className='cursor-pointer hover:text-blue-500 dark:hover:text-blue-400 transition-colors font-mono text-xs' : undefined
}
className={
isRootUser
? 'cursor-pointer hover:text-blue-500 dark:hover:text-blue-400 transition-colors font-mono text-xs'
: 'font-mono text-xs'
}
> >
{text} {text}
</Typography.Text> </Typography.Text>
@@ -51,6 +51,7 @@ const TaskLogsFilters = ({
isAdminUser, isAdminUser,
getFreshInitValues, getFreshInitValues,
usageRecordMode = false, usageRecordMode = false,
hideDateRange = false,
t, t,
}) => { }) => {
const SearchIcon = Search; const SearchIcon = Search;
@@ -268,25 +269,27 @@ const TaskLogsFilters = ({
{/* 搜索字段网格 */} {/* 搜索字段网格 */}
<div className='grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3'> <div className='grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3'>
{/* 时间选择器 */} {/* 时间选择器:企业页复用上方消费记录的已提交时间范围 */}
<div className='col-span-1 lg:col-span-2'> {!hideDateRange && (
<div className='relative group'> <div className='col-span-1 lg:col-span-2'>
<div className='absolute -inset-0.5 bg-gradient-to-r from-cyan-500/20 to-blue-500/20 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity duration-300 blur-sm' /> <div className='relative group'>
<div className='relative'> <div className='absolute -inset-0.5 bg-gradient-to-r from-cyan-500/20 to-blue-500/20 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity duration-300 blur-sm' />
<Form.DatePicker <div className='relative'>
field='dateRange' <Form.DatePicker
className='w-full' field='dateRange'
type='dateTimeRange' className='w-full'
placeholder={[t('开始时间'), t('结束时间')]} type='dateTimeRange'
showClear placeholder={[t('开始时间'), t('结束时间')]}
pure showClear
size='small' pure
prefix={<InputPrefix icon={Calendar} />} size='small'
presets={datePresets} prefix={<InputPrefix icon={Calendar} />}
/> presets={datePresets}
/>
</div>
</div> </div>
</div> </div>
</div> )}
{/* 任务 ID */} {/* 任务 ID */}
<div className='relative group'> <div className='relative group'>
@@ -42,6 +42,7 @@ const TaskLogsTable = (taskLogsData) => {
openContentModal, openContentModal,
openVideoModal, openVideoModal,
isAdminUser, isAdminUser,
isRootUser,
t, t,
COLUMN_KEYS, COLUMN_KEYS,
usageRecordMode = false, usageRecordMode = false,
@@ -57,6 +58,7 @@ const TaskLogsTable = (taskLogsData) => {
openVideoModal, openVideoModal,
isAdminUser, isAdminUser,
usageRecordMode, usageRecordMode,
isRootUser,
}); });
}, [ }, [
t, t,
@@ -66,6 +68,7 @@ const TaskLogsTable = (taskLogsData) => {
openVideoModal, openVideoModal,
isAdminUser, isAdminUser,
usageRecordMode, usageRecordMode,
isRootUser,
]); ]);
// Filter columns based on visibility settings // Filter columns based on visibility settings
+19 -3
View File
@@ -34,8 +34,19 @@ import { useTaskLogsData } from '../../../hooks/task-logs/useTaskLogsData';
import { useIsMobile } from '../../../hooks/common/useIsMobile'; import { useIsMobile } from '../../../hooks/common/useIsMobile';
import { createCardProPagination } from '../../../helpers/utils'; import { createCardProPagination } from '../../../helpers/utils';
const TaskLogsPage = ({ usageRecordMode = false }) => { const TaskLogsPage = ({
const taskLogsData = useTaskLogsData(); usageRecordMode = false,
organizationMode = false,
sharedStartTimestamp,
sharedEndTimestamp,
sharedFilterRevision = 0,
}) => {
const taskLogsData = useTaskLogsData({
organizationMode,
sharedStartTimestamp,
sharedEndTimestamp,
sharedFilterRevision,
});
const isMobile = useIsMobile(); const isMobile = useIsMobile();
// 与 CardPro 一致:移动端默认收起筛选区,仅视图状态 // 与 CardPro 一致:移动端默认收起筛选区,仅视图状态
const [showMobileFilters, setShowMobileFilters] = useState(false); const [showMobileFilters, setShowMobileFilters] = useState(false);
@@ -167,7 +178,12 @@ const TaskLogsPage = ({ usageRecordMode = false }) => {
statsArea={ statsArea={
<TaskLogsActions {...taskLogsData} logs={taskLogsData.logs} /> <TaskLogsActions {...taskLogsData} logs={taskLogsData.logs} />
} }
searchArea={<TaskLogsFilters {...taskLogsData} />} searchArea={
<TaskLogsFilters
{...taskLogsData}
hideDateRange={taskLogsData.usesSharedDateRange}
/>
}
paginationArea={createCardProPagination({ paginationArea={createCardProPagination({
currentPage: taskLogsData.activePage, currentPage: taskLogsData.activePage,
pageSize: taskLogsData.pageSize, pageSize: taskLogsData.pageSize,
@@ -30,6 +30,7 @@ const ColumnSelectorModal = ({
initDefaultColumns, initDefaultColumns,
COLUMN_KEYS, COLUMN_KEYS,
isAdminUser, isAdminUser,
isRootUser,
copyText, copyText,
openContentModal, openContentModal,
t, t,
@@ -41,6 +42,7 @@ const ColumnSelectorModal = ({
copyText, copyText,
openContentModal, openContentModal,
isAdminUser, isAdminUser,
isRootUser,
}); });
// 计算"全选"状态时应忽略的 key:当前角色下不可见的管理员专属列 // 计算"全选"状态时应忽略的 key:当前角色下不可见的管理员专属列
+63 -23
View File
@@ -24,6 +24,7 @@ import {
API, API,
copy, copy,
isAdmin, isAdmin,
isRoot,
showError, showError,
showSuccess, showSuccess,
timestamp2string, timestamp2string,
@@ -33,7 +34,25 @@ import { resolveColumnVisibility } from '../../helpers/columnVisibility';
import { ITEMS_PER_PAGE } from '../../constants'; import { ITEMS_PER_PAGE } from '../../constants';
import { useTableCompactMode } from '../common/useTableCompactMode'; import { useTableCompactMode } from '../common/useTableCompactMode';
export const useTaskLogsData = () => { const DEFAULT_TASK_RANGE_DAYS = 7;
const toUnixTimestamp = (value) => {
if (typeof value === 'number' && Number.isFinite(value)) {
return Math.floor(value);
}
if (value instanceof Date) {
return Math.floor(value.getTime() / 1000);
}
const parsed = Date.parse(value);
return Number.isFinite(parsed) ? Math.floor(parsed / 1000) : NaN;
};
export const useTaskLogsData = ({
organizationMode = false,
sharedStartTimestamp,
sharedEndTimestamp,
sharedFilterRevision = 0,
} = {}) => {
const { t } = useTranslation(); const { t } = useTranslation();
// Define column keys for selection // Define column keys for selection
@@ -44,7 +63,6 @@ export const useTaskLogsData = () => {
FINISH_TIME: 'finish_time', FINISH_TIME: 'finish_time',
DURATION: 'duration', DURATION: 'duration',
CHANNEL: 'channel', CHANNEL: 'channel',
PLATFORM: 'platform',
TYPE: 'type', TYPE: 'type',
MODEL: 'model', MODEL: 'model',
TASK_ID: 'task_id', TASK_ID: 'task_id',
@@ -62,11 +80,15 @@ export const useTaskLogsData = () => {
const [pageSize, setPageSize] = useState(ITEMS_PER_PAGE); const [pageSize, setPageSize] = useState(ITEMS_PER_PAGE);
// User and admin // User and admin
const isAdminUser = isAdmin(); const isAdminUser = !organizationMode && isAdmin();
// 任务 ID 详情包含完整任务记录,仅系统超级管理员可查看;企业用户始终不可打开
const isRootUser = !organizationMode && isRoot();
// Role-specific storage key to prevent different roles from overwriting each other // Role-specific storage key to prevent different roles from overwriting each other
const STORAGE_KEY = isAdminUser const STORAGE_KEY = organizationMode
? 'task-logs-table-columns-admin' ? 'task-logs-table-columns-organization'
: 'task-logs-table-columns-user'; : isAdminUser
? 'task-logs-table-columns-admin'
: 'task-logs-table-columns-user';
// Modal state // Modal state
const [isModalOpen, setIsModalOpen] = useState(false); const [isModalOpen, setIsModalOpen] = useState(false);
@@ -82,15 +104,20 @@ export const useTaskLogsData = () => {
// Form state // Form state
const [formApi, setFormApi] = useState(null); const [formApi, setFormApi] = useState(null);
// 每次调用都返回"此刻"的默认时间范围,避免长时间驻留页面后 const usesSharedDateRange =
// 点击"重置"仍得到页面加载时的"今日"(跨日 bug) organizationMode &&
Number.isFinite(Number(sharedStartTimestamp)) &&
Number.isFinite(Number(sharedEndTimestamp));
// 每次调用都返回"此刻"的默认时间范围,默认最近 7 天,避免任务页首屏
// 只查当天而遗漏历史任务;返回 Date 对象以便日期控件正确显示。
const getFreshDateRange = () => { const getFreshDateRange = () => {
const now = new Date(); const now = new Date();
const zeroNow = new Date(now.getFullYear(), now.getMonth(), now.getDate()); now.setSeconds(0, 0);
return [ const start = new Date(
timestamp2string(zeroNow.getTime() / 1000), now.getTime() - DEFAULT_TASK_RANGE_DAYS * 24 * 60 * 60 * 1000,
timestamp2string(now.getTime() / 1000 + 3600), );
]; return [start, now];
}; };
const getFreshInitValues = () => ({ const getFreshInitValues = () => ({
@@ -153,7 +180,6 @@ export const useTaskLogsData = () => {
[COLUMN_KEYS.FINISH_TIME]: true, [COLUMN_KEYS.FINISH_TIME]: true,
[COLUMN_KEYS.DURATION]: true, [COLUMN_KEYS.DURATION]: true,
[COLUMN_KEYS.CHANNEL]: isAdminUser, [COLUMN_KEYS.CHANNEL]: isAdminUser,
[COLUMN_KEYS.PLATFORM]: true,
[COLUMN_KEYS.TYPE]: true, [COLUMN_KEYS.TYPE]: true,
[COLUMN_KEYS.MODEL]: true, [COLUMN_KEYS.MODEL]: true,
[COLUMN_KEYS.TASK_ID]: true, [COLUMN_KEYS.TASK_ID]: true,
@@ -206,12 +232,17 @@ export const useTaskLogsData = () => {
// 否则 URL 带的 ?task_id=xxx 在第一次 loadLogs 时会被当成空字符串,导致初始列表不过滤 // 否则 URL 带的 ?task_id=xxx 在第一次 loadLogs 时会被当成空字符串,导致初始列表不过滤
const formValues = formApi ? formApi.getValues() : formInitValues; const formValues = formApi ? formApi.getValues() : formInitValues;
// 处理时间范围:每次调用时取"此刻"的默认值,避免闭包陈旧 // 企业页复用上方已经提交的时间范围;个人/平台任务页使用自己的日期控件。
const [freshStart, freshEnd] = getFreshDateRange(); const [freshStart, freshEnd] = getFreshDateRange();
let start_timestamp = freshStart; let start_timestamp = usesSharedDateRange
let end_timestamp = freshEnd; ? Number(sharedStartTimestamp)
: freshStart;
let end_timestamp = usesSharedDateRange
? Number(sharedEndTimestamp)
: freshEnd;
if ( if (
!usesSharedDateRange &&
formValues.dateRange && formValues.dateRange &&
Array.isArray(formValues.dateRange) && Array.isArray(formValues.dateRange) &&
formValues.dateRange.length === 2 formValues.dateRange.length === 2
@@ -295,8 +326,8 @@ export const useTaskLogsData = () => {
start_timestamp, start_timestamp,
end_timestamp, end_timestamp,
} = getFormValues(); } = getFormValues();
let localStartTimestamp = parseInt(Date.parse(start_timestamp) / 1000); let localStartTimestamp = toUnixTimestamp(start_timestamp);
let localEndTimestamp = parseInt(Date.parse(end_timestamp) / 1000); let localEndTimestamp = toUnixTimestamp(end_timestamp);
// 时间范围校验:起始晚于结束视为非法,避免白发一轮请求并给出提示 // 时间范围校验:起始晚于结束视为非法,避免白发一轮请求并给出提示
if ( if (
Number.isFinite(localStartTimestamp) && Number.isFinite(localStartTimestamp) &&
@@ -324,9 +355,11 @@ export const useTaskLogsData = () => {
// 与使用日志对齐:管理员可按 user_id 过滤任务日志 // 与使用日志对齐:管理员可按 user_id 过滤任务日志
if (user_id) params.set('user_id', user_id); if (user_id) params.set('user_id', user_id);
} }
const url = isAdminUser const url = organizationMode
? `/api/task/?${params.toString()}` ? `/api/org/tasks?${params.toString()}`
: `/api/task/self?${params.toString()}`; : isAdminUser
? `/api/task/?${params.toString()}`
: `/api/task/self?${params.toString()}`;
try { try {
const res = await API.get(url); const res = await API.get(url);
// 过时响应直接丢弃:reqId 小于最新值说明更新的请求已经发出 // 过时响应直接丢弃:reqId 小于最新值说明更新的请求已经发出
@@ -411,7 +444,12 @@ export const useTaskLogsData = () => {
parseInt(localStorage.getItem('task-page-size')) || ITEMS_PER_PAGE; parseInt(localStorage.getItem('task-page-size')) || ITEMS_PER_PAGE;
setPageSize(localPageSize); setPageSize(localPageSize);
loadLogs(1, localPageSize).then(); loadLogs(1, localPageSize).then();
}, []); }, [
organizationMode,
sharedStartTimestamp,
sharedEndTimestamp,
sharedFilterRevision,
]);
// 存在进行中的任务时,自动轮询刷新(10s 间隔),无 pending 则停止,避免无谓请求 // 存在进行中的任务时,自动轮询刷新(10s 间隔),无 pending 则停止,避免无谓请求
const loadLogsRef = useRef(loadLogs); const loadLogsRef = useRef(loadLogs);
@@ -463,6 +501,8 @@ export const useTaskLogsData = () => {
logCount, logCount,
pageSize, pageSize,
isAdminUser, isAdminUser,
isRootUser,
usesSharedDateRange,
// Modal state // Modal state
isModalOpen, isModalOpen,
+146 -129
View File
@@ -47,6 +47,7 @@ import {
import OrgPageHeader from './components/OrgPageHeader'; import OrgPageHeader from './components/OrgPageHeader';
import { OrgFilterCard, OrgListCard } from './components/OrgListCard'; import { OrgFilterCard, OrgListCard } from './components/OrgListCard';
import OrgModal from './components/OrgModal'; import OrgModal from './components/OrgModal';
import TaskLogsTable from '../../components/table/task-logs';
import { import {
API, API,
showError, showError,
@@ -233,6 +234,7 @@ const OrgLogs = ({ orgId, orgRole, isDeptManager = false }) => {
const [page, setPage] = useState(1); const [page, setPage] = useState(1);
const pageSize = 20; const pageSize = 20;
const [activeTab, setActiveTab] = useState('logs'); const [activeTab, setActiveTab] = useState('logs');
const [taskFilterRevision, setTaskFilterRevision] = useState(0);
const isAdmin = const isAdmin =
orgRole === 'owner' || orgRole === 'admin' || orgRole === 'super_admin'; orgRole === 'owner' || orgRole === 'admin' || orgRole === 'super_admin';
const canViewTeamUsage = isAdmin || isDeptManager; const canViewTeamUsage = isAdmin || isDeptManager;
@@ -344,6 +346,7 @@ const OrgLogs = ({ orgId, orgRole, isDeptManager = false }) => {
); );
} }
setPage(1); setPage(1);
setTaskFilterRevision((revision) => revision + 1);
}; };
// 重置:回到默认状态(滚动最近 7 天、不限成员/模型) // 重置:回到默认状态(滚动最近 7 天、不限成员/模型)
@@ -364,6 +367,7 @@ const OrgLogs = ({ orgId, orgRole, isDeptManager = false }) => {
}); });
} }
setPage(1); setPage(1);
setTaskFilterRevision((revision) => revision + 1);
}; };
// 导出弹窗状态(导出方式 + 字段勾选从 localStorage 恢复) // 导出弹窗状态(导出方式 + 字段勾选从 localStorage 恢复)
@@ -778,144 +782,157 @@ const OrgLogs = ({ orgId, orgRole, isDeptManager = false }) => {
onChange={setActiveTab} onChange={setActiveTab}
items={[ items={[
{ key: 'logs', label: t('明细日志') }, { key: 'logs', label: t('明细日志') },
{ key: 'tasks', label: t('绘图与视频') },
...(canViewTeamUsage ...(canViewTeamUsage
? [{ key: 'ranking', label: t('成员排行') }] ? [{ key: 'ranking', label: t('成员排行') }]
: []), : []),
]} ]}
/> />
{/* 筛选栏(原型 .ee-filter-card / .eex-filter-grid) */} {activeTab === 'tasks' ? (
<OrgFilterCard <TaskLogsTable
className='oc-exp-filter' usageRecordMode
actions={ organizationMode
<> sharedStartTimestamp={appliedFilters.startTimestamp}
<Button onClick={handleReset}>{t('重置')}</Button> sharedEndTimestamp={appliedFilters.endTimestamp}
<Button sharedFilterRevision={taskFilterRevision}
type='primary' />
icon={<Search size={16} />} ) : (
onClick={() => handleSearch(false)} <>
loading={loading} {/* 筛选栏(原型 .ee-filter-card / .eex-filter-grid) */}
> <OrgFilterCard
{t('搜索')} className='oc-exp-filter'
</Button> actions={
</> <>
} <Button onClick={handleReset}>{t('重置')}</Button>
> <Button
<AntForm layout='vertical' requiredMark={false} component='div'> type='primary'
<AntForm.Item label={t('成员')}> icon={<Search size={16} />}
{canViewTeamUsage ? ( onClick={() => handleSearch(false)}
<Select loading={loading}
value={selectedUserId} >
onChange={setSelectedUserId} {t('搜索')}
optionList={memberOptions} </Button>
style={{ width: '100%' }} </>
placeholder={isAdmin ? t('全部成员') : t('全部部门成员')} }
filter >
<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={16} />}
onClick={() => handleSearch(true)}
loading={loading}
>
{t('刷新')}
</Button>
</>
}
>
{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>
<p className='text-gray-400 dark:text-gray-500 text-sm'>
{t('暂无排行数据')}
</p>
</div>
}
/> />
) : ( ) : (
<div className='oc-exp-self'>{t('仅本人')}</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>
}
/>
)} )}
</AntForm.Item> </OrgListCard>
</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={16} />}
onClick={() => handleSearch(true)}
loading={loading}
>
{t('刷新')}
</Button>
</>
}
>
{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>
<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 <OrgModal
+95
View File
@@ -0,0 +1,95 @@
/*
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 assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import test from 'node:test';
const hook = readFileSync(
new URL('../src/hooks/task-logs/useTaskLogsData.js', import.meta.url),
'utf8',
);
const columns = readFileSync(
new URL(
'../src/components/table/task-logs/TaskLogsColumnDefs.jsx',
import.meta.url,
),
'utf8',
);
const actions = readFileSync(
new URL(
'../src/components/table/task-logs/TaskLogsActions.jsx',
import.meta.url,
),
'utf8',
);
const filters = readFileSync(
new URL(
'../src/components/table/task-logs/TaskLogsFilters.jsx',
import.meta.url,
),
'utf8',
);
const orgLogs = readFileSync(
new URL('../src/pages/Organization/OrgLogs.jsx', import.meta.url),
'utf8',
);
const usageRecord = readFileSync(
new URL('../src/pages/UserCenter/UsageRecord.jsx', import.meta.url),
'utf8',
);
test('enterprise task records use the organization-scoped endpoint', () => {
assert.match(hook, /organizationMode/);
assert.match(hook, /`\/api\/org\/tasks\?\$\{params\.toString\(\)\}`/);
assert.match(
orgLogs,
/sharedStartTimestamp=\{appliedFilters\.startTimestamp\}/,
);
assert.match(orgLogs, /sharedEndTimestamp=\{appliedFilters\.endTimestamp\}/);
assert.match(orgLogs, /sharedFilterRevision=\{taskFilterRevision\}/);
assert.match(hook, /DEFAULT_TASK_RANGE_DAYS = 7/);
assert.match(hook, /const usesSharedDateRange/);
assert.match(filters, /hideDateRange = false/);
assert.match(filters, /!hideDateRange/);
});
test('platform is not exposed as a task-log presentation field', () => {
assert.doesNotMatch(columns, /COLUMN_KEYS\.PLATFORM/);
assert.doesNotMatch(columns, /title: t\('平台'\)/);
assert.doesNotMatch(actions, /key: 'platform'/);
assert.doesNotMatch(actions, /title: t\('平台'\)/);
});
test('task details can only be opened by the system root user', () => {
assert.match(
hook,
/import \{[\s\S]*isRoot[\s\S]*\} from '\.\.\/\.\.\/helpers';/,
);
assert.match(hook, /const isRootUser = !organizationMode && isRoot\(\);/);
assert.match(columns, /isRootUser = false/);
assert.match(columns, /isRootUser\s*\?\s*\(\) => openContentModal/);
assert.match(columns, /isRootUser\s*\?\s*'cursor-pointer/);
});
test('personal usage records reuse the same platform-free task view', () => {
assert.match(usageRecord, /<TaskLogsTable usageRecordMode \/>/);
assert.doesNotMatch(actions, /key: 'platform'/);
assert.match(columns, /isRootUser\s*\?\s*\(\) => openContentModal/);
});