1
This commit is contained in:
@@ -1,6 +1,27 @@
|
||||
import axios from 'axios'
|
||||
import { formatDate } from './tools'
|
||||
|
||||
/** 递归删除对象中值为空字符串的键(不修改数组内的空字符串元素) */
|
||||
function stripEmptyStringKeys(value) {
|
||||
if (value === null || value === undefined) {
|
||||
return value
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
return value.map((item) => stripEmptyStringKeys(item))
|
||||
}
|
||||
if (typeof value === 'object' && Object.prototype.toString.call(value) === '[object Object]') {
|
||||
const next = {}
|
||||
for (const k of Object.keys(value)) {
|
||||
const v = value[k]
|
||||
if (v === '') {
|
||||
continue
|
||||
}
|
||||
next[k] = stripEmptyStringKeys(v)
|
||||
}
|
||||
return next
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
class Http {
|
||||
constructor() {
|
||||
@@ -131,13 +152,18 @@ class Http {
|
||||
}
|
||||
|
||||
param = JSON.parse(JSON.stringify(param))
|
||||
return param
|
||||
return stripEmptyStringKeys(param)
|
||||
}
|
||||
|
||||
formatFormDataParam(param) {
|
||||
param = param || {}
|
||||
let formData = new FormData()
|
||||
Object.keys(param).forEach(key => {
|
||||
formData.append(key, param[key])
|
||||
Object.keys(param).forEach((key) => {
|
||||
const v = param[key]
|
||||
if (v === '') {
|
||||
return
|
||||
}
|
||||
formData.append(key, v)
|
||||
})
|
||||
return formData
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user