【功能修复】全局:升级 axios 版本,修复 token 过期刷新后,文件重传失败的问题
parent
13dde308f7
commit
a76b0ecbc3
|
@ -1,7 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "yudao-ui-admin-vben",
|
"name": "yudao-ui-admin-vben",
|
||||||
"version": "2.1.0-snapshot",
|
"version": "2.1.0-snapshot",
|
||||||
"packageManager": "pnpm@8.9.0",
|
|
||||||
"author": {
|
"author": {
|
||||||
"name": "xingyuv",
|
"name": "xingyuv",
|
||||||
"email": "xingyu4j@vip.qq.com",
|
"email": "xingyu4j@vip.qq.com",
|
||||||
|
@ -53,7 +52,7 @@
|
||||||
"@vueuse/core": "^10.6.1",
|
"@vueuse/core": "^10.6.1",
|
||||||
"@zxcvbn-ts/core": "^3.0.4",
|
"@zxcvbn-ts/core": "^3.0.4",
|
||||||
"ant-design-vue": "^4.0.7",
|
"ant-design-vue": "^4.0.7",
|
||||||
"axios": "^1.6.1",
|
"axios": "^1.6.8",
|
||||||
"benz-amr-recorder": "^1.1.5",
|
"benz-amr-recorder": "^1.1.5",
|
||||||
"codemirror": "5.65.15",
|
"codemirror": "5.65.15",
|
||||||
"cron-parser": "^4.9.0",
|
"cron-parser": "^4.9.0",
|
||||||
|
|
11734
pnpm-lock.yaml
11734
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -15,7 +15,7 @@ import type { RequestOptions, Result, UploadFileParams } from '@/types/axios'
|
||||||
import { ContentTypeEnum, RequestEnum } from '@/enums/httpEnum'
|
import { ContentTypeEnum, RequestEnum } from '@/enums/httpEnum'
|
||||||
import { downloadByData } from '@/utils/file/download'
|
import { downloadByData } from '@/utils/file/download'
|
||||||
import { useGlobSetting } from '@/hooks/setting'
|
import { useGlobSetting } from '@/hooks/setting'
|
||||||
import { getRefreshToken, getTenantId, setAccessToken } from '@/utils/auth'
|
import {getAccessToken, getRefreshToken, getTenantId, setAccessToken} from '@/utils/auth'
|
||||||
|
|
||||||
export * from './axiosTransform'
|
export * from './axiosTransform'
|
||||||
|
|
||||||
|
@ -134,15 +134,14 @@ export class VAxios {
|
||||||
try {
|
try {
|
||||||
const refreshTokenRes = await this.refreshToken()
|
const refreshTokenRes = await this.refreshToken()
|
||||||
// 2.1 刷新成功,则回放队列的请求 + 当前请求
|
// 2.1 刷新成功,则回放队列的请求 + 当前请求
|
||||||
const refreshToken = getRefreshToken()
|
|
||||||
setAccessToken(refreshTokenRes.data.data.accessToken)
|
setAccessToken(refreshTokenRes.data.data.accessToken)
|
||||||
;(config as Recordable).headers.Authorization = `Bearer ${refreshToken}`
|
;(config as Recordable).headers.Authorization = `Bearer ${getAccessToken()}`
|
||||||
requestList.forEach((cb: any) => {
|
requestList.forEach((cb: any) => {
|
||||||
cb()
|
cb()
|
||||||
})
|
})
|
||||||
requestList = []
|
requestList = []
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
resolve(this.axiosInstance(config))
|
resolve(this.axiosInstance.request(config))
|
||||||
})
|
})
|
||||||
// res = await Promise.all([this.axiosInstance(config)])[0]
|
// res = await Promise.all([this.axiosInstance(config)])[0]
|
||||||
}
|
}
|
||||||
|
@ -160,9 +159,8 @@ export class VAxios {
|
||||||
else {
|
else {
|
||||||
// 添加到队列,等待刷新获取到新的令牌
|
// 添加到队列,等待刷新获取到新的令牌
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const refreshToken = getRefreshToken()
|
|
||||||
requestList.push(() => {
|
requestList.push(() => {
|
||||||
;(config as Recordable).headers.Authorization = `Bearer ${refreshToken}` // 让每个请求携带自定义token 请根据实际情况自行修改
|
;(config as Recordable).headers.Authorization = `Bearer ${getAccessToken()}` // 让每个请求携带自定义token 请根据实际情况自行修改
|
||||||
resolve(this.axiosInstance(config))
|
resolve(this.axiosInstance(config))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -215,7 +213,7 @@ export class VAxios {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: formData,
|
data: formData,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-type': ContentTypeEnum.FORM_DATA,
|
'Content-Type': ContentTypeEnum.FORM_DATA,
|
||||||
'ignoreCancelToken': true,
|
'ignoreCancelToken': true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue