273 lines
8.9 KiB
React
273 lines
8.9 KiB
React
/*
|
||
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 {
|
||
Download as ActionDownload,
|
||
RefreshCw as ActionRefreshCw,
|
||
} from '@/components/common/icons/ActionIcons';
|
||
import TableEmpty from '../../../components/common/table/TableEmpty';
|
||
import React, { useMemo } from 'react';
|
||
import { Card, Tag } from 'antd';
|
||
import { Clock } from 'lucide-react';
|
||
import { Button, Table } from '@/components/ui';
|
||
import { useTaskLogsData } from '../../../hooks/task-logs/useTaskLogsData';
|
||
import { timestamp2string } from '../../../helpers';
|
||
import { getTaskLogsColumns } from '../../../components/table/task-logs/TaskLogsColumnDefs';
|
||
import TaskLogsFilters from '../../../components/table/task-logs/TaskLogsFilters';
|
||
import {
|
||
exportTaskLogsPageCsv,
|
||
useTaskPageStats,
|
||
} from '../../../components/table/task-logs/TaskLogsActions';
|
||
import ColumnSelectorModal from '../../../components/table/task-logs/modals/ColumnSelectorModal';
|
||
import ContentModal from '../../../components/table/task-logs/modals/ContentModal';
|
||
import { OrgListCard } from './OrgListCard';
|
||
import { ColumnSettingsButton } from '../../../components/common/table/ColumnSettings';
|
||
|
||
// 原型 EnterpriseExpenseTasks 列宽(提交 / 结束 185、花费 110、类型 110、模型 250、任务 ID 330、状态 110、进度 155、费用 145、末列 150)
|
||
const COLUMN_WIDTHS = {
|
||
submit_time: 185,
|
||
finish_time: 185,
|
||
duration: 110,
|
||
channel: 85,
|
||
type: 110,
|
||
model: 250,
|
||
task_id: 330,
|
||
task_status: 110,
|
||
progress: 155,
|
||
quota: 145,
|
||
fail_reason: 150,
|
||
};
|
||
|
||
/**
|
||
* 企业中心「消耗明细 → 绘图与视频」(原型 .eex-task-records:筛选卡 + “任务记录”列表卡)。
|
||
* 与原型一致,本页签使用自身筛选卡中的时间范围(默认最近 7 天,可编辑),不受“明细日志”筛选影响;
|
||
* 数据、请求、URL 同步、分页、列显隐、复制与预览回调全部来自原 useTaskLogsData(organizationMode);
|
||
* 列渲染复用 getTaskLogsColumns 的使用记录分支,只包一层企业页类名与原型列宽。
|
||
*/
|
||
const OrgTaskRecords = () => {
|
||
const taskLogsData = useTaskLogsData({ organizationMode: true });
|
||
const {
|
||
t,
|
||
logs,
|
||
loading,
|
||
isAdminUser,
|
||
isRootUser,
|
||
COLUMN_KEYS,
|
||
copyText,
|
||
openContentModal,
|
||
openVideoModal,
|
||
visibleColumns,
|
||
} = taskLogsData;
|
||
// 仅用于“实时更新中”提示(存在进行中任务时轮询);原型无“本页统计”区块,不渲染
|
||
const pageStats = useTaskPageStats(logs);
|
||
|
||
const configurableColumns = useMemo(() => {
|
||
const base = getTaskLogsColumns({
|
||
t,
|
||
COLUMN_KEYS,
|
||
copyText,
|
||
openContentModal,
|
||
openVideoModal,
|
||
isAdminUser,
|
||
usageRecordMode: true,
|
||
isRootUser,
|
||
});
|
||
return base.map((column) => {
|
||
const width = COLUMN_WIDTHS[column.key];
|
||
switch (column.key) {
|
||
// 原型为单行“YYYY-MM-DD HH:mm:ss”
|
||
case COLUMN_KEYS.SUBMIT_TIME:
|
||
case COLUMN_KEYS.FINISH_TIME:
|
||
return {
|
||
...column,
|
||
width,
|
||
render: (value) =>
|
||
value ? (
|
||
<span className='oc-number'>{timestamp2string(value)}</span>
|
||
) : (
|
||
'-'
|
||
),
|
||
};
|
||
case COLUMN_KEYS.DURATION:
|
||
return {
|
||
...column,
|
||
width,
|
||
render: (...args) => (
|
||
<span className='oc-number'>{column.render(...args)}</span>
|
||
),
|
||
};
|
||
case COLUMN_KEYS.MODEL:
|
||
return {
|
||
...column,
|
||
width,
|
||
render: (...args) => (
|
||
<span className='oc-task-model'>{column.render(...args)}</span>
|
||
),
|
||
};
|
||
case COLUMN_KEYS.TASK_ID:
|
||
return {
|
||
...column,
|
||
// 原型列名“任务 ID”(与筛选标签同一文案)
|
||
title: t('任务 ID'),
|
||
width,
|
||
render: (...args) => {
|
||
const node = column.render(...args);
|
||
return (
|
||
<span className='oc-task-id'>
|
||
{node?.props?.children ?? node}
|
||
</span>
|
||
);
|
||
},
|
||
};
|
||
case COLUMN_KEYS.QUOTA:
|
||
return {
|
||
...column,
|
||
width,
|
||
align: 'right',
|
||
render: (...args) => {
|
||
const node = column.render(...args);
|
||
return node?.type === 'span' ? (
|
||
<span className='oc-exp-cost'>{node.props.children}</span>
|
||
) : (
|
||
node
|
||
);
|
||
},
|
||
};
|
||
case COLUMN_KEYS.FAIL_REASON: {
|
||
// 原型末列“操作”:随表格横向滚动(不固定),无可操作内容时显示“-”;
|
||
// 预览视频链接与失败原因查看保持原节点与回调
|
||
const { fixed: _fixed, ...rest } = column;
|
||
return {
|
||
...rest,
|
||
title: t('操作'),
|
||
width,
|
||
render: (...args) => {
|
||
const node = column.render(...args);
|
||
return (
|
||
<span className='oc-task-detail'>
|
||
{node?.type === 'span' ? '-' : node}
|
||
</span>
|
||
);
|
||
},
|
||
};
|
||
}
|
||
default:
|
||
return width ? { ...column, width } : column;
|
||
}
|
||
});
|
||
}, [
|
||
t,
|
||
COLUMN_KEYS,
|
||
copyText,
|
||
openContentModal,
|
||
openVideoModal,
|
||
isAdminUser,
|
||
isRootUser,
|
||
]);
|
||
|
||
const columns = configurableColumns.filter(
|
||
(column) => visibleColumns[column.key],
|
||
);
|
||
const scrollX = columns.reduce(
|
||
(total, column) => total + (column.width || 120),
|
||
0,
|
||
);
|
||
|
||
return (
|
||
<div className='oc-task-records'>
|
||
<ColumnSelectorModal
|
||
{...taskLogsData}
|
||
usageRecordMode
|
||
columns={configurableColumns}
|
||
/>
|
||
<ContentModal {...taskLogsData} isVideo={false} />
|
||
{/* 视频预览弹窗:复用 ContentModal */}
|
||
<ContentModal
|
||
isModalOpen={taskLogsData.isVideoModalOpen}
|
||
setIsModalOpen={taskLogsData.setIsVideoModalOpen}
|
||
modalContent={taskLogsData.videoUrl}
|
||
sourceUrl={taskLogsData.videoSourceUrl}
|
||
isVideo={true}
|
||
/>
|
||
|
||
{/* 原型移动端筛选卡直接展开(与“明细日志”页签一致),不设收起开关 */}
|
||
<Card className='oc-filter-card oc-task-filter'>
|
||
<TaskLogsFilters {...taskLogsData} usageRecordMode />
|
||
</Card>
|
||
|
||
<OrgListCard
|
||
className='oc-task-list'
|
||
title={t('任务记录')}
|
||
tools={
|
||
<>
|
||
{/* 只有真实存在进行中任务时才显示,避免误导 */}
|
||
{pageStats.pendingCount > 0 && (
|
||
<Tag
|
||
variant='filled'
|
||
color='processing'
|
||
icon={<Clock size={12} />}
|
||
>
|
||
{t('实时更新中')}
|
||
</Tag>
|
||
)}
|
||
{/* 导出当前页为 CSV,空列表时禁用 */}
|
||
<Button
|
||
icon={<ActionDownload size={16} />}
|
||
onClick={() => exportTaskLogsPageCsv(logs, isAdminUser, t)}
|
||
disabled={!logs || logs.length === 0}
|
||
>
|
||
{t('导出本页')}
|
||
</Button>
|
||
{/* 与筛选“搜索”同一处理函数(同步 URL 筛选条件并重新加载第 1 页) */}
|
||
<Button
|
||
icon={<ActionRefreshCw size={16} />}
|
||
onClick={() => taskLogsData.refresh()}
|
||
loading={loading}
|
||
>
|
||
{t('刷新')}
|
||
</Button>
|
||
<ColumnSettingsButton
|
||
open={taskLogsData.showColumnSelector}
|
||
onClick={() => taskLogsData.setShowColumnSelector(true)}
|
||
/>
|
||
</>
|
||
}
|
||
>
|
||
<Table
|
||
columns={columns}
|
||
dataSource={logs}
|
||
rowKey='key'
|
||
loading={loading}
|
||
pagination={{
|
||
currentPage: taskLogsData.activePage,
|
||
pageSize: taskLogsData.pageSize,
|
||
total: taskLogsData.logCount,
|
||
onPageSizeChange: taskLogsData.handlePageSizeChange,
|
||
onPageChange: taskLogsData.handlePageChange,
|
||
}}
|
||
scroll={{ x: scrollX }}
|
||
empty={<TableEmpty />}
|
||
/>
|
||
</OrgListCard>
|
||
</div>
|
||
);
|
||
};
|
||
|
||
export default OrgTaskRecords;
|