const Multipart = require('../utils/Multipart.min')
|
const $f = require('./baserequest')
|
const util = require('../utils/util')
|
|
module.exports = {
|
//获取台账类型
|
getLedgerType: function (sceneType, fun) {
|
let cb = {
|
url: `/ledger/type`,
|
params: {
|
sceneType: sceneType,
|
},
|
}
|
Object.assign(cb, fun)
|
|
let fun1 = util.deepCopy(cb)
|
fun1.success = function (res) {
|
res.forEach(r => {
|
r.iconUrl = $f.basePicUrl + r.iconUrl
|
});
|
cb.success(res)
|
}
|
$f.get(fun1)
|
},
|
|
//上传台账
|
// uploadLedger: function (userId, ledger, files, fun) {
|
// let formData = new FormData();
|
|
// // 用法
|
// // formData.append("name", "value"); // value 表单值
|
// // formData.appendFile("file", filepath); // filepath 文件路径
|
|
// // formData.append("params", JSON.stringify([ledger]))
|
// files.forEach(f => {
|
// formData.appendFile("images", f);
|
// });
|
|
// // formData.getData() => {
|
// // buffer:<ArrayBuffer>[], // buffer 表单数据的ArrayBuffer对象
|
// // contentType: string, // http请求Content-Type头部内容
|
// // }
|
// const data = formData.getData();
|
|
// let cb = {
|
// url: `/ledger/${userId}/upload`,
|
// params: {
|
// params: JSON.stringify([ledger]),
|
// },
|
// header: {
|
// 'content-type': data.contentType
|
// },
|
// data: data.buffer,
|
// }
|
|
// Object.assign(cb, fun)
|
// $f.post(cb)
|
// }
|
uploadLedger: function (userId, ledger, paths, fun) {
|
const fields = [{
|
name: 'params',
|
value: JSON.stringify([ledger])
|
}]
|
const files = []
|
paths.forEach(p => {
|
files.push({
|
name: 'images',
|
filePath: p
|
})
|
});
|
console.log(files);
|
new Multipart({
|
fields,
|
files
|
}).submit($f.baseUrl + `/ledger/${userId}/upload`)
|
}
|
}
|