ZZJ
2022-04-12 994e5e08cba4e6b9ce321b7cf5cb1ec8d19dfa22
src/scripts/httpRequest.ts
@@ -12,27 +12,24 @@
/* //POST传参序列化(添加请求拦截器) */
Axios.interceptors.request.use(
  config => {
    // config.data = JSON.stringify(config.data)
    // let Public = {};
    // if (
    //   config.method === "post" ||
    //   config.method === "put" ||
    //   config.method === "delete"
    // ) {
    //   // 序列化
    //   // config.data = qs.stringify(config.data);
    //   // config.data = qs.stringify(Object.assign(Public, config.data));
    // } else {
    //   config.method = "get";
    //   config.params = Object.assign(Public, config.data);
    // }
    // config.headers = {
    //   "X-Requested-With": "XMLHttpRequest",
    //   Accept: "application/json",
    //   "Content-Type": "application/json; charset=UTF-8"
    // };
    if (
      config.method === "post" &&
      sessionStorage.getItem('clusterId') ||
      sessionStorage.getItem('devId')
    ) {
      if( !config.data ) {
        config.data = {}
      }
      if(typeof config.data == 'object' ) {
       config.data.clusterId = sessionStorage.getItem('clusterId')
       config.data.devId = sessionStorage.getItem('devId')
      }
    }
    // 若是有做鉴权token , 就给头部带上token
    let token =
      sessionStorage.getItem('loginedInfo') &&
      JSON.parse(sessionStorage.getItem('loginedInfo')).access_token
@@ -42,6 +39,10 @@
    return config
  },
  error => {
    console.log('请求错误');
    console.log(error);
    /*  Message({
      showClose: true,
      message: "提交出错,请联系管理员!",
@@ -86,8 +87,13 @@
    /* //return res.data ? res.data : {}; */
  },
  error => {
    console.log('响应错误');
    console.log(error);
    let errJson: any = {
      success: false
    }
    if(error && error.response&&error.response.status == 404) {
      return
    }
    // 下面是接口回调的satus ,因为我做了一些错误页面,所以都会指向对应的报错页面
    if (error && error.response) {
@@ -164,7 +170,6 @@
      //   path: '/login'
      // });
    }
    console.log(error.response);
    
    if(error.response&&error.response.data&&!error.response.data.success ) {
      errJson.message =error.response.data.msg