From 42c6f1e2d04c88c5b51eb22633c0e6a8bb712d6e Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Wed, 17 Sep 2025 10:16:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=99=A8=E4=BE=A7=E8=BE=B9=E6=A0=8F=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复目录树API数据格式不匹配:listSSHFiles返回{files, path}对象而非数组 - 修复侧边栏滚动问题:添加thin-scrollbar类保持样式一致性 - 修复Recent和Pin文件点击行为:区分文件和文件夹处理逻辑 - 增强侧边栏高度约束:确保滚动容器正确工作 - 优化TypeScript类型安全:更新listSSHFiles返回类型定义 主要改进: 1. 侧边栏目录树现在正确显示所有文件夹而不是只有根目录 2. Recent和Pinned文件点击时正确打开文件而不是当作文件夹处理 3. 侧边栏支持滚动查看所有内容,滚动条样式与主容器一致 4. API错误处理更加健壮,避免undefined导致的运行时错误 --- .../Apps/File Manager/FileManagerModern.tsx | 17 +++++++++- .../Apps/File Manager/FileManagerSidebar.tsx | 32 +++++++++++++++---- src/ui/main-axios.ts | 5 +-- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/ui/Desktop/Apps/File Manager/FileManagerModern.tsx b/src/ui/Desktop/Apps/File Manager/FileManagerModern.tsx index 3c0f4f5d..48076394 100644 --- a/src/ui/Desktop/Apps/File Manager/FileManagerModern.tsx +++ b/src/ui/Desktop/Apps/File Manager/FileManagerModern.tsx @@ -45,6 +45,7 @@ import { addFolderShortcut, getPinnedFiles } from "@/ui/main-axios.ts"; +import type { SidebarItem } from "./FileManagerSidebar"; interface FileManagerModernProps { @@ -1309,6 +1310,19 @@ function FileManagerContent({ initialHost, onClose }: FileManagerModernProps) { } } + // 处理侧边栏文件打开 + async function handleSidebarFileOpen(sidebarItem: SidebarItem) { + // 将SidebarItem转换为FileItem格式 + const file: FileItem = { + name: sidebarItem.name, + path: sidebarItem.path, + type: 'file' // recent和pinned都是文件类型 + }; + + // 调用常规的文件打开处理 + await handleFileOpen(file); + } + // 处理文件打开 async function handleFileOpen(file: FileItem) { if (file.type === 'directory') { @@ -1481,12 +1495,13 @@ function FileManagerContent({ initialHost, onClose }: FileManagerModernProps) { {/* 主内容区域 */}
{/* 左侧边栏 */} -
+
diff --git a/src/ui/Desktop/Apps/File Manager/FileManagerSidebar.tsx b/src/ui/Desktop/Apps/File Manager/FileManagerSidebar.tsx index fe3a0270..9b134d8a 100644 --- a/src/ui/Desktop/Apps/File Manager/FileManagerSidebar.tsx +++ b/src/ui/Desktop/Apps/File Manager/FileManagerSidebar.tsx @@ -19,7 +19,7 @@ import { listSSHFiles } from "@/ui/main-axios.ts"; -interface SidebarItem { +export interface SidebarItem { id: string; name: string; path: string; @@ -34,6 +34,7 @@ interface FileManagerSidebarProps { currentPath: string; onPathChange: (path: string) => void; onLoadDirectory?: (path: string) => void; + onFileOpen?: (file: SidebarItem) => void; // 新增:处理文件打开 sshSessionId?: string; refreshTrigger?: number; // 用于触发数据刷新 } @@ -43,6 +44,7 @@ export function FileManagerSidebar({ currentPath, onPathChange, onLoadDirectory, + onFileOpen, sshSessionId, refreshTrigger }: FileManagerSidebarProps) { @@ -51,7 +53,7 @@ export function FileManagerSidebar({ const [pinnedItems, setPinnedItems] = useState([]); const [shortcuts, setShortcuts] = useState([]); const [directoryTree, setDirectoryTree] = useState([]); - const [expandedFolders, setExpandedFolders] = useState>(new Set(['/'])); + const [expandedFolders, setExpandedFolders] = useState>(new Set(['root'])); // 加载快捷功能数据 useEffect(() => { @@ -113,7 +115,10 @@ export function FileManagerSidebar({ try { // 加载根目录 - const rootFiles = await listSSHFiles(sshSessionId, '/'); + const response = await listSSHFiles(sshSessionId, '/'); + + // listSSHFiles 现在总是返回 {files: Array, path: string} 格式 + const rootFiles = response.files || []; const rootFolders = rootFiles.filter((item: any) => item.type === 'directory'); const rootTreeItems = rootFolders.map((folder: any) => ({ @@ -154,8 +159,20 @@ export function FileManagerSidebar({ const handleItemClick = (item: SidebarItem) => { if (item.type === 'folder') { toggleFolder(item.id, item.path); + onPathChange(item.path); + } else if (item.type === 'recent' || item.type === 'pinned') { + // 对于文件类型,调用文件打开回调 + if (onFileOpen) { + onFileOpen(item); + } else { + // 如果没有文件打开回调,切换到文件所在目录 + const directory = item.path.substring(0, item.path.lastIndexOf('/')) || '/'; + onPathChange(directory); + } + } else if (item.type === 'shortcut') { + // 文件夹快捷方式直接切换到目录 + onPathChange(item.path); } - onPathChange(item.path); }; const toggleFolder = async (folderId: string, folderPath?: string) => { @@ -169,7 +186,10 @@ export function FileManagerSidebar({ // 按需加载子目录 if (sshSessionId && folderPath && folderPath !== '/') { try { - const subFiles = await listSSHFiles(sshSessionId, folderPath); + const subResponse = await listSSHFiles(sshSessionId, folderPath); + + // listSSHFiles 现在总是返回 {files: Array, path: string} 格式 + const subFiles = subResponse.files || []; const subFolders = subFiles.filter((item: any) => item.type === 'directory'); const subTreeItems = subFolders.map((folder: any) => ({ @@ -271,7 +291,7 @@ export function FileManagerSidebar({ return (
-
+
{/* 快捷功能区域 */} {renderSection(t("fileManager.recent"), , recentItems)} {renderSection(t("fileManager.pinned"), , pinnedItems)} diff --git a/src/ui/main-axios.ts b/src/ui/main-axios.ts index 91b71422..475f55de 100644 --- a/src/ui/main-axios.ts +++ b/src/ui/main-axios.ts @@ -958,14 +958,15 @@ export async function getSSHStatus( export async function listSSHFiles( sessionId: string, path: string, -): Promise { +): Promise<{files: any[], path: string}> { try { const response = await fileManagerApi.get("/ssh/listFiles", { params: { sessionId, path }, }); - return response.data || []; + return response.data || {files: [], path}; } catch (error) { handleApiError(error, "list SSH files"); + return {files: [], path}; // 确保总是返回正确格式 } }