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}; // 确保总是返回正确格式 } }