charles
2024-07-18 dbab45ef6e56c32ca3b2d286ec5cb7ed0c86bfea
src/common/untils/request.js
@@ -1,6 +1,6 @@
import axios from "axios"
import { Message } from "element-ui"
import {getApsPage} from './index.js';
// import router from '@/router'
// 开发环境下将自己的token复制到这里, 也可以在浏览器中手动添加token到cookie中,cookie中的token优先
@@ -27,17 +27,17 @@
  withCredentials: true // 是否允许带cookie这些
})
const getApsPage = () => {
/*const getApsPage = () => {
    // 首页部署在各个环境的端口
    const loginPathMap = {
        prod:`//${window.location.hostname}:9080`,
        test:`//192.168.20.119:9080`,
        // 想跳到本地启动的登录页的话需要把dev改成你本地项目路径
        dev: `//192.168.20.124:8081`
        dev: `//192.168.8.108:8080`
    }
    return loginPathMap[environmentType()]
}
}*/
/* //POST传参序列化(添加请求拦截器) */
Axios.interceptors.request.use(
@@ -64,18 +64,35 @@
  (res) => {
    /* //对响应数据做些事 */
    if (res.data.code === 200) {
      return res.data ? res.data : {}
      if(res.config.IsHeader){
        return res;
      }else{
        return res.data ? res.data : {}
      }
    } else if (res.data.code === 700001 || res.data.code === 700005) {
      console.log("客户名称重复")
      return res
    } else if([2012,2013,2014,2015].includes(res.data.code)){
      if (isDev){
          alert("JWT失效")
       // alert("JWT失效,即将跳转至登录页..")
        window.location = getApsPage()+'/login'
      }else {
        //   JWT鉴权失效 跳转到登录页
        window.location = getApsPage()+'/login'
      }
      return Promise.reject(res.data)
    }else if([2036].includes(res.data.code)){
      if (isDev){
        window.location = getApsPage()+'/commonWeb?resetPwd=true'
      }else {
        //   JWT鉴权失效 跳转到登录页
        window.location = getApsPage()+'/commonWeb?resetPwd=true'
      }
      return Promise.reject(res.data)
      // if(window.location.pathname && window.location.pathname !== '/login'){
      //   window.location = window.location.origin+'/login'
      // }
    } else {
      Message({
        message: res.data.msg,
@@ -88,7 +105,8 @@
  (error) => {
    if (error.response.status === 401){
      if (isDev){
          alert("JWT失效")
        alert("JWT失效,即将跳转至登录页..")
        window.location = getApsPage()+'/login'
      }else {
        //   JWT鉴权失效 跳转到登录页
        window.location = getApsPage()+'/login'