diff --git a/admin-web/src/utils/request.qs.js b/admin-web/src/utils/request.qs.js new file mode 100644 index 000000000..bbc9521e2 --- /dev/null +++ b/admin-web/src/utils/request.qs.js @@ -0,0 +1,37 @@ +/* eslint-disable */ +import qs from 'qs'; + +/** + * 过滤字符串为 '' 直接不传了 + * + * @param params + */ +function filterEmptyStr(params) { + function filterObject(object) { + const res = {}; + for (const key in params) { + const val = params[key]; + if (typeof val === 'string' && val) { + res[key] = val; + } else { + res[key] = val; + } + } + return res; + } + + if (typeof params === 'object') { + return filterObject(params); + } else if (params instanceof Array) { + let res = []; + for (const object in params) { + res.push(filterObject(params)); + } + } +} + +export function stringify(params) { + return qs.stringify(filterEmptyStr(params)); +} + +export default qs;