From 48ca7aca8c30c8ad3cb3530264bf2cbcae6a980a Mon Sep 17 00:00:00 2001 From: dap <15891557205@163.com> Date: Fri, 6 Dec 2024 09:27:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BE=AE=E6=9C=8D=E5=8A=A1=E7=89=88?= =?UTF-8?q?=E6=9C=AC=20=E5=8C=BA=E9=97=B4=E6=9F=A5=E8=AF=A2=E5=92=8C?= =?UTF-8?q?=E4=B8=AD=E6=96=87=E6=90=9C=E7=B4=A2=E6=9D=A1=E4=BB=B6=E4=B8=80?= =?UTF-8?q?=E8=B5=B7=E4=BD=BF=E7=94=A8=20=E6=97=A0=E6=B3=95=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + apps/web-antd/src/api/request.ts | 18 ++++++++++++++++++ packages/effects/request/package.json | 4 +++- packages/effects/request/src/index.ts | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a6237f5..676a5698 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ **BUG FIXES** - 操作日志详情 在description组件中json预览样式异常 +- 微服务版本 区间查询和中文搜索条件一起使用 无法正确查询 # 1.1.2 diff --git a/apps/web-antd/src/api/request.ts b/apps/web-antd/src/api/request.ts index 7d540963..b3d80804 100644 --- a/apps/web-antd/src/api/request.ts +++ b/apps/web-antd/src/api/request.ts @@ -10,6 +10,7 @@ import { authenticateResponseInterceptor, errorMessageResponseInterceptor, RequestClient, + stringify, } from '@vben/request'; import { useAccessStore } from '@vben/stores'; @@ -94,6 +95,23 @@ function createRequestClient(baseURL: string) { // 添加全局clientId config.headers.clientId = clientId; + /** + * 格式化get/delete参数 + * 如果包含自定义的paramsSerializer则不走此逻辑 + */ + if ( + ['DELETE', 'GET'].includes(config.method?.toUpperCase() || '') && + config.params && + !config.paramsSerializer + ) { + /** + * 1. 格式化参数 微服务在传递区间时间选择(后端的params Map类型参数)需要格式化key 否则接收不到 + * 2. 数组参数需要格式化 后端才能正常接收 会变成arr=1&arr=2&arr=3的格式来接收 + */ + config.paramsSerializer = (params) => + stringify(params, { arrayFormat: 'repeat' }); + } + const { encrypt } = config; // 全局开启请求加密功能 && 该请求开启 && 是post/put请求 if ( diff --git a/packages/effects/request/package.json b/packages/effects/request/package.json index 59bcd836..3cff702c 100644 --- a/packages/effects/request/package.json +++ b/packages/effects/request/package.json @@ -22,9 +22,11 @@ "dependencies": { "@vben/locales": "workspace:*", "@vben/utils": "workspace:*", - "axios": "catalog:" + "axios": "catalog:", + "qs": "^6.13.1" }, "devDependencies": { + "@types/qs": "^6.9.17", "axios-mock-adapter": "catalog:" } } diff --git a/packages/effects/request/src/index.ts b/packages/effects/request/src/index.ts index fae1b058..e1805bf5 100644 --- a/packages/effects/request/src/index.ts +++ b/packages/effects/request/src/index.ts @@ -1,2 +1,3 @@ export * from './request-client'; export * from 'axios'; +export { stringify } from 'qs';