Sanakey
5 天以前 2af71bcf522c485ea005184c977986374a7dcc4a
src/utils/http/axios/index.ts
@@ -19,6 +19,7 @@
import { useUserStoreWithOut } from '@/store/modules/user';
import { AxiosRetry } from '@/utils/http/axios/axiosRetry';
import axios from 'axios';
import DragBar from '@/layouts/default/sider/DragBar.vue';
const globSetting = useGlobSetting();
const urlPrefix = globSetting.urlPrefix;
@@ -44,17 +45,19 @@
      return res.data;
    }
    // 错误的时候返回
    const { data } = res;
    if (!data) {
      // return '[HTTP] Request has no return value';
      throw new Error(t('sys.api.apiRequestFailed'));
    }
    //  这里 code,result,message为 后台统一的字段,需要在 types.ts内修改为项目自己的接口返回格式
    const { code, result, message } = data;
    const { code, result, state } = data;
    const { msg: message } = data;
    // 这里逻辑可以根据项目进行修改
    const hasSuccess = data && Reflect.has(data, 'code') && code === ResultEnum.SUCCESS;
    const isPass = code === ResultEnum.SUCCESS || state === ResultEnum.SUCCESS;
    const isReflect = Reflect.has(data, 'code') || Reflect.has(data, 'state');
    const hasSuccess = data && isReflect && isPass;
    if (hasSuccess) {
      let successMsg = message;
@@ -67,7 +70,7 @@
      } else if (options.successMessageMode === 'message') {
        createMessage.success(successMsg);
      }
      return result;
      return result || data;
    }
    // 在此处根据自己项目的实际情况对不同的code执行不同的操作
@@ -232,7 +235,7 @@
        // authentication schemes,e.g: Bearer
        // authenticationScheme: 'Bearer',
        authenticationScheme: '',
        timeout: 10 * 1000,
        timeout: 60 * 1000,
        // 基础接口地址
        // baseURL: globSetting.apiUrl,
@@ -241,6 +244,7 @@
        // headers: { 'Content-Type': ContentTypeEnum.FORM_URLENCODED },
        // 数据处理方式
        transform: clone(transform),
        withCredentials: true,
        // 配置项,下面的选项都可以在独立的接口请求中覆盖
        requestOptions: {
          // 默认将prefix 添加到url