This commit is contained in:
刘玉霞 2024-06-21 14:02:09 +08:00
parent 8d9f09dd46
commit 0c90654ee5
3 changed files with 35 additions and 34 deletions

View File

@ -26,10 +26,10 @@ export const changeTerminalConfigUrl = '/admin/ajax/changeTerminalConfig'
export const clearCacheUrl = '/admin/ajax/clearCache'
// 公共
export const captchaUrl = '/api/captcha/captchaImage'
export const clickCaptchaUrl = '/api/captcha/captchaImage'
export const captchaUrl = '/api/auth/captchaImage'
export const clickCaptchaUrl = '/api/auth/captchaImage'
export const checkClickCaptchaUrl = '/api/common/checkClickCaptcha'
export const refreshTokenUrl = '/api/common/refreshToken'
export const refreshTokenUrl = '/api/auth/refreshToken'
// api模块(前台)
export const apiUploadUrl = '/api/ajax/upload'

View File

@ -122,35 +122,36 @@ function createAxios<Data = any, T = ApiPromise<Data>>(axiosConfig: AxiosRequest
if (response.config.responseType == 'json') {
if (response.data && response.data.code == 401) {
// if (response.data.code == 409) {
// if (!window.tokenRefreshing) {
// window.tokenRefreshing = true
// return refreshToken()
// .then((res) => {
// adminInfo.setToken(res.data.token, 'auth')
// response.headers.token = `${res.data.token}`
// window.requests.forEach((cb) => cb(res.data.token, 'admin-refresh'))
// window.requests = []
// return Axios(response.config)
// })
// .catch((err) => {
// adminInfo.removeToken()
// router.push({ name: 'adminLogin' })
// return Promise.reject(err)
// })
// .finally(() => {
// window.tokenRefreshing = false
// })
// } else {
// return new Promise((resolve) => {
// // 用函数形式将 resolve 存入,等待刷新后再执行
// window.requests.push((token: string, type: string) => {
// response.headers.token = `${token}`
// resolve(Axios(response.config))
// })
// })
// }
// }
if (response.data.code == 409) {
if (!window.tokenRefreshing) {
window.tokenRefreshing = true
return refreshToken()
.then((res) => {
adminInfo.setToken(res.data.token, 'auth')
response.headers.token = `${res.data.accessToken}`
window.requests.forEach((cb) => cb(res.data.accessToken, 'admin-refresh'))
window.requests = []
return Axios(response.config)
})
.catch((err) => {
adminInfo.removeToken()
router.push({ name: 'adminLogin' })
return Promise.reject(err)
})
.finally(() => {
window.tokenRefreshing = false
})
} else {
return new Promise((resolve) => {
// 用函数形式将 resolve 存入,等待刷新后再执行
window.requests.push((token: string, type: string) => {
const v = response.headers.v
response.headers.token = encrypt_aes(token, v)
resolve(Axios(response.config))
})
})
}
}
// if (options.showCodeMessage) {
// ElNotification({
// type: 'error',

View File

@ -117,7 +117,7 @@ const form = reactive({
username: '',
password: '',
keep: false,
uuid: '',
key: '',
code: '',
})
@ -174,7 +174,7 @@ const onSubmitPre = () => {
const load = () => {
getCaptchaData().then((res) => {
form.uuid = res.data.key
form.key = res.data.key
state.captcha = 'data:image\/png;base64,' + res.data.img
})
}