feat: 新增encodeParams工具

This commit is contained in:
xieyonghong 2023-03-02 14:33:28 +08:00
parent 421788b2d6
commit b3ea70db0f
1 changed files with 11 additions and 1 deletions

View File

@ -1,4 +1,14 @@
import { isObject } from 'lodash-es'
import { isObject, isArray } from 'lodash-es'
const encodeParams = (params: Record<string, any>) => {
const _params = new URLSearchParams()
for (const key in params) {
const _value = params[key]
const isArrOrObj = isObject(_value) || isArray(_value)
_params.set(key, isArrOrObj ? encodeParams(_value) : _value)
}
return _params.toString()
}
export default function encodeQuery(params: any) {
if (!params) return {};