js
formSubmit: function(e) {
var that = this;
wx.request({
url: url,
data: {
xx: xx
},
method: 'POST',
dataType: 'json',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: async function(res) {
var status = res.statusCode
if (status == 203) {
wx.showToast({
title: '名称含有敏感词汇',
icon: 'none',
duration: 2000
})
} else {
that.foodImage(picpath, that);
for (let j = 0; j < that.data.img.length; j++) {
await that.data.img[j].then(v => {
that.data.arr.push(JSON.parse(v.data).imageUrl)
that.setData({
arr: that.data.arr,
});
})
}
wx.request({
url: url,
data: {
picpath: that.data.arr,
},
method: 'POST',
dataType: 'json',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function (res) {
var status = res.statusCode
}
})
}
}
})
}
foodImage: (param, that) => {
var e = param
for (let i = 0; i < e.length; i++) {
let s = new Promise((resolve, reject) => {
wx.uploadFile({
url: app.serverUrl + app.savefood + '/upimage',
filePath: e[i],
name: 'image',
success: function (res) {
resolve(res)
},
fail: function (res) {
wx.showToast({
title: '图片上传失败',
icon: 'none',
duration: 2000
})
reject(res)
}
})
});
that.data.img.push(s)
that.setData({
img: that.data.img,
});
}
}