You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mudu-vx/src/util/refresh.js

26 lines
702 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import * as api from '@/api/api.js'
import { encryptionLogin } from '../util/Login.js'
let promise
export async function refreshToken() {
if (promise) {
return promise
}
promise = new Promise(async resolve => {
const loginFrom = encryptionLogin()
console.log('重新换token', loginFrom)
let res = await api.login(loginFrom, { __isRefreshToken: true })
localStorage.setItem('mudu_token', res.access_token) //存token
resolve(res.code === 200)
})
promise.finally(() => {
promise = null
})
return promise
}
export function isRefreshRequest(config) {
// console.log(config.__isRefreshToken)
return !!config.__isRefreshToken //两个取反变成boolean
}