From 84ebc1226bfa1f43d13f3b1ce7e6190e249e2ad9 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:15:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=B8=B8=E7=94=A8?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E8=B7=AF=E5=BE=84=E8=8E=B7=E5=8F=96=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=A1=8C=E9=9D=A2=E6=96=87=E6=A1=A3=E7=AD=89?= =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.go | 18 +++++++++++ web/src/components/FileSystem.vue | 54 ++++++++++++++++++++----------- 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/app.go b/app.go index 3c38738..9476a83 100644 --- a/app.go +++ b/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中调用) diff --git a/web/src/components/FileSystem.vue b/web/src/components/FileSystem.vue index b6b7536..c3779ec 100644 --- a/web/src/components/FileSystem.vue +++ b/web/src/components/FileSystem.vue @@ -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() })