diff --git a/CHANGELOG.md b/CHANGELOG.md index 96186684..168b6c1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ **OTHERS** - 菜单管理 改为虚拟滚动 +- 移除requestClient的一些冗余参数 **BUG FIXES** diff --git a/apps/web-antd/src/api/request.ts b/apps/web-antd/src/api/request.ts index f9830b75..7d540963 100644 --- a/apps/web-antd/src/api/request.ts +++ b/apps/web-antd/src/api/request.ts @@ -12,7 +12,6 @@ import { RequestClient, } from '@vben/request'; import { useAccessStore } from '@vben/stores'; -import { isString } from '@vben/utils'; import { message, Modal } from 'ant-design-vue'; import { isEmpty, isNull } from 'lodash-es'; @@ -27,8 +26,6 @@ import { } from '#/utils/encryption/crypto'; import * as encryptUtil from '#/utils/encryption/jsencrypt'; -import { formatRequestDate, joinTimestamp, setObjToUrlParams } from './helper'; - const { apiURL, clientId, enableEncrypt } = useAppConfig( import.meta.env, import.meta.env.PROD, @@ -46,16 +43,10 @@ function createRequestClient(baseURL: string) { baseURL, // 消息提示类型 errorMessageMode: 'message', - // 格式化提交参数时间 - formatDate: true, // 是否返回原生响应 比如:需要获取响应头时使用该属性 isReturnNativeResponse: false, // 需要对返回数据进行处理 isTransformResponse: true, - // post请求的时候添加参数到url - joinParamsToUrl: false, - // 是否加入时间戳 - joinTime: false, }); /** @@ -103,51 +94,7 @@ function createRequestClient(baseURL: string) { // 添加全局clientId config.headers.clientId = clientId; - const { encrypt, formatDate, joinParamsToUrl, joinTime = true } = 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), - ); - } - } - } + const { encrypt } = config; // 全局开启请求加密功能 && 该请求开启 && 是post/put请求 if ( enableEncrypt && diff --git a/packages/effects/request/src/request-client/types.ts b/packages/effects/request/src/request-client/types.ts index 06ff223a..aca3f62a 100644 --- a/packages/effects/request/src/request-client/types.ts +++ b/packages/effects/request/src/request-client/types.ts @@ -62,10 +62,6 @@ declare module 'axios' { * 错误弹窗类型 */ errorMessageMode?: ErrorMessageMode; - /** - * 是否格式化日期 - */ - formatDate?: boolean; /** * 是否返回原生axios响应 */ @@ -74,14 +70,6 @@ declare module 'axios' { * 是否需要转换响应 即只获取{code, msg, data}中的data */ isTransformResponse?: boolean; - /** - * param添加到url后 - */ - joinParamsToUrl?: boolean; - /** - * 加入时间戳 - */ - joinTime?: boolean; /** * 成功弹窗类型 */