【功能修复】全局:升级 axios 版本,修复 token 过期刷新后,文件重传失败的问题

pull/43/head
YunaiV 2024-07-27 17:09:03 +08:00
parent 13dde308f7
commit a76b0ecbc3
3 changed files with 6759 additions and 5476 deletions

View File

@ -1,7 +1,6 @@
{
"name": "yudao-ui-admin-vben",
"version": "2.1.0-snapshot",
"packageManager": "pnpm@8.9.0",
"author": {
"name": "xingyuv",
"email": "xingyu4j@vip.qq.com",
@ -53,7 +52,7 @@
"@vueuse/core": "^10.6.1",
"@zxcvbn-ts/core": "^3.0.4",
"ant-design-vue": "^4.0.7",
"axios": "^1.6.1",
"axios": "^1.6.8",
"benz-amr-recorder": "^1.1.5",
"codemirror": "5.65.15",
"cron-parser": "^4.9.0",

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@ import type { RequestOptions, Result, UploadFileParams } from '@/types/axios'
import { ContentTypeEnum, RequestEnum } from '@/enums/httpEnum'
import { downloadByData } from '@/utils/file/download'
import { useGlobSetting } from '@/hooks/setting'
import { getRefreshToken, getTenantId, setAccessToken } from '@/utils/auth'
import {getAccessToken, getRefreshToken, getTenantId, setAccessToken} from '@/utils/auth'
export * from './axiosTransform'
@ -134,15 +134,14 @@ export class VAxios {
try {
const refreshTokenRes = await this.refreshToken()
// 2.1 刷新成功,则回放队列的请求 + 当前请求
const refreshToken = getRefreshToken()
setAccessToken(refreshTokenRes.data.data.accessToken)
;(config as Recordable).headers.Authorization = `Bearer ${refreshToken}`
;(config as Recordable).headers.Authorization = `Bearer ${getAccessToken()}`
requestList.forEach((cb: any) => {
cb()
})
requestList = []
return new Promise((resolve) => {
resolve(this.axiosInstance(config))
resolve(this.axiosInstance.request(config))
})
// res = await Promise.all([this.axiosInstance(config)])[0]
}
@ -160,9 +159,8 @@ export class VAxios {
else {
// 添加到队列,等待刷新获取到新的令牌
return new Promise((resolve) => {
const refreshToken = getRefreshToken()
requestList.push(() => {
;(config as Recordable).headers.Authorization = `Bearer ${refreshToken}` // 让每个请求携带自定义token 请根据实际情况自行修改
;(config as Recordable).headers.Authorization = `Bearer ${getAccessToken()}` // 让每个请求携带自定义token 请根据实际情况自行修改
resolve(this.axiosInstance(config))
})
})
@ -215,7 +213,7 @@ export class VAxios {
method: 'POST',
data: formData,
headers: {
'Content-type': ContentTypeEnum.FORM_DATA,
'Content-Type': ContentTypeEnum.FORM_DATA,
'ignoreCancelToken': true,
},
})