QYF-GitLab1
2 天以前 264a2c1e93e9b9cd3c7e0568b656325b12b008ec
src/plugin/axios/index.ts
@@ -2,11 +2,13 @@
import myConfig from '@/assets/js/config.js'
import toolClass from '@/assets/js/toolClass.js'
import router from '@/router'
import { inject } from 'vue'
// 创建 axios 实例
const service = axios.create({
  baseURL: myConfig.requestCtx,
  timeout: myConfig.requestTimeOut, // 请求超时时间
})
const logIn = inject('logIn')
// 请求拦截器
service.interceptors.request.use(
@@ -48,7 +50,6 @@
  (error) => {
    if ((error.response && error.response.status == 401) || error.code == 'ERR_NETWORK') {
      console.log(router, 'router')
      localStorage.removeItem(myConfig.tokenKey)
      localStorage.removeItem('xiehe-userInfo')
      localStorage.removeItem('xiehe-isUserInfo')
@@ -59,17 +60,16 @@
      sessionStorage.removeItem('cartNumber')
      const url = window.location.hash.slice(1)
      console.log(url, 'url')
      if (url.includes('showLogin=1')) {
        router.push(url)
      } else {
        // router.push(url)
        if (url.includes('?')) {
          console.log(url.includes('?'))
          router.push(url)
        } else {
          router.push(url + '?showLogin=1')
        }
      }
      window.location.href = `${myConfig.requestCtx}/home/#/home?login=true&callBackUrl=${encodeURIComponent(window.location.href)}`
      // window.location.href = `${'http://192.168.3.16:5173'}/#/home?login=true&callBackUrl=${encodeURIComponent(window.location.href)}`
      router.push({
        path: '/home',
        query: {
          login: 'true',
          callBackUrl: encodeURIComponent(window.location.href),
        },
      })
    } else {
      if (error.response && error.response.data && error.response.data.error) {
        console.error(error.response.data.error.msg)