diff --git a/src/router/index.ts b/src/router/index.ts index f2b5a21c..98d8d877 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -19,7 +19,9 @@ const filterPath = [ InitHomePath, AccountCenterBindPath ] router.beforeEach((to, from, next) => { // TODO 切换路由取消请求 const token = getToken() - if (token) { + if (to.path === AccountCenterBindPath) { + next() + } else if (token) { if (to.path === LoginPath) { next({ path: '/' }) } else { diff --git a/src/utils/request.ts b/src/utils/request.ts index 0ce9335f..1bb873bc 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -13,6 +13,8 @@ interface AxiosResponseRewrite extends AxiosResponse { export const SUCCESS_CODE = 200 // 成功代码 +const filterApiUrl = ['/system/version', '/system/config/front', '/authorize/captcha/config', '/application/sso/_all', '/authorize/captcha/image'] + export const request = axios.create({ withCredentials: false, baseURL: BASE_API_PATH, @@ -165,7 +167,8 @@ request.interceptors.request.use(config => { // 如果 token 存在 // 让每个请求携带自定义 token 请根据实际情况自行修改 const token = getToken() - if (!token) { + const isFilterUrl = filterApiUrl.some(url => config.url.includes(url)) + if (!token && !isFilterUrl) { setTimeout(() => { cleanToken() router.replace({ diff --git a/src/views/account/Center/bind/index.vue b/src/views/account/Center/bind/index.vue index 5d590f9b..c8737e8d 100644 --- a/src/views/account/Center/bind/index.vue +++ b/src/views/account/Center/bind/index.vue @@ -157,7 +157,7 @@ const token = computed(() => LocalStore.get(TOKEN_KEY)); */ const user = ref(); const getDetail = () => { - if (!token) return; + if (!token.value) return; userDetail().then((res: any) => { user.value = res?.result; });