mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-09-07 00:27:44 +08:00
refactor(Web): optimize task management and layout styles
This commit is contained in:
@@ -145,20 +145,14 @@ function AdminLayout() {
|
|||||||
currentRouteData={headerRouteData}
|
currentRouteData={headerRouteData}
|
||||||
isMobile={isMobile}
|
isMobile={isMobile}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Content style={{
|
<Content style={{
|
||||||
margin: isMobile ? '10px' : '20px',
|
padding: isMobile ? '10px' : '20px',
|
||||||
background: '#f0f2f5',
|
background: colorBgContainer,
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
borderRadius: isMobile ? 10 : 20,
|
|
||||||
overflowY: 'auto'
|
overflowY: 'auto'
|
||||||
}}>
|
}}>
|
||||||
<div style={{
|
<div style={{
|
||||||
padding: isMobile ? '15px' : '25px',
|
|
||||||
minHeight: '100%',
|
minHeight: '100%',
|
||||||
background: colorBgContainer,
|
|
||||||
boxShadow: '0 6px 30px rgba(0,0,0,0.03)',
|
|
||||||
border: '1px solid #f0f0f0',
|
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
overflow: 'hidden'
|
overflow: 'hidden'
|
||||||
}}>
|
}}>
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ function AllImages() {
|
|||||||
const [isUploadDialogVisible, setIsUploadDialogVisible] = useState(false);
|
const [isUploadDialogVisible, setIsUploadDialogVisible] = useState(false);
|
||||||
const [refreshTrigger, setRefreshTrigger] = useState(0);
|
const [refreshTrigger, setRefreshTrigger] = useState(0);
|
||||||
const sortByRef = useRef(sortBy);
|
const sortByRef = useRef(sortBy);
|
||||||
// 优化handleSortChange,减少不必要的状态更新
|
|
||||||
const handleSortChange = (newSortBy: string) => {
|
const handleSortChange = (newSortBy: string) => {
|
||||||
if (sortBy !== newSortBy) {
|
if (sortBy !== newSortBy) {
|
||||||
setSortBy(newSortBy);
|
setSortBy(newSortBy);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useState, useEffect, useCallback } from 'react';
|
import React, { useState, useEffect, useCallback } from 'react';
|
||||||
import { Typography, Table, Card, Tag, Space, Button, Empty, message, Modal } from 'antd';
|
import { Typography, Table, Card, Tag, Button, Empty, message } from 'antd';
|
||||||
import { SyncOutlined, EyeOutlined } from '@ant-design/icons';
|
import { SyncOutlined } from '@ant-design/icons';
|
||||||
import { getUserTasks, TaskExecutionStatus } from '../../api';
|
import { getUserTasks, TaskExecutionStatus } from '../../api';
|
||||||
import { type TaskDetailsViewModel } from '../../api';
|
import { type TaskDetailsViewModel } from '../../api';
|
||||||
import TaskProgressBar from '../../components/TaskProgressBar';
|
import TaskProgressBar from '../../components/TaskProgressBar';
|
||||||
@@ -12,10 +12,7 @@ const { Title, Text } = Typography;
|
|||||||
|
|
||||||
// 定义任务类型映射
|
// 定义任务类型映射
|
||||||
const taskTypeDisplayMapping: { [key: number]: string } = {
|
const taskTypeDisplayMapping: { [key: number]: string } = {
|
||||||
0: '图片处理', // 对应后端的 PictureProcessing = 0
|
0: '图片处理',
|
||||||
// 如果有其他任务类型,在此处添加
|
|
||||||
// 1: '视频处理',
|
|
||||||
// 2: '数据导出',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const BackgroundTasks: React.FC = () => {
|
const BackgroundTasks: React.FC = () => {
|
||||||
@@ -25,9 +22,11 @@ const BackgroundTasks: React.FC = () => {
|
|||||||
const [pollingInterval, setPollingIntervalState] = useState<number | null>(null);
|
const [pollingInterval, setPollingIntervalState] = useState<number | null>(null);
|
||||||
|
|
||||||
// 加载任务数据
|
// 加载任务数据
|
||||||
const fetchTasks = useCallback(async () => {
|
const fetchTasks = useCallback(async (showLoading = true) => {
|
||||||
try {
|
try {
|
||||||
|
if (showLoading) {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
}
|
||||||
const result = await getUserTasks();
|
const result = await getUserTasks();
|
||||||
if (result.success && result.data) {
|
if (result.success && result.data) {
|
||||||
setTasks(result.data);
|
setTasks(result.data);
|
||||||
@@ -38,8 +37,10 @@ const BackgroundTasks: React.FC = () => {
|
|||||||
console.error('获取任务失败:', error);
|
console.error('获取任务失败:', error);
|
||||||
message.error('加载任务列表时出错');
|
message.error('加载任务列表时出错');
|
||||||
} finally {
|
} finally {
|
||||||
|
if (showLoading) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// 自动刷新逻辑
|
// 自动刷新逻辑
|
||||||
@@ -48,7 +49,7 @@ const BackgroundTasks: React.FC = () => {
|
|||||||
|
|
||||||
// 设置轮询
|
// 设置轮询
|
||||||
if (pollingActive) {
|
if (pollingActive) {
|
||||||
const interval = setInterval(fetchTasks, 3000); // 轮询间隔调整为3秒
|
const interval = setInterval(() => fetchTasks(false), 3000); // 轮询时不显示加载动画
|
||||||
setPollingIntervalState(interval as unknown as number); // 保存 interval ID
|
setPollingIntervalState(interval as unknown as number); // 保存 interval ID
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,12 +118,6 @@ const BackgroundTasks: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 渲染错误信息
|
// 渲染错误信息
|
||||||
const showErrorMessage = (error: string) => {
|
|
||||||
Modal.error({
|
|
||||||
title: '处理失败',
|
|
||||||
content: error,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// 表格列定义
|
// 表格列定义
|
||||||
const columns: ColumnType<TaskDetailsViewModel>[] = [ // Updated type
|
const columns: ColumnType<TaskDetailsViewModel>[] = [ // Updated type
|
||||||
@@ -186,31 +181,7 @@ const BackgroundTasks: React.FC = () => {
|
|||||||
key: 'completedAt',
|
key: 'completedAt',
|
||||||
render: (date: Date | undefined) => formatDate(date), // Ensure date can be undefined
|
render: (date: Date | undefined) => formatDate(date), // Ensure date can be undefined
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: '操作',
|
|
||||||
key: 'action',
|
|
||||||
render: (_: any, record: TaskDetailsViewModel) => ( // Updated type
|
|
||||||
<Space size="middle">
|
|
||||||
{record.taskType === 0 && record.relatedEntityId && (
|
|
||||||
<Link to={`/pictures/${record.relatedEntityId}`}>
|
|
||||||
<Button type="link" icon={<EyeOutlined />} size="small">
|
|
||||||
查看关联图片
|
|
||||||
</Button>
|
|
||||||
</Link>
|
|
||||||
)}
|
|
||||||
{record.status === TaskExecutionStatus.Failed && record.error && ( // 使用数字枚举成员
|
|
||||||
<Button
|
|
||||||
type="link"
|
|
||||||
danger
|
|
||||||
size="small"
|
|
||||||
onClick={() => showErrorMessage(record.error!)}
|
|
||||||
>
|
|
||||||
查看错误
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</Space>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -231,17 +202,17 @@ const BackgroundTasks: React.FC = () => {
|
|||||||
background: 'linear-gradient(120deg, #000000, #444444)',
|
background: 'linear-gradient(120deg, #000000, #444444)',
|
||||||
WebkitBackgroundClip: 'text',
|
WebkitBackgroundClip: 'text',
|
||||||
WebkitTextFillColor: 'transparent',
|
WebkitTextFillColor: 'transparent',
|
||||||
}}>图片处理队列</Title>
|
}}>任务中心</Title>
|
||||||
<Text type="secondary" style={{
|
<Text type="secondary" style={{
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
color: '#888',
|
color: '#888',
|
||||||
letterSpacing: '0.3px'
|
letterSpacing: '0.3px'
|
||||||
}}>查看和管理图片后台处理任务</Text>
|
}}>查看和管理后台处理任务</Text>
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
type="primary"
|
type="primary"
|
||||||
icon={<SyncOutlined />}
|
icon={<SyncOutlined />}
|
||||||
onClick={fetchTasks}
|
onClick={() => fetchTasks()}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
>
|
>
|
||||||
刷新
|
刷新
|
||||||
|
|||||||
Reference in New Issue
Block a user