wx.getImageInfo({
src: item,
success: res => {
console.log(res)
var imageSize = util.imageUtil(res);
var oldWidth = imageSize.oldWidth;
var oldHeight= imageSize.oldHeight;
var targetWidth = imageSize.imageWidth;
var targetHeight = imageSize.imageHeight;
that.setData({
cw: oldWidth,
ch: oldHeight
});
const ctx = wx.createCanvasContext('ypyasuo');
ctx.drawImage(item, 0, 0, oldWidth, oldHeight);
ctx.draw(true, setTimeout(function () {
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: oldWidth,
height: oldHeight,
destWidth: targetWidth,
destHeight: targetHeight,
canvasId: 'ypyasuo',
success: function success(res) {
item = res.tempFilePath
var sort = i;
var nowTime = util.formatTime(new Date());
uploadImage(item, 'cbb/' + nowTime + '/',
function (result) {
console.log("======上传成功图片地址为:", result);
that.data.imgUrl[sort] = result;
if (i == count - 1) {
console.log('上传完成')
wx.hideLoading()
var images = '';
for (var ii = 0; ii < that.data.imgUrl.length; ii++) {
if (ii > 0) {
images += ',' + that.data.imgUrl[ii];
} else {
images += that.data.imgUrl[ii];
}
}
console.log(images);
wx.request({
url: app.globalData.baseHost + '/api/member/addyuhuo',
data: {
user_id: app.globalData.userId,
cid: 41,
title: that.data.content,
images: images,
pass: app.globalData.requestpass
},
method: 'post',
success(res) {
wx.showToast({
title: res.data,
icon: 'success',
mask: true,
duration: 3000
})
setTimeout(function () {
wx.switchTab({ url: '../../my/my' });
}, 3000)
}
})
} else {
i++
console.log('开始传下一个' + i)
that.upload(i);
}
}, function (result) {
console.log("======上传失败======", result);
}
)
}, fail: function (e) {
console.log('压缩失败')
}
});
}, 1000));
}
});
},
己解决,是我把变量写错啦