jiangping
2024-06-20 09da100729793848bc01b51f7b05ca3f1e7ec64f
company/src/utils/request.js
@@ -3,7 +3,7 @@
import pkg from '../../package'
import { trim } from './util'
import cache from '../plugins/cache'
import { Message } from 'element-ui'
import { Message, Loading } from 'element-ui'
axios.defaults.headers.common['Content-Type'] = 'application/json;charset=UTF-8'
const axiosInstance = axios.create({
@@ -30,9 +30,10 @@
  // 设置操作平台
  config.headers['eva-platform'] = `pc-${pkg.version}`
  // 设置认证头
  const authToken = Cookies.get('eva-auth-token')
  const cookieName = process.env.VUE_APP_COOKIE_NAME || 'eva-auth-token'
  const authToken = Cookies.get(cookieName)
  if (authToken != null) {
    config.headers['eva-auth-token'] = authToken
    config.headers[cookieName] = authToken
  }
  return config
}, function (error) {
@@ -41,8 +42,7 @@
// 新建响应拦截器
axiosInstance.interceptors.response.use((response) => {
  console.log(response.status)
  // console.log(response.status)
  // debugger
  // 请求失败
  if (response.status !== 200) {
@@ -55,7 +55,8 @@
  // 未登录
  if (response.data.code === 401) {
    if (response.config.autoLogin !== false) {
      window.location.href = process.env.VUE_APP_ROUTER_MODE === 'history' ? '/#/login' : '/login'
      location.reload()
      // window.location.href = process.env.VUE_APP_ROUTER_MODE === 'history' ? '/login' : '/#/login'
    }
    return Promise.reject(response.data)
  }