feat: 自行开发设计 ui样式优化 超管端-控制台 相关的页面
This commit is contained in:
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
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 TableEmpty from '../../../components/common/table/TableEmpty';
|
||||
import React, { useMemo } from 'react';
|
||||
import { Card, Table, Tag } from 'antd';
|
||||
import { Clock, Download, RefreshCw } from 'lucide-react';
|
||||
import { Button, Pagination } from '@/components/ui';
|
||||
import { useTaskLogsData } from '../../../hooks/task-logs/useTaskLogsData';
|
||||
import { useIsMobile } from '../../../hooks/common/useIsMobile';
|
||||
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 isMobile = useIsMobile();
|
||||
// 仅用于“实时更新中”提示(存在进行中任务时轮询);原型无“本页统计”区块,不渲染
|
||||
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
|
||||
bordered={false}
|
||||
color='processing'
|
||||
icon={<Clock size={12} />}
|
||||
>
|
||||
{t('实时更新中')}
|
||||
</Tag>
|
||||
)}
|
||||
{/* 导出当前页为 CSV,空列表时禁用 */}
|
||||
<Button
|
||||
icon={<Download size={16} />}
|
||||
onClick={() => exportTaskLogsPageCsv(logs, isAdminUser, t)}
|
||||
disabled={!logs || logs.length === 0}
|
||||
>
|
||||
{t('导出本页')}
|
||||
</Button>
|
||||
{/* 与筛选“搜索”同一处理函数(同步 URL 筛选条件并重新加载第 1 页) */}
|
||||
<Button
|
||||
icon={<RefreshCw 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={false}
|
||||
scroll={{ x: scrollX }}
|
||||
locale={{
|
||||
emptyText: <TableEmpty />,
|
||||
}}
|
||||
/>
|
||||
{taskLogsData.logCount > 0 && (
|
||||
<Pagination
|
||||
currentPage={taskLogsData.activePage}
|
||||
pageSize={taskLogsData.pageSize}
|
||||
total={taskLogsData.logCount}
|
||||
pageSizeOpts={[10, 20, 50]}
|
||||
showSizeChanger
|
||||
onPageSizeChange={taskLogsData.handlePageSizeChange}
|
||||
onPageChange={taskLogsData.handlePageChange}
|
||||
preventPageChangeOnPageSizeChange={false}
|
||||
showQuickJumper={isMobile}
|
||||
showTotal={(total) => t('共 {{total}} 条', { total })}
|
||||
/>
|
||||
)}
|
||||
</OrgListCard>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default OrgTaskRecords;
|
||||
Reference in New Issue
Block a user