Files
monkey-ai-web/src/components/table/task-logs/index.jsx
T

205 lines
7.2 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 } from '@/components/common/icons/ActionIcons';
import React, { useState } from 'react';
import { Card, Tag as AntTag } from 'antd';
import { Clock } from 'lucide-react';
import { Button, Pagination } from '@/components/ui';
import CardPro from '../../common/ui/CardPro';
import { ColumnSettingsButton } from '../../common/table/ColumnSettings';
import TaskLogsTable from './TaskLogsTable';
import TaskLogsActions, {
exportTaskLogsPageCsv,
useTaskPageStats,
} from './TaskLogsActions';
import TaskLogsFilters from './TaskLogsFilters';
import ColumnSelectorModal from './modals/ColumnSelectorModal';
import ContentModal from './modals/ContentModal';
import { useTaskLogsData } from '../../../hooks/task-logs/useTaskLogsData';
import { useIsMobile } from '../../../hooks/common/useIsMobile';
import { createCardProPagination } from '../../../helpers/utils';
const TaskLogsPage = ({
usageRecordMode = false,
organizationMode = false,
sharedStartTimestamp,
sharedEndTimestamp,
sharedFilterRevision = 0,
}) => {
const taskLogsData = useTaskLogsData({
organizationMode,
sharedStartTimestamp,
sharedEndTimestamp,
sharedFilterRevision,
});
const isMobile = useIsMobile();
// 与 CardPro 一致:移动端默认收起筛选区,仅视图状态
const [showMobileFilters, setShowMobileFilters] = useState(false);
const pageStats = useTaskPageStats(taskLogsData.logs);
if (usageRecordMode) {
const { t, logs, isAdminUser } = taskLogsData;
return (
<>
<ColumnSelectorModal {...taskLogsData} usageRecordMode />
<ContentModal {...taskLogsData} isVideo={false} />
{/* 视频预览弹窗 */}
<ContentModal
isModalOpen={taskLogsData.isVideoModalOpen}
setIsModalOpen={taskLogsData.setIsVideoModalOpen}
modalContent={taskLogsData.videoUrl}
sourceUrl={taskLogsData.videoSourceUrl}
isVideo={true}
/>
<div className='usage-record-panels'>
<TaskLogsActions {...taskLogsData} usageRecordMode />
<Card className='usage-record-card usage-record-filter-card'>
{isMobile && (
<Button
block
className='usage-record-mobile-toggle'
onClick={() => setShowMobileFilters(!showMobileFilters)}
>
{showMobileFilters ? t('隐藏操作项') : t('显示操作项')}
</Button>
)}
<div hidden={isMobile && !showMobileFilters}>
<TaskLogsFilters {...taskLogsData} usageRecordMode />
</div>
</Card>
<Card className='usage-record-card usage-record-table-card'>
<div className='usage-record-table-head'>
<h3>{t('任务记录')}</h3>
<div className='usage-record-table-actions'>
{/* 只有真实存在进行中任务时才显示,避免误导 */}
{pageStats.pendingCount > 0 && (
<AntTag
bordered={false}
color='processing'
icon={<Clock size={12} />}
>
{t('实时更新中')}
</AntTag>
)}
{/* 导出当前页为 CSV,空列表时禁用避免生成只有表头的无用文件 */}
<Button
icon={<ActionDownload size={14} />}
onClick={() => exportTaskLogsPageCsv(logs, isAdminUser, t)}
disabled={!logs || logs.length === 0}
>
{t('导出本页')}
</Button>
<ColumnSettingsButton
open={taskLogsData.showColumnSelector}
onClick={() => taskLogsData.setShowColumnSelector(true)}
/>
</div>
</div>
<TaskLogsTable
{...taskLogsData}
compactMode={false}
usageRecordMode
/>
{taskLogsData.logCount > 0 && (
<div className='usage-record-pagination'>
<Pagination
currentPage={taskLogsData.activePage}
pageSize={taskLogsData.pageSize}
total={taskLogsData.logCount}
pageSizeOpts={[10, 20, 50, 100]}
showSizeChanger
onPageSizeChange={taskLogsData.handlePageSizeChange}
onPageChange={taskLogsData.handlePageChange}
preventPageChangeOnPageSizeChange={false}
size='small'
showQuickJumper={isMobile}
showTotal={(total) => t('共 {{total}} 条', { total })}
/>
</div>
)}
</Card>
</div>
</>
);
}
return (
<div className='relative'>
{/* 装饰性网格背景 */}
{/* Modals */}
<ColumnSelectorModal {...taskLogsData} />
<ContentModal {...taskLogsData} isVideo={false} />
{/* 视频预览弹窗 */}
<ContentModal
isModalOpen={taskLogsData.isVideoModalOpen}
setIsModalOpen={taskLogsData.setIsVideoModalOpen}
modalContent={taskLogsData.videoUrl}
sourceUrl={taskLogsData.videoSourceUrl}
isVideo={true}
/>
{/* Main Content */}
<CardPro
tableTitle={taskLogsData.t('任务明细')}
type='type2'
className='!bg-transparent !border-0 !shadow-none relative'
statsArea={
<TaskLogsActions {...taskLogsData} logs={taskLogsData.logs} />
}
searchArea={
<TaskLogsFilters
{...taskLogsData}
hideDateRange={taskLogsData.usesSharedDateRange}
/>
}
tableActions={
<ColumnSettingsButton
open={taskLogsData.showColumnSelector}
onClick={() => taskLogsData.setShowColumnSelector(true)}
/>
}
paginationArea={createCardProPagination({
showRange: false,
currentPage: taskLogsData.activePage,
pageSize: taskLogsData.pageSize,
total: taskLogsData.logCount,
onPageChange: taskLogsData.handlePageChange,
onPageSizeChange: taskLogsData.handlePageSizeChange,
isMobile: isMobile,
t: taskLogsData.t,
})}
t={taskLogsData.t}
>
{/* 表格容器 */}
<TaskLogsTable
{...taskLogsData}
compactMode={taskLogsData.compactMode}
/>
</CardPro>
</div>
);
};
export default TaskLogsPage;