From 307e0d987dc1c44fcaedd097583932d1680de910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=9D=E5=B0=98?= <237809796@qq.com> Date: Mon, 26 Jan 2026 02:18:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=B3=BB=E7=BB=9F=E6=89=80=E6=9C=89=E7=9B=98?= =?UTF-8?q?=E7=AC=A6=EF=BC=88C/D/E/F=E7=AD=89=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.go | 37 ++++++++++++++++++++++++++----- web/src/components/FileSystem.vue | 30 +++++++++++++++++++++---- 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/app.go b/app.go index 9476a83..d13f1e5 100644 --- a/app.go +++ b/app.go @@ -140,14 +140,39 @@ func (a *App) GetCommonPaths() (map[string]string, error) { return nil, err } - return map[string]string{ - "home": homeDir, - "desktop": filepath.Join(homeDir, "Desktop"), + // 获取所有可用驱动器(Windows) + drives := getSystemDrives() + + paths := map[string]string{ + "home": homeDir, + "desktop": filepath.Join(homeDir, "Desktop"), "documents": filepath.Join(homeDir, "Documents"), "downloads": filepath.Join(homeDir, "Downloads"), - "root_c": "C:\\", - "root_d": "D:\\", - }, nil + } + + // 动态添加所有盘符 + for i, drive := range drives { + key := fmt.Sprintf("root_%s", drive[:1]) + paths[key] = drive + _ = i // 避免未使用变量警告 + } + + return paths, nil +} + +// getSystemDrives 获取系统所有可用驱动器 +func getSystemDrives() []string { + var drives []string + + // Windows: 检查 A-Z 所有盘符 + for _, drive := range "ABCDEFGHIJKLMNOPQRSTUVWXYZ" { + path := string(drive) + ":\\" + if _, err := os.Stat(path); err == nil { + drives = append(drives, path) + } + } + + return drives } // ========== 数据库连接管理接口 ========== diff --git a/web/src/components/FileSystem.vue b/web/src/components/FileSystem.vue index c3779ec..8e2ff0c 100644 --- a/web/src/components/FileSystem.vue +++ b/web/src/components/FileSystem.vue @@ -203,14 +203,36 @@ const loadCommonPaths = async () => { const platform = window.navigator.platform if (platform.includes('Win')) { - commonPaths.value = [ + // 基础路径 + const pathList = [ { name: '🖥️ 桌面', path: paths.desktop }, { name: '📁 文档', path: paths.documents }, { name: '📥 下载', path: paths.downloads }, - { name: '💾 用户目录', path: paths.home }, - { name: '💿 C盘', path: paths.root_c }, - { name: '💿 D盘', path: paths.root_d } + { name: '💾 用户目录', path: paths.home } ] + + // 动态添加所有盘符(按字母顺序) + const drives = [] + for (const key in paths) { + if (key.startsWith('root_')) { + const driveLetter = key.substring(5) + drives.push({ + letter: driveLetter, + path: paths[key] + }) + } + } + drives.sort((a, b) => a.letter.localeCompare(b.letter)) + + // 添加盘符到路径列表 + drives.forEach(drive => { + pathList.push({ + name: `💿 ${drive.letter}盘`, + path: drive.path + }) + }) + + commonPaths.value = pathList } else { commonPaths.value = [ { name: '🖥️ 桌面', path: paths.desktop },