功能变化: 刷新token后,重新请求
parent
0258e7c3ca
commit
e0e51594f4
|
@ -307,7 +307,7 @@ from datetime import timedelta
|
||||||
|
|
||||||
SIMPLE_JWT = {
|
SIMPLE_JWT = {
|
||||||
# token有效时长
|
# token有效时长
|
||||||
"ACCESS_TOKEN_LIFETIME": timedelta(seconds=60),
|
"ACCESS_TOKEN_LIFETIME": timedelta(minutes=1),
|
||||||
# token刷新后的有效时间
|
# token刷新后的有效时间
|
||||||
"REFRESH_TOKEN_LIFETIME": timedelta(days=1),
|
"REFRESH_TOKEN_LIFETIME": timedelta(days=1),
|
||||||
# 设置前缀
|
# 设置前缀
|
||||||
|
|
|
@ -9,8 +9,6 @@ import qs from 'qs'
|
||||||
/**
|
/**
|
||||||
* @description 创建请求实例
|
* @description 创建请求实例
|
||||||
*/
|
*/
|
||||||
axios.defaults.retry = 1
|
|
||||||
axios.defaults.retryDelay = 1000
|
|
||||||
|
|
||||||
export function getErrorMessage (msg) {
|
export function getErrorMessage (msg) {
|
||||||
if (typeof msg === 'string') {
|
if (typeof msg === 'string') {
|
||||||
|
@ -59,7 +57,7 @@ function createService () {
|
||||||
service.interceptors.response.use(
|
service.interceptors.response.use(
|
||||||
response => {
|
response => {
|
||||||
// dataAxios 是 axios 返回数据中的 data
|
// dataAxios 是 axios 返回数据中的 data
|
||||||
let dataAxios = response.data
|
let dataAxios = response.data || null
|
||||||
if (response.headers['content-disposition']) {
|
if (response.headers['content-disposition']) {
|
||||||
dataAxios = response
|
dataAxios = response
|
||||||
}
|
}
|
||||||
|
@ -80,7 +78,22 @@ function createService () {
|
||||||
case 401:
|
case 401:
|
||||||
refreshTken().then(res => {
|
refreshTken().then(res => {
|
||||||
util.cookies.set('token', res.data.access)
|
util.cookies.set('token', res.data.access)
|
||||||
// router.push({path:'/index'})
|
// 设置请求超时次数
|
||||||
|
let config = response.config
|
||||||
|
config.__retryCount = config.__retryCount || 0
|
||||||
|
if (config.__retryCount >= config.retry) {
|
||||||
|
return Promise.reject()
|
||||||
|
}
|
||||||
|
config.__retryCount += 1
|
||||||
|
const backoff = new Promise((resolve) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
resolve()
|
||||||
|
}, config.retryDelay || 1)
|
||||||
|
})
|
||||||
|
return backoff.then(() => {
|
||||||
|
config.headers['Authorization'] = 'JWT ' + res.data.access
|
||||||
|
return service(config)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
case 404:
|
case 404:
|
||||||
|
@ -176,7 +189,9 @@ function createRequestFunction (service) {
|
||||||
timeout: 60000,
|
timeout: 60000,
|
||||||
baseURL: util.baseURL(),
|
baseURL: util.baseURL(),
|
||||||
data: {},
|
data: {},
|
||||||
params: params
|
params: params,
|
||||||
|
retry: 3, //重新请求次数
|
||||||
|
retryDelay: 1500 //重新请求间隔
|
||||||
}
|
}
|
||||||
return service(Object.assign(configDefault, config))
|
return service(Object.assign(configDefault, config))
|
||||||
}
|
}
|
||||||
|
@ -212,7 +227,12 @@ const refreshTken = function () {
|
||||||
* @param method
|
* @param method
|
||||||
* @param filename
|
* @param filename
|
||||||
*/
|
*/
|
||||||
export const downloadFile = function ({ url, params, method, filename = '文件导出' }) {
|
export const downloadFile = function ({
|
||||||
|
url,
|
||||||
|
params,
|
||||||
|
method,
|
||||||
|
filename = '文件导出'
|
||||||
|
}) {
|
||||||
request({
|
request({
|
||||||
url: url,
|
url: url,
|
||||||
method: method,
|
method: method,
|
||||||
|
|
Loading…
Reference in New Issue