You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

35 lines
984 B

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
}