canvasInit(){
const ctx = uni.createCanvasContext('canvas', this);
return new Promise(async(r,j)=>{
try{
await this.drawBg(ctx)
ctx.draw();
r();
}catch(err){
j();
}
})
},
drawBg(ctx){
return new Promise(async(r,j)=>{
ctx.save();
ctx.beginPath();
let cWidth = uni.upx2px(750)
let cHeight = uni.upx2px(1362)
let bgImgUrl = await downLoadBgImg(`${imgHost}/save-bg.png`)
ctx.drawImage(bgImgUrl,0,0,cWidth,cHeight)
ctx.closePath();
ctx.restore();
r();
})
}
export function downLoadBgImg (url) {
return new Promise((r,j) => {
uni.downloadFile({
url,
success : res => {
if (res.statusCode === 200) {
r(res.tempFilePath);
return;
};
j('依赖文件下载失败');
},
fail : err => {
j(err)
}
})
})
}