吉安感知网项目-前端
罗广辉
3 days ago 1d552a3bad95caae4af15322df28e6240b797693
applications/task-work-order/src/axiosXT.js
@@ -1,7 +1,6 @@
import axios from 'axios'
import store from '@/store/'
import router from '@/router/'
import { serialize } from '@/utils/util'
import { serialize, logOutFun } from '@/utils/util'
import { getToken, removeToken, removeRefreshToken } from '@/utils/auth'
import { ElMessage } from 'element-plus'
@@ -16,22 +15,6 @@
   withCredentials: false,
})
function logOutFun () {
   store.dispatch('LogOut').then(() => {
      const { VITE_APP_PARENT_SYSTEM, VITE_APP_ENV } = import.meta.env
      const isDev = VITE_APP_ENV === 'development'
      const urlParams = new URLSearchParams(window.location.search);
      const devLogin = urlParams.get('devLogin');
      isErrorShown = false
      _retry = false
      isDev || devLogin
         ? router.push({ path: '/login' })
         : window.location.replace(`${VITE_APP_PARENT_SYSTEM}/#/login`)
   })
}
//http request拦截
serviceXT.interceptors.request.use(
@@ -64,7 +47,7 @@
      const message = res?.data?.msg || res?.data?.message || '系统错误'
      // 如果是401并且已经重试过,直接跳转到登录页面
      if ((status === 500 || status === 401) && !_retry) {
      if ((status === 401) && !_retry) {
         _retry = true
         // 首次报错时提示
         if (!isErrorShown) {
@@ -75,7 +58,10 @@
         removeToken()
         removeRefreshToken()
         // 重定向到登录页
         logOutFun()
         logOutFun().then(() => {
            isErrorShown = false
            _retry = false
         })
         return Promise.reject(new Error(message))
      }