Commit 868264dc by 杨明

formData

1 parent ce518e43
......@@ -4,7 +4,7 @@
* @Last Modified by: huyue
* @Last Modified time: 2021-07-16 18:02:05
*/
import { createSign } from './util'
import util from './util'
import axios from 'axios'
import qs from 'qs'
function Http(options = {}) {
......@@ -32,13 +32,18 @@ Http.prototype.create = function () {
data.sessionId = this.customer.sessionId || data.sessionId
if (sign) {
let _configSign = this.customer.sign || {}
data = createSign(Object.assign({}, _configSign, data), this.customer.secret, noSignAttr, this.customer.signWay)
data = util.createSign(Object.assign({}, _configSign, data), this.customer.secret, noSignAttr, this.customer.signWay)
}
const method = config.method.toLowerCase()
if (method == 'get') {
config.params = data
} else if (method == 'post') {
config.data = qs.stringify(data)
if (config.format == 'formData') {
config.headers['Content-Type'] = 'multipart/form-data'
config.data = util.appendFormData(data)
} else {
config.data = qs.stringify(data)
}
}
return config
},
......
......@@ -173,6 +173,16 @@ export const Util = {
}, [])
collect.sign = { sha1, md5 }[way](secret + str.join('') + secret).toUpperCase()
return collect
},
// 转为formData数据
appendFormData: function (obj) {
const formData = new FormData()
for (let k in obj) {
if (obj.hasOwnProperty(k)) {
formData.append(k, obj[k])
}
}
return formData
}
}
export const createSign = Util.createSign
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!