修复:常用系统路径获取,支持桌面文档等快捷访问
This commit is contained in:
18
app.go
18
app.go
@@ -9,6 +9,7 @@ import (
|
||||
"go-desk/internal/storage"
|
||||
"go-desk/internal/system"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
@@ -132,6 +133,23 @@ func (a *App) GetEnvVars() (map[string]string, error) {
|
||||
return envVars, nil
|
||||
}
|
||||
|
||||
// GetCommonPaths 获取常用系统路径
|
||||
func (a *App) GetCommonPaths() (map[string]string, error) {
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return 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
|
||||
}
|
||||
|
||||
// ========== 数据库连接管理接口 ==========
|
||||
|
||||
// initAPIs 初始化所有API(在startup中调用)
|
||||
|
||||
@@ -192,26 +192,43 @@ const STORAGE_KEYS = {
|
||||
}
|
||||
|
||||
// 常用路径快捷方式
|
||||
const commonPaths = computed(() => {
|
||||
const platform = window.navigator.platform
|
||||
if (platform.includes('Win')) {
|
||||
return [
|
||||
{ name: '桌面', path: `${process.env.USERPROFILE || ''}\\Desktop` },
|
||||
{ name: '文档', path: `${process.env.USERPROFILE || ''}\\Documents` },
|
||||
{ name: '下载', path: `${process.env.USERPROFILE || ''}\\Downloads` },
|
||||
{ name: 'C盘根目录', path: 'C:\\' },
|
||||
{ name: 'D盘根目录', path: 'D:\\' }
|
||||
]
|
||||
} else {
|
||||
return [
|
||||
{ name: '用户主目录', path: '~' },
|
||||
{ name: '桌面', path: '~/Desktop' },
|
||||
{ name: '文档', path: '~/Documents' },
|
||||
{ name: '下载', path: '~/Downloads' },
|
||||
{ name: '根目录', path: '/' }
|
||||
const commonPaths = ref([])
|
||||
const systemPaths = ref({})
|
||||
|
||||
// 加载常用系统路径
|
||||
const loadCommonPaths = async () => {
|
||||
try {
|
||||
const paths = await window.go.main.App.GetCommonPaths()
|
||||
systemPaths.value = paths
|
||||
|
||||
const platform = window.navigator.platform
|
||||
if (platform.includes('Win')) {
|
||||
commonPaths.value = [
|
||||
{ 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 }
|
||||
]
|
||||
} else {
|
||||
commonPaths.value = [
|
||||
{ name: '🖥️ 桌面', path: paths.desktop },
|
||||
{ name: '📁 文档', path: paths.documents },
|
||||
{ name: '📥 下载', path: paths.downloads },
|
||||
{ name: '🏠 主目录', path: paths.home },
|
||||
{ name: '📂 根目录', path: '/' }
|
||||
]
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载常用路径失败:', error)
|
||||
// 降级方案:使用默认路径
|
||||
commonPaths.value = [
|
||||
{ name: '💿 C盘', path: 'C:\\' },
|
||||
{ name: '💿 D盘', path: 'D:\\' }
|
||||
]
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 状态
|
||||
const filePath = ref('')
|
||||
@@ -494,6 +511,7 @@ watch(fileList, (newList) => {
|
||||
|
||||
onMounted(() => {
|
||||
loadFromStorage()
|
||||
loadCommonPaths()
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user