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.

34 lines
984 B

8 months ago
  1. const _cloneDeep = require('lodash/cloneDeep')
  2. // 移除空字符串,null, undefined
  3. export function clearEmptyParam(config) {
  4. ['data', 'params'].forEach(item => {
  5. if (config[item]) {
  6. const keys = Object.keys(config[item])
  7. if (keys.length) {
  8. keys.forEach(key => {
  9. const rawType = toRawType(config[item])
  10. if (['', undefined, null].includes(toRawType(config[item][key]) == 'String' ?
  11. config[item][key].trim() : config[item][key]) && ['Object'].includes(
  12. rawType)) {
  13. // 移除属性之前,进行深拷贝断开引用,避免影响页面
  14. config[item] = _cloneDeep(config[item])
  15. delete config[item][key]
  16. }
  17. })
  18. }
  19. }
  20. })
  21. }
  22. /**
  23. * @description 获取原始类型
  24. * @param {*} value
  25. * @returns {String} 类型字符串'String', 'Object', 'Null', 'Boolean', 'Number', 'Array'
  26. */
  27. export function toRawType(value) {
  28. return Object.prototype.toString.call(value).slice(8, -1)
  29. }
  30. export default {
  31. clearEmptyParam
  32. }