From 5560dbf042cfb8c36084e2b38988d045aa87c379 Mon Sep 17 00:00:00 2001 From: yxsj245 <17737475682@163.com> Date: Sun, 5 Apr 2026 17:46:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8E=8B=E7=BC=A9=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=BC=BA=E7=94=A8=E6=88=B7=E5=8F=8D=E9=A6=88=E5=92=8C=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/pages/FileManagerPage.tsx | 102 +++++++++++++++++++-------- client/src/stores/fileStore.ts | 19 ++--- docs/压缩任务错误提示优化说明.md | 23 ++++++ server/src/utils/zipToolsManager.ts | 32 +++++++-- 4 files changed, 135 insertions(+), 41 deletions(-) create mode 100644 docs/压缩任务错误提示优化说明.md diff --git a/client/src/pages/FileManagerPage.tsx b/client/src/pages/FileManagerPage.tsx index f52b895..2d6bbfb 100644 --- a/client/src/pages/FileManagerPage.tsx +++ b/client/src/pages/FileManagerPage.tsx @@ -75,7 +75,7 @@ import { ImagePreview } from '@/components/ImagePreview' import { EncodingConfirmDialog } from '@/components/EncodingConfirmDialog' import { FileChangedDialog } from '@/components/FileChangedDialog' import PasteConflictDialog from '@/components/PasteConflictDialog' -import { FileItem } from '@/types/file' +import { FileItem, Task } from '@/types/file' import socketClient from '@/utils/socket' import { fileApiClient } from '@/utils/fileApi' import { isTextFile, isImageFile } from '@/utils/format' @@ -193,6 +193,7 @@ const FileManagerPage: React.FC = () => { const [searchResults, setSearchResults] = useState([]) const [isSearching, setIsSearching] = useState(false) const searchTimeoutRef = useRef(null) + const previousActiveTaskCountRef = useRef(0) // 历史记录 const [history, setHistory] = useState([]) @@ -774,6 +775,7 @@ const FileManagerPage: React.FC = () => { // 初始加载任务列表 loadActiveTasks() + loadTasks() // 加载系统盘符 loadDrives() @@ -783,7 +785,7 @@ const FileManagerPage: React.FC = () => { // 预加载系统信息(用于右键菜单权限判断) fetchSystemInfo() - }, [searchParams, setCurrentPath, loadFiles, fetchSystemInfo, loadFavorites]) + }, [searchParams, setCurrentPath, loadFiles, loadActiveTasks, loadTasks, fetchSystemInfo, loadFavorites]) // 当路径变化时更新选中的盘符 useEffect(() => { @@ -795,23 +797,26 @@ const FileManagerPage: React.FC = () => { } }, [currentPath, drives, selectedDrive, findDriveForPath]) - // 定期刷新活动任务 + // 定期刷新任务状态 useEffect(() => { const interval = setInterval(() => { - if (activeTasks.length > 0) { + if (taskDrawerVisible || activeTasks.length > 0) { loadActiveTasks() - // 如果有任务完成,刷新文件列表 - const hasCompletedTasks = activeTasks.some(task => - task.status === 'completed' || task.status === 'failed' - ) - if (hasCompletedTasks) { - loadFiles(undefined, true) // 重置分页 - } + loadTasks() } }, 2000) // 每2秒刷新一次 return () => clearInterval(interval) - }, [activeTasks, loadFiles]) + }, [activeTasks.length, taskDrawerVisible, loadActiveTasks, loadTasks]) + + useEffect(() => { + if (previousActiveTaskCountRef.current > 0 && activeTasks.length === 0) { + loadTasks() + loadFiles(undefined, true) + } + + previousActiveTaskCountRef.current = activeTasks.length + }, [activeTasks.length, loadFiles, loadTasks]) // 键盘快捷键 useEffect(() => { @@ -1268,7 +1273,7 @@ const FileManagerPage: React.FC = () => { const handleCompressConfirm = async (archiveName: string, format: string, compressionLevel: number) => { const filePaths = compressDialog.files.map(file => file.path) - const success = await compressFiles(filePaths, archiveName, format) + const success = await compressFiles(filePaths, archiveName, format, compressionLevel) if (success) { addNotification({ type: 'success', @@ -1524,6 +1529,42 @@ const FileManagerPage: React.FC = () => { } } + const getTaskTypeText = (type: Task['type']) => { + switch (type) { + case 'compress': + return '压缩' + case 'extract': + return '解压' + case 'copy': + return '复制' + case 'move': + return '移动' + case 'download': + return '下载' + default: + return type + } + } + + const getTaskTargetText = (task: Task) => { + const archivePath = typeof task.data?.archivePath === 'string' ? task.data.archivePath : '' + const targetPath = typeof task.data?.targetPath === 'string' ? task.data.targetPath : '' + + if ((task.type === 'compress' || task.type === 'extract') && archivePath) { + return getBasename(archivePath) + } + + if (task.type === 'download' && targetPath) { + return getBasename(targetPath) + } + + return '' + } + + const visibleTasks = [...tasks] + .sort((a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()) + .slice(0, 12) + return (
{/* 工具栏 */} @@ -2426,27 +2467,30 @@ const FileManagerPage: React.FC = () => { width={400} >
- {activeTasks.length === 0 ? ( + {visibleTasks.length === 0 ? ( ) : ( - activeTasks.map((task) => ( + visibleTasks.map((task) => (
-
- {getTaskStatusIcon(task.status)} - - {task.type === 'compress' ? '压缩' : - task.type === 'extract' ? '解压' : - task.type === 'copy' ? '复制' : - task.type === 'move' ? '移动' : - task.type === 'download' ? '下载' : task.type} - - - {getTaskStatusText(task.status)} - +
+
+ {getTaskStatusIcon(task.status)} + + {getTaskTypeText(task.type)} + + + {getTaskStatusText(task.status)} + +
+ {getTaskTargetText(task) && ( +
+ {getTaskTargetText(task)} +
+ )}
{(task.status === 'completed' || task.status === 'failed') && (