From 382aee8e61700f25fe9affbd06f0e25eb1544a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=96=BB=E5=8B=87=E7=A5=A5?= <237899745@qq.com> Date: Mon, 24 Nov 2025 20:51:14 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20=E4=BC=98=E5=8C=96=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8B=E8=BD=BD=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 前端优化: - 统一文件下载逻辑,HTTP 和 SFTP 下载使用相同方式 - 移除 window.open 弹出新窗口的方式 - 统一使用隐藏的 标签触发下载 - 简化代码逻辑,提高可维护性 用户体验改进: - 避免浏览器弹出窗口拦截 - 下载过程更加流畅 - 减少额外的页面跳转 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- frontend/app.js | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/frontend/app.js b/frontend/app.js index ab377a9..27da683 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -933,25 +933,17 @@ handleDragLeave(e) { downloadFile(file) { console.log("[DEBUG] 下载文件:", file); - if (file.httpDownloadUrl) { - // 如果配置了HTTP下载URL,使用HTTP直接下载 - console.log("[DEBUG] 使用HTTP下载:", file.httpDownloadUrl); - window.open(file.httpDownloadUrl, "_blank"); - } else { - // 如果没有配置HTTP URL,通过后端SFTP下载 - console.log("[DEBUG] 使用SFTP下载"); - const filePath = this.currentPath === '/' - ? `/${file.name}` - : `${this.currentPath}/${file.name}`; + const url = file.httpDownloadUrl + ? file.httpDownloadUrl + : `${this.apiBase}/api/files/download?path=${encodeURIComponent(this.currentPath === '/' ? `/${file.name}` : `${this.currentPath}/${file.name}`)}`; - // 使用标签下载,依赖同域 Cookie/凭证 - const link = document.createElement('a'); - link.href = `${this.apiBase}/api/files/download?path=${encodeURIComponent(filePath)}`; - link.setAttribute('download', file.name); - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); - } + // 统一通过隐藏链接触发下载,避免弹出新窗口 + const link = document.createElement('a'); + link.href = url; + link.setAttribute('download', file.name); + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); }, // ===== 文件操作 =====