🐞 fix: 修复一些下载和登录问题

fix: #49
This commit is contained in:
alger
2025-01-25 23:53:20 +08:00
parent 4fa1295b84
commit c6ca63ee11
12 changed files with 149 additions and 113 deletions
+10 -20
View File
@@ -50,7 +50,7 @@ request.interceptors.request.use(
};
const token = localStorage.getItem('token');
if (token) {
config.params.cookie = config.params.cookie || token;
config.params.cookie = config.params.cookie !== undefined ? config.params.cookie : token;
}
if (isElectron) {
const proxyConfig = setData?.proxyConfig;
@@ -70,6 +70,8 @@ request.interceptors.request.use(
}
);
const NO_RETRY_URLS = ['暂时没有'];
// 响应拦截器
request.interceptors.response.use(
(response) => {
@@ -88,28 +90,16 @@ request.interceptors.response.use(
if (error.response?.status === 301) {
// 使用 store mutation 清除用户信息
store.commit('logout');
// 如果还可以重试,则重新发起请求
if (config.retryCount === undefined || config.retryCount < MAX_RETRIES) {
config.retryCount = (config.retryCount || 1) + 1;
console.log(`301 状态码,清除登录信息后重试第 ${config.retryCount}`);
notification.error({
content: '登录状态失效,请重新登录',
meta: '请重新登录',
duration: 2500,
keepAliveOnHover: true
});
// 延迟重试
await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY));
// 重新发起请求
return request(config);
}
console.log(`301 状态码,清除登录信息后重试第 ${config.retryCount}`);
config.retryCount = 3;
}
// 检查是否还可以重试
if (config.retryCount !== undefined && config.retryCount < MAX_RETRIES) {
if (
config.retryCount !== undefined &&
config.retryCount < MAX_RETRIES &&
!NO_RETRY_URLS.includes(config.url as string)
) {
config.retryCount++;
console.log(`请求重试第 ${config.retryCount}`);