wujingjing
2024-09-13 e0243a29ebd9617ff660dcae75b44dd3e09b956d
src/utils/request.ts
@@ -1,4 +1,4 @@
import type { AxiosInstance, AxiosRequestConfig } from 'axios';
import type { AxiosInstance, AxiosRequestConfig, CancelToken } from 'axios';
import axios from 'axios';
import { ElLoadingService, ElMessage } from 'element-plus';
import router from '../router';
@@ -10,6 +10,7 @@
   loading?: boolean;
   noAuth?: boolean;
   handleFail?: boolean;
   cancelToken?: CancelToken | undefined;
};
export const checkAuth = () => {
   const session = Local.get(accessSessionKey);
@@ -37,14 +38,15 @@
   clearAccessTokens();
   window.location.reload();
});
window.handleNoAuth = handleNoAuth;
let requestNum = 0;
let loadingInstance: ReturnType<typeof ElLoadingService>;
const addLoading = () => {
   // 增加loading 如果pending请求数量等于1,弹出loading, 防止重复弹出
   // 增加loading 如果pending请求数量等于1,弹出loading, 防止重复弹出F
   requestNum++;
   if (requestNum == 1) {
       loadingInstance = ElLoadingService({
      loadingInstance = ElLoadingService({
         text: '加载中...',
         target: '.layout-parent',
      });
@@ -72,7 +74,7 @@
            config.headers['hswatersession'] = accessSession;
         }
         if (!noAuth) {
            if (!accessSession ) {
            if (!accessSession) {
               handleNoAuth();
            }
         }
@@ -111,7 +113,7 @@
            switch (serveData?.err_code) {
               case ErrorCode.Auth:
                  handleNoAuth();
                     throw '权限验证失败';
                  throw '权限验证失败';
                  break;
               case ErrorCode.Exception:
                  ElMessage.error('内部错误!');