为文件夹/分享详情加载引入无感自动重试,优化失败体验

- 新增:在 `getSavepathDetail` 失败时自动无感重试一次
  - 仅在 `#fileSelectModal` 仍显示时触发重试,避免误重试
  - 为请求参数追加 `_ts` 时间戳,绕过浏览器/代理缓存导致的伪重试
- 新增:在 `getShareDetail` 失败时自动无感重试一次
  - 重试前强制清空 `this.fileSelect.stoken`,让后端重新获取有效 `stoken`
  - 仅在 `#fileSelectModal` 仍显示时触发重试
- 超过最大重试次数后,立即提示“获取文件夹列表失败,请关闭窗口再试一次”,不再继续等待

原因:
- 原有“等待1秒再调一次”的重试在令牌失效或缓存命中时无效,用户需手动关窗再点
- 本次改动通过刷新 `stoken` 与规避缓存,实现与“手动关窗再点”接近的效果,且对用户无感
This commit is contained in:
x1ao4 2025-08-28 22:05:29 +08:00
parent 5216fa981d
commit 484e68a82d

View File

@ -4628,15 +4628,23 @@
}
this.modalLoading = false;
}).catch(error => {
// 如果还有重试次数,则进行重试
// 增强版无感重试:添加缓存破坏参数,并仅在模态框仍打开时重试
if (retryCount < maxRetries) {
console.log(`获取文件夹列表失败,正在进行第 ${retryCount + 1} 次重试...`);
// 短暂延迟后重试
setTimeout(() => {
// 确保模态框仍处于打开状态否则中止并结束loading
const fileSelectModal = document.getElementById('fileSelectModal');
if (!(fileSelectModal && fileSelectModal.classList.contains('show'))) {
this.modalLoading = false;
return;
}
// 为请求参数添加时间戳,避免潜在的缓存干扰
if (typeof params === 'object' && params !== null) {
params._ts = Date.now();
}
this.getSavepathDetail(params, retryCount + 1, maxRetries);
}, 1000); // 1秒后重试
}, 600);
} else {
// 超过最大重试次数,显示错误信息
this.fileSelect.error = "获取文件夹列表失败,请关闭窗口再试一次";
this.modalLoading = false;
}
@ -4768,15 +4776,20 @@
}
this.modalLoading = false;
}).catch(error => {
// 如果还有重试次数,则进行重试
// 增强版无感重试:清空 stoken 强制刷新令牌,并仅在模态框仍打开时重试
if (retryCount < maxRetries) {
console.log(`获取文件夹列表失败,正在进行第 ${retryCount + 1} 次重试...`);
// 短暂延迟后重试
setTimeout(() => {
const fileSelectModal = document.getElementById('fileSelectModal');
if (!(fileSelectModal && fileSelectModal.classList.contains('show'))) {
this.modalLoading = false;
return;
}
// 清空stoken促使后端重新获取有效的stoken
this.fileSelect.stoken = "";
this.getShareDetail(retryCount + 1, maxRetries);
}, 1000); // 1秒后重试
}, 600);
} else {
// 超过最大重试次数,显示错误信息
this.fileSelect.error = "获取文件夹列表失败,请关闭窗口再试一次";
this.modalLoading = false;
}