jiangping
2024-02-18 05cf6324ea8322164d99a3d3d4161fe374534b3b
platform/src/utils/request.js
@@ -3,11 +3,11 @@
import pkg from '../../package'
import { trim } from './util'
import cache from '../plugins/cache'
import { Message, Loading } from 'element-ui'
axios.defaults.headers.common['Content-Type'] = 'application/json;charset=UTF-8'
const axiosInstance = axios.create({
  baseURL: process.env.VUE_APP_API_PREFIX,
  // baseURL: process.env.VUE_APP_API,
  // 请求超时时间
  timeout: 60000
})
@@ -30,9 +30,9 @@
  // 设置操作平台
  config.headers['eva-platform'] = `pc-${pkg.version}`
  // 设置认证头
  const authToken = Cookies.get('doumee-auth-token')
  const authToken = Cookies.get('eva-auth-token')
  if (authToken != null) {
    config.headers['doumee-auth-token'] = authToken
    config.headers['eva-auth-token'] = authToken
  }
  return config
}, function (error) {
@@ -41,6 +41,8 @@
// 新建响应拦截器
axiosInstance.interceptors.response.use((response) => {
  // console.log(response.status)
  // debugger
  // 请求失败
  if (response.status !== 200) {
    return Promise.reject(new Error('服务器繁忙,请稍后再试'))
@@ -52,7 +54,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)
  }