zhanghua
昨天 fc0646f5a7d8ff66470fc3228ac7cff24497d54c
src/utils/request.ts
@@ -1,6 +1,6 @@
import axios, { AxiosResponse, InternalAxiosRequestConfig } from 'axios';
import { useUserStore } from '@/store/modules/user';
import { getToken } from '@/utils/auth';
import { getToken, getPlat } from '@/utils/auth';
import { tansParams, blobValidate } from '@/utils/ruoyi';
import cache from '@/plugins/cache';
import { HttpStatus } from '@/enums/RespEnum';
@@ -12,6 +12,7 @@
import { encrypt } from '@/utils/jsencrypt';
import router from "@/router";
import { ElLoading, ElMessage, ElNotification } from "element-plus";
import { el } from 'element-plus/es/locale';
let downloadLoadingInstance: LoadingInstance;
// 是否显示重新登录
@@ -115,7 +116,10 @@
      await userStore.logout()
      console.log(code, 'code==============');
      await router.push({ path: '/login' });
      if (getPlat() === 'dingding')
        await router.push({ path: '/login' });
      else
        await router.push({ path: '/rzt_login' });
      return
    } else if (code === HttpStatus.SERVER_ERROR) {
      console.log(msg);
@@ -149,30 +153,30 @@
  downloadLoadingInstance = ElLoading.service({ text: '正在下载数据,请稍候', background: 'rgba(0, 0, 0, 0.7)' });
  // prettier-ignore
  return service.post(url, params, {
      transformRequest: [
        (params: any) => {
          return tansParams(params);
        }
      ],
      headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
      responseType: 'blob'
    }).then(async (resp: any) => {
      const isLogin = blobValidate(resp);
      if (isLogin) {
        const blob = new Blob([resp]);
        FileSaver.saveAs(blob, fileName);
      } else {
        const resText = await resp.data.text();
        const rspObj = JSON.parse(resText);
        const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default'];
        ElMessage.error(errMsg);
    transformRequest: [
      (params: any) => {
        return tansParams(params);
      }
      downloadLoadingInstance.close();
    }).catch((r: any) => {
      console.error(r);
      ElMessage.error('下载文件出现错误,请联系管理员!');
      downloadLoadingInstance.close();
    });
    ],
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    responseType: 'blob'
  }).then(async (resp: any) => {
    const isLogin = blobValidate(resp);
    if (isLogin) {
      const blob = new Blob([resp]);
      FileSaver.saveAs(blob, fileName);
    } else {
      const resText = await resp.data.text();
      const rspObj = JSON.parse(resText);
      const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default'];
      ElMessage.error(errMsg);
    }
    downloadLoadingInstance.close();
  }).catch((r: any) => {
    console.error(r);
    ElMessage.error('下载文件出现错误,请联系管理员!');
    downloadLoadingInstance.close();
  });
}
// 导出 axios 实例
export default service;