odc.xiaohui
2023-12-04 e19cf3c81d4e45654442233afd4a002afeaa5143
src/utils/request.ts
@@ -10,6 +10,8 @@
import { getLanguage } from '@/lang';
import { encryptBase64, encryptWithAes, generateAesKey } from '@/utils/crypto';
import { encrypt } from '@/utils/jsencrypt';
import router from "@/router";
import { ElLoading, ElMessage, ElNotification } from "element-plus";
let downloadLoadingInstance: LoadingInstance;
// 是否显示重新登录
@@ -93,9 +95,10 @@
  }
);
// 响应拦截器
service.interceptors.response.use(
  (res: AxiosResponse) => {
  async (res: AxiosResponse) => {
    // 未设置状态码则默认成功状态
    const code = res.data.code || HttpStatus.SUCCESS;
    // 获取错误信息
@@ -105,24 +108,31 @@
      return res.data;
    }
    if (code === 401) {
      const userStore = useUserStore();
      await userStore.logout()
      console.log(code, 'code==============');
      await router.push({ path: '/login' });
      // prettier-ignore
      if (!isRelogin.show) {
        // isRelogin.show = true;
        isRelogin.show = true;
        ElMessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
          confirmButtonText: '重新登录',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          isRelogin.show = false;
          useUserStore().logout().then(() => {
              location.href = import.meta.env.VITE_APP_CONTEXT_PATH + 'index';
            });
        }).catch(() => {
          isRelogin.show = false;
        });
      }
      return Promise.reject('无效的会话,或者会话已过期,请重新登录。');
      // if (!isRelogin.show) {
      //   // isRelogin.show = true;
      //   isRelogin.show = true;
      //   ElMessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
      //     confirmButtonText: '重新登录',
      //     cancelButtonText: '取消',
      //     type: 'warning'
      //   }).then(() => {
      //     isRelogin.show = false;
      //     useUserStore().logout().then(() => {
      //         location.href = import.meta.env.VITE_APP_CONTEXT_PATH + 'index';
      //       });
      //   }).catch(() => {
      //     isRelogin.show = false;
      //   });
      // }
      // return Promise.reject('无效的会话,或者会话已过期,请重新登录。');
      return
    } else if (code === HttpStatus.SERVER_ERROR) {
      console.log(msg);
      ElMessage({ message: msg, type: 'error' });