[代码]this[代码][代码].cardDataList.reduce((curr, r1, k1, arr1) => {[代码][代码] [代码][代码]return[代码] [代码]curr.then(() => {[代码][代码] [代码][代码]return[代码] [代码]r1.trips.reduce((curr, r2, k2) => {[代码][代码] [代码][代码]return[代码] [代码]curr.then(() => {[代码][代码] [代码][代码]if[代码] [代码](r2.triptype === [代码][代码]'flight'[代码][代码]) {[代码][代码] [代码][代码]return[代码] [代码]this[代码][代码].drawShareCanvas(k1, k2, arr1);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]});[代码][代码] [代码][代码]}, Promise.resolve());[代码][代码] [代码][代码]});[代码][代码] [代码][代码]}, Promise.resolve());[代码] [代码]drawShareCanvas(idx1, idx2, array) {[代码][代码] [代码][代码]......[代码][代码] [代码][代码]......[代码][代码] [代码][代码]return[代码] [代码]new[代码] [代码]Promise(resolve => {[代码][代码] [代码][代码]setTimeout(() => {[代码][代码] [代码][代码]resolve();[代码][代码] [代码][代码]}, 500);[代码][代码] [代码][代码]}).then(() => {[代码][代码] [代码][代码]return[代码] [代码]wx.canvasToTempFilePath({[代码][代码] [代码][代码]x: 0,[代码][代码] [代码][代码]y: 0,[代码][代码] [代码][代码]width: 216,[代码][代码] [代码][代码]height: 174,[代码][代码] [代码][代码]destWidth: 216 * 4,[代码][代码] [代码][代码]destHeight: 174 * 4,[代码][代码] [代码][代码]canvasId: aid,[代码][代码] [代码][代码]success: res => {[代码][代码] [代码][代码]data.sharePicurl = res.tempFilePath;[代码][代码] [代码][代码]this[代码][代码].$store.dispatch([代码][代码]'journey/updateCardDataByShare'[代码][代码], array);[代码][代码] [代码][代码]return[代码] [代码]data;[代码][代码] [代码][代码]}[代码][代码] [代码][代码]// fail: err => {[代码][代码] [代码][代码]// console.error(err);[代码][代码] [代码][代码]// }[代码][代码] [代码][代码]});[代码][代码] [代码][代码]});[代码][代码] [代码][代码]}[代码][代码] [代码][代码]},[代码]this.cardDataList是我的卡片组,如果直接map来调用drawShareCanvas函数(内部的wx.canvasToTempFilePath),只会绘制第一张卡片,所以我不得不将它改为Promise.resolve()的异步调用形式来遍历数据,而且内部加了一个setTimeout来给生成图片时间,这样对开发不太友好
wx.canvasToTempFilePath的坑wx.canvasToTempFilePath 这个API假如我有N张卡片,需要生成绘制N张CANVAS图,生成N张对应的分享图片,调用这个API就会有问题,只生成第一张图片,后面无法生成,还要预估给一个setTimeout延迟,让它绘制完成,能不能改良下这个API,增加一个异步的。
2018-07-12