fix: bug#10667
This commit is contained in:
parent
58e01fe28e
commit
12e3bf620b
|
@ -3,7 +3,7 @@ import {BASE_API_PATH, TOKEN_KEY} from '@/utils/variable'
|
||||||
import { notification as Notification } from 'ant-design-vue'
|
import { notification as Notification } from 'ant-design-vue'
|
||||||
import router from '@/router'
|
import router from '@/router'
|
||||||
import { LoginPath } from '@/router/menu'
|
import { LoginPath } from '@/router/menu'
|
||||||
import {LocalStore} from "@/utils/comm";
|
import { cleanToken, getToken, LocalStore } from '@/utils/comm'
|
||||||
import type { AxiosInstance, AxiosResponse } from 'axios'
|
import type { AxiosInstance, AxiosResponse } from 'axios'
|
||||||
|
|
||||||
interface AxiosResponseRewrite<T = any[]> extends AxiosResponse<T, any> {
|
interface AxiosResponseRewrite<T = any[]> extends AxiosResponse<T, any> {
|
||||||
|
@ -47,7 +47,7 @@ export const post = function<T>(url: string, data = {}, params = {}, ext={}) {
|
||||||
* @param {Object} [data]
|
* @param {Object} [data]
|
||||||
* @returns {AxiosInstance}
|
* @returns {AxiosInstance}
|
||||||
*/
|
*/
|
||||||
export const put = function<T>(url: string, data = {},) {
|
export const put = function <T>(url: string, data = {}) {
|
||||||
return request<any, AxiosResponseRewrite<T>>({
|
return request<any, AxiosResponseRewrite<T>>({
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
url,
|
url,
|
||||||
|
@ -145,9 +145,11 @@ const errorHandler = (error: any) => {
|
||||||
showNotification('Request Error', (data.message + '').substr(0, 90), '400')
|
showNotification('Request Error', (data.message + '').substr(0, 90), '400')
|
||||||
} else if (status === 401) {
|
} else if (status === 401) {
|
||||||
showNotification('Unauthorized', '用户未登录', '401')
|
showNotification('Unauthorized', '用户未登录', '401')
|
||||||
console.log('showNotification')
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
location.href = `/#${LoginPath}`
|
cleanToken()
|
||||||
|
router.replace({
|
||||||
|
path: LoginPath
|
||||||
|
})
|
||||||
}, 0)
|
}, 0)
|
||||||
}
|
}
|
||||||
} else if (error.response === undefined) {
|
} else if (error.response === undefined) {
|
||||||
|
@ -160,16 +162,13 @@ const errorHandler = (error: any) => {
|
||||||
request.interceptors.request.use(config => {
|
request.interceptors.request.use(config => {
|
||||||
// 如果 token 存在
|
// 如果 token 存在
|
||||||
// 让每个请求携带自定义 token 请根据实际情况自行修改
|
// 让每个请求携带自定义 token 请根据实际情况自行修改
|
||||||
const token = LocalStore.get(TOKEN_KEY)
|
const token = getToken()
|
||||||
// const token = store.$state.tokenAlias
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
// setTimeout(() => {
|
|
||||||
// router.replace({
|
|
||||||
// path: LoginPath
|
|
||||||
// })
|
|
||||||
// }, 0)
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
location.href = `/#${LoginPath}`
|
cleanToken()
|
||||||
|
router.replace({
|
||||||
|
path: LoginPath
|
||||||
|
})
|
||||||
}, 0)
|
}, 0)
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue