From 6d2de002ef9e9f2274d3e9b833d867eac8cf063c Mon Sep 17 00:00:00 2001 From: alucardxh Date: Mon, 2 Sep 2024 10:55:11 +0900 Subject: [PATCH] Support array parameter parsing (#4300) --- src/utils/index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/utils/index.ts b/src/utils/index.ts index 2b6c68b42..e7cd76cd9 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -20,14 +20,19 @@ export function getPopupContainer(node?: HTMLElement): HTMLElement { * @param obj * @returns {string} * eg: - * let obj = {a: '3', b: '4'} + * let obj = {a: '3', b: '4', c: ['1','2']} * setObjToUrlParams('www.baidu.com', obj) - * ==>www.baidu.com?a=3&b=4 + * ==>www.baidu.com?a=3&b=4&c=1,2 */ export function setObjToUrlParams(baseUrl: string, obj: any): string { let parameters = ''; for (const key in obj) { - parameters += key + '=' + encodeURIComponent(obj[key]) + '&'; + const value = obj[key]; + if (Array.isArray(value)) { + parameters += `${key}=${encodeURIComponent(value.join(','))}&`; + } else { + parameters += `${key}=${encodeURIComponent(value)}&`; + } } parameters = parameters.replace(/&$/, ''); return /\?$/.test(baseUrl) ? baseUrl + parameters : baseUrl.replace(/\/?$/, '?') + parameters;