💄 优化文件下载体验
前端优化: - 统一文件下载逻辑,HTTP 和 SFTP 下载使用相同方式 - 移除 window.open 弹出新窗口的方式 - 统一使用隐藏的 <a> 标签触发下载 - 简化代码逻辑,提高可维护性 用户体验改进: - 避免浏览器弹出窗口拦截 - 下载过程更加流畅 - 减少额外的页面跳转 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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}`)}`;
|
||||
|
||||
// 使用<a>标签下载,依赖同域 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);
|
||||
},
|
||||
|
||||
// ===== 文件操作 =====
|
||||
|
||||
Reference in New Issue
Block a user