Fixiaobai
2023-09-09 34a7e21b3508ac0f5f011d958210fdb7176d726b
src/utils/request.js
@@ -1,4 +1,5 @@
import axios from 'axios'
import router from '../router/index'
import { MessageBox, Message } from 'element-ui'
import store from '@/store'
import { getToken } from '@/utils/auth'
@@ -7,7 +8,7 @@
const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 5000 // request timeout
  timeout: 10000 // request timeout
})
// request interceptor
@@ -48,7 +49,30 @@
    // if the custom code is not 20000, it is judged as an error.
    if (res.code !== 200) {
      console.log(res.message || 'Error')
      if(res.code===400){
        Message({
        message: res.message,
        type: 'warning',
        duration: 5 * 1000
      })
      }
      if(res.code===401){
        Message({
        message: res.message,
        type: 'warning',
        duration: 5 * 1000
      })
      sessionStorage.removeItem("user")
      sessionStorage.setItem("flushPage",1)
      router.replace({path: '/login'});
      }
      if(res.code===403){
        Message({
        message: res.message,
        type: 'warning',
        duration: 5 * 1000
      })
      }
      // Message({
      //   message: res.message || 'Error',
      //   type: 'error',