写了
chooseImage22: async function (){
var that = this;
var user_id = wx.getStorageSync(‘userid’);
wx.chooseImage({
count: 6, // 默认9
sizeType: [‘compressed’], // 可以指定是原图还是压缩图,默认二者都有
sourceType: [‘album’, ‘camera’], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
//var tempFilePaths = res.tempFilePaths[0];
var tempFilePaths = res.tempFilePaths;
var imgs1 = that.data.imgs1;
for (var i = 0; i < tempFilePaths.length; i++) {
if (imgs1.length >= 6) {
that.setData({
imgs1: imgs1
});
// return false;
} else {
//imgs1.push(tempFilePaths[i]);
}
}
that.setData({
imgs1: imgs1
});
for (var s = 0; s < tempFilePaths.length; s++) {
let promise = new Promise((resolve,reject)=>{
wx.uploadFile({
url: app.config.apiUrl + ‘Api/Poster/uploadImage’,
filePath: tempFilePaths[s],
name: ‘image’,
formData:{uid:user_id,s:s},
success: function (res) {
console.log(‘abcccdddd’);
console.log(res);
var st = JSON.parse(res.data);
console.log(st);
image = st.data;
var img_data = that.data.img_data;
var imgs1 = that.data.imgs1;
if (imgs1.length < 6){
img_data.push(st.data.imgurl);
imgs1.push(app.config.apiDomain+st.data.imgurl);
}
/*if(!that.data.ttpic){ //用户没有上传图片
that.setData({
ttpic:image
});
}*/
that.setData({
//mrpic: 'https://mp.8658.cn’+image,
img_data: img_data,
//ttpic: image, //选中的自定义转发图片
//pic: image
imgs1:imgs1
})
resolve(‘done’);
},
fail:function(){
console.log(‘uploadfile-fail’);
}
})
});
let result = await promise;
} //end for
},
fail: function (res) {
},
complete: function (res) {
}
});
},