From c253e9e58fab348f0211d90ab3350cad3ccf441e Mon Sep 17 00:00:00 2001 From: "SWX\\10484" <1048449493@qq.com> Date: Tue, 16 Jun 2026 10:03:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=AF=E5=BE=84=E9=99=8D=E7=BA=A7=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/components/SystemSettingDialog.vue | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/layout/components/SystemSettingDialog.vue b/src/layout/components/SystemSettingDialog.vue index 76b2411..938ac8b 100644 --- a/src/layout/components/SystemSettingDialog.vue +++ b/src/layout/components/SystemSettingDialog.vue @@ -321,8 +321,14 @@ export default { }, // 通用:弹出目录选择器 → 创建 HiUTalkStore 子文件夹 → 存储句柄 → 填充路径到输入框 async _selectAndStorePath(handleKey, pathKey, label) { + // File System Access API 必须在安全上下文(HTTPS/localhost)下才可用 if (!window.showDirectoryPicker) { - this.$message.error('当前浏览器不支持,请使用 Chrome 或 Edge'); + const reason = window.isSecureContext + ? '当前浏览器不支持目录选择(需要 Chrome/Edge 86+)' + : '非安全连接(HTTP),目录选择仅支持 HTTPS 或 localhost'; + this.$message({ message: `${reason},可手动输入路径`, type: 'warning', duration: 5000 }); + // 降级:弹出输入框让用户手动填写路径 + await this._manualInputPath(pathKey, label); return; } try { @@ -345,6 +351,36 @@ export default { } } }, + + // 降级方案:用户手动输入路径(showDirectoryPicker 不可用时) + _manualInputPath(pathKey, label) { + return new Promise((resolve) => { + this.$prompt(`请输入${label}文件夹的完整路径(如 D:\\MyFolder\\HiUTalkStore)`, '手动输入路径', { + confirmButtonText: '确定', + cancelButtonText: '取消', + inputValue: this.basicForm[pathKey], + inputPattern: /^[A-Za-z]:\\.+$/, + inputErrorMessage: '请输入有效的完整路径(如 D:\\RUS\\HiUTalkStore)', + }).then(({ value }) => { + this.basicForm[pathKey] = value.trim(); + // 手动输入的路径无法获得目录句柄,清空 IndexedDB 中的旧句柄 + try { + this._openIDB().then(db => { + const tx = db.transaction('handles', 'readwrite'); + tx.objectStore('handles').delete(pathKey === 'videoPath' ? 'screenshot_dir' : 'cache_dir'); + db.close(); + }); + } catch (e) { /* 忽略 */ } + // 标记未授权(HTTP 下无法使用 File System Access API 写入) + if (pathKey === 'videoPath') this.videoAuthorized = false; + if (pathKey === 'cachePath') this.cacheAuthorized = false; + this.$message.success(`${label}路径已更新(由于非 HTTPS,截图/录制将使用浏览器下载)`); + resolve(); + }).catch(() => { + resolve(); // 用户取消 + }); + }); + }, // 从路径中提取盘符,例如 "D:\RUS\HiUTalkStore" → "D:" _extractDrive(path) { if (!path) return 'D:';