优化:动态获取系统所有盘符(C/D/E/F等)
This commit is contained in:
37
app.go
37
app.go
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========== 数据库连接管理接口 ==========
|
// ========== 数据库连接管理接口 ==========
|
||||||
|
|||||||
@@ -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 },
|
||||||
|
|||||||
Reference in New Issue
Block a user