From 0cbbbfacc771bd63a7351039ac6b62720624768a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cls=5F=E5=AE=81=E6=B3=A2=E6=9C=AC=E6=9C=BA?= <908705107@qq.com> Date: Fri, 12 Jun 2026 17:25:20 +0800 Subject: [PATCH] chore: trim request query dependency --- .../src/request-client/request-client.ts | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/web/packages/effects/request/src/request-client/request-client.ts b/web/packages/effects/request/src/request-client/request-client.ts index d0249ee..dfe8419 100644 --- a/web/packages/effects/request/src/request-client/request-client.ts +++ b/web/packages/effects/request/src/request-client/request-client.ts @@ -5,13 +5,47 @@ import type { RequestClientConfig, RequestClientOptions } from './types'; import { bindMethods, isString, merge } from '@vben/utils'; import axios from 'axios'; -import qs from 'qs'; import { FileDownloader } from './modules/downloader'; import { InterceptorManager } from './modules/interceptor'; import { SSE } from './modules/sse'; import { FileUploader } from './modules/uploader'; +function stringifyQuery( + params: Record, + arrayFormat: 'brackets' | 'comma' | 'indices' | 'repeat', +) { + const searchParams = new URLSearchParams(); + + for (const [key, value] of Object.entries(params ?? {})) { + if (value === undefined || value === null) { + continue; + } + + if (!Array.isArray(value)) { + searchParams.append(key, value); + continue; + } + + if (arrayFormat === 'comma') { + searchParams.append(key, value.join(',')); + continue; + } + + value.forEach((item, index) => { + const arrayKey = + arrayFormat === 'brackets' + ? `${key}[]` + : arrayFormat === 'indices' + ? `${key}[${index}]` + : key; + searchParams.append(arrayKey, item); + }); + } + + return searchParams.toString(); +} + function getParamsSerializer( paramsSerializer: RequestClientOptions['paramsSerializer'], ) { @@ -19,17 +53,17 @@ function getParamsSerializer( switch (paramsSerializer) { case 'brackets': { return (params: any) => - qs.stringify(params, { arrayFormat: 'brackets' }); + stringifyQuery(params, 'brackets'); } case 'comma': { - return (params: any) => qs.stringify(params, { arrayFormat: 'comma' }); + return (params: any) => stringifyQuery(params, 'comma'); } case 'indices': { return (params: any) => - qs.stringify(params, { arrayFormat: 'indices' }); + stringifyQuery(params, 'indices'); } case 'repeat': { - return (params: any) => qs.stringify(params, { arrayFormat: 'repeat' }); + return (params: any) => stringifyQuery(params, 'repeat'); } } }