const _cloneDeep = require('lodash/cloneDeep')
|
|
|
|
// 移除空字符串,null, undefined
|
|
export function clearEmptyParam(config) {
|
|
['data', 'params'].forEach(item => {
|
|
if (config[item]) {
|
|
const keys = Object.keys(config[item])
|
|
if (keys.length) {
|
|
keys.forEach(key => {
|
|
const rawType = toRawType(config[item])
|
|
if (['', undefined, null].includes(toRawType(config[item][key]) == 'String' ?
|
|
config[item][key].trim() : config[item][key]) && ['Object'].includes(
|
|
rawType)) {
|
|
// 移除属性之前,进行深拷贝断开引用,避免影响页面
|
|
config[item] = _cloneDeep(config[item])
|
|
delete config[item][key]
|
|
}
|
|
})
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
/**
|
|
* @description 获取原始类型
|
|
* @param {*} value
|
|
* @returns {String} 类型字符串,如'String', 'Object', 'Null', 'Boolean', 'Number', 'Array'
|
|
*/
|
|
export function toRawType(value) {
|
|
return Object.prototype.toString.call(value).slice(8, -1)
|
|
}
|
|
|
|
export default {
|
|
clearEmptyParam
|
|
}
|