chore: 移除requestClient的一些冗余参数

This commit is contained in:
dap 2024-11-25 09:34:21 +08:00
parent da0ddfc8c7
commit d214da3303
3 changed files with 2 additions and 66 deletions

View File

@ -7,6 +7,7 @@
**OTHERS** **OTHERS**
- 菜单管理 改为虚拟滚动 - 菜单管理 改为虚拟滚动
- 移除requestClient的一些冗余参数
**BUG FIXES** **BUG FIXES**

View File

@ -12,7 +12,6 @@ import {
RequestClient, RequestClient,
} from '@vben/request'; } from '@vben/request';
import { useAccessStore } from '@vben/stores'; import { useAccessStore } from '@vben/stores';
import { isString } from '@vben/utils';
import { message, Modal } from 'ant-design-vue'; import { message, Modal } from 'ant-design-vue';
import { isEmpty, isNull } from 'lodash-es'; import { isEmpty, isNull } from 'lodash-es';
@ -27,8 +26,6 @@ import {
} from '#/utils/encryption/crypto'; } from '#/utils/encryption/crypto';
import * as encryptUtil from '#/utils/encryption/jsencrypt'; import * as encryptUtil from '#/utils/encryption/jsencrypt';
import { formatRequestDate, joinTimestamp, setObjToUrlParams } from './helper';
const { apiURL, clientId, enableEncrypt } = useAppConfig( const { apiURL, clientId, enableEncrypt } = useAppConfig(
import.meta.env, import.meta.env,
import.meta.env.PROD, import.meta.env.PROD,
@ -46,16 +43,10 @@ function createRequestClient(baseURL: string) {
baseURL, baseURL,
// 消息提示类型 // 消息提示类型
errorMessageMode: 'message', errorMessageMode: 'message',
// 格式化提交参数时间
formatDate: true,
// 是否返回原生响应 比如:需要获取响应头时使用该属性 // 是否返回原生响应 比如:需要获取响应头时使用该属性
isReturnNativeResponse: false, isReturnNativeResponse: false,
// 需要对返回数据进行处理 // 需要对返回数据进行处理
isTransformResponse: true, isTransformResponse: true,
// post请求的时候添加参数到url
joinParamsToUrl: false,
// 是否加入时间戳
joinTime: false,
}); });
/** /**
@ -103,51 +94,7 @@ function createRequestClient(baseURL: string) {
// 添加全局clientId // 添加全局clientId
config.headers.clientId = clientId; config.headers.clientId = clientId;
const { encrypt, formatDate, joinParamsToUrl, joinTime = true } = config; const { encrypt } = config;
const params = config.params || {};
const data = config.data || false;
// TODO: 这块要重构 复杂度太高了
formatDate && data && !isString(data) && formatRequestDate(data);
if (config.method?.toUpperCase() === 'GET') {
if (isString(params)) {
// 兼容restful风格
config.url = `${config.url + params}${joinTimestamp(joinTime, true)}`;
config.params = undefined;
} else {
// 给 get 请求加上时间戳参数,避免从缓存中拿数据。
config.params = Object.assign(
params || {},
joinTimestamp(joinTime, false),
);
}
} else {
if (isString(params)) {
// 兼容restful风格
config.url = config.url + params;
config.params = undefined;
} else {
formatDate && formatRequestDate(params);
if (
Reflect.has(config, 'data') &&
config.data &&
(Object.keys(config.data).length > 0 ||
config.data instanceof FormData)
) {
config.data = data;
config.params = params;
} else {
// 非GET请求如果没有提供data则将params视为data
config.data = params;
config.params = undefined;
}
if (joinParamsToUrl) {
config.url = setObjToUrlParams(
config.url as string,
Object.assign({}, config.params, config.data),
);
}
}
}
// 全局开启请求加密功能 && 该请求开启 && 是post/put请求 // 全局开启请求加密功能 && 该请求开启 && 是post/put请求
if ( if (
enableEncrypt && enableEncrypt &&

View File

@ -62,10 +62,6 @@ declare module 'axios' {
* *
*/ */
errorMessageMode?: ErrorMessageMode; errorMessageMode?: ErrorMessageMode;
/**
*
*/
formatDate?: boolean;
/** /**
* axios响应 * axios响应
*/ */
@ -74,14 +70,6 @@ declare module 'axios' {
* {code, msg, data}data * {code, msg, data}data
*/ */
isTransformResponse?: boolean; isTransformResponse?: boolean;
/**
* param添加到url后
*/
joinParamsToUrl?: boolean;
/**
*
*/
joinTime?: boolean;
/** /**
* *
*/ */