对 qs stringify 重写
This commit is contained in:
parent
1ebc7492fa
commit
d51fc7f5d0
37
admin-web/src/utils/request.qs.js
Normal file
37
admin-web/src/utils/request.qs.js
Normal file
@ -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;
|
Loading…
Reference in New Issue
Block a user