Private
Public Access
1
0

优化:动态获取系统所有盘符(C/D/E/F等)

This commit is contained in:
2026-01-26 02:18:33 +08:00
parent 84ebc1226b
commit 307e0d987d
2 changed files with 57 additions and 10 deletions

37
app.go
View File

@@ -140,14 +140,39 @@ func (a *App) GetCommonPaths() (map[string]string, error) {
return nil, err return nil, err
} }
return map[string]string{ // 获取所有可用驱动器Windows
"home": homeDir, drives := getSystemDrives()
"desktop": filepath.Join(homeDir, "Desktop"),
paths := map[string]string{
"home": homeDir,
"desktop": filepath.Join(homeDir, "Desktop"),
"documents": filepath.Join(homeDir, "Documents"), "documents": filepath.Join(homeDir, "Documents"),
"downloads": filepath.Join(homeDir, "Downloads"), "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
} }
// ========== 数据库连接管理接口 ========== // ========== 数据库连接管理接口 ==========

View File

@@ -203,14 +203,36 @@ const loadCommonPaths = async () => {
const platform = window.navigator.platform const platform = window.navigator.platform
if (platform.includes('Win')) { if (platform.includes('Win')) {
commonPaths.value = [ // 基础路径
const pathList = [
{ name: '🖥️ 桌面', path: paths.desktop }, { name: '🖥️ 桌面', path: paths.desktop },
{ name: '📁 文档', path: paths.documents }, { name: '📁 文档', path: paths.documents },
{ name: '📥 下载', path: paths.downloads }, { name: '📥 下载', path: paths.downloads },
{ name: '💾 用户目录', path: paths.home }, { name: '💾 用户目录', path: paths.home }
{ name: '💿 C盘', path: paths.root_c },
{ name: '💿 D盘', path: paths.root_d }
] ]
// 动态添加所有盘符(按字母顺序)
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 { } else {
commonPaths.value = [ commonPaths.value = [
{ name: '🖥️ 桌面', path: paths.desktop }, { name: '🖥️ 桌面', path: paths.desktop },