import { createWxCode } from '~/api/global' Component({ properties: {}, data: { state: false, qrCode: '' }, methods: { async open() { let qrCode = await createWxCode({ page: "pages/index/index", scene: wx.getStorageSync('uid') }) this.setData({ state: true, qrCode }) }, closeMediaBox() { this.setData({ state: false }) }, savePoster() { const query = wx.createSelectorQuery().in(this); query .select('#cavansId') .fields({ node: true, size: true }).exec(async (res) => { console.log(res, 'rrr'); let canvas = res[0].node; const ctx = canvas.getContext('2d'); canvas.width = 646; canvas.height = 959; let pic = canvas.createImage(); pic.src = 'https://reader-wx.ai160.com/images/reader/pay/shareBg.jpg' pic.onload = () => { ctx.drawImage(pic, 0, 0, 646, 959); let pl = canvas.createImage(); pl.src = this.data.qrCode pl.onload = () => { ctx.drawImage(pl, 29, 756, 170, 170) console.log(canvas, 'canvas'); wx.canvasToTempFilePath({ canvas: canvas, success(imgRes) { wx.saveImageToPhotosAlbum({ filePath: imgRes.tempFilePath, success() { wx.showToast({ title: '保存成功', icon: 'none' }) }, fail(rrr) { console.log(rrr, 'rrr'); } }) }, fail(failMsg) { console.log(failMsg, 'eqweqwe'); } }) } } }) } } })