const app = require('../../utils/util.js'); Page({ data: { codeImg: '../../images/ewm.png', bj: '../../images/ewmbj.png' }, save() { wx.saveImageToPhotosAlbum({ filePath: this.data.imagePath, success:(data)=> { console.log(data) let fileMgr = wx.getFileSystemManager() fileMgr.unlink({ filePath: this.data.imagePath, success() { wx.showToast({ title: '已保存', duration: 2000 }) } }) }, fail(err) { if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg === "saveImageToPhotosAlbum:fail auth deny" || err.errMsg === "saveImageToPhotosAlbum:fail authorize no response") { wx.showModal({ title: '提示', content: '需要您授权保存相册', showCancel: false, success: modalSuccess => { wx.openSetting({ success(settingdata) { if (settingdata.authSetting['scope.writePhotosAlbum']) { console.log('获取权限成功,给出再次点击图片保存到相册的提示。') } else { console.log('获取权限失败,给出不给权限就无法正常使用的提示') } } }) } }) } } }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { wx.showLoading(); console.log('1111111') const ctx = wx.createCanvasContext('myCanvasId'); ctx.drawImage(this.data.bj, 0, 0, 302, 256); //里面的参数无非就是图片放置的位置即图片的横纵坐标,图片的宽高 ctx.drawImage(this.data.codeImg, 88, 114, 114, 114); ctx.draw(); this.save(); setTimeout(() => { wx.canvasToTempFilePath({ canvasId: 'myCanvasId', success: (res) => { var tempFilePath = res.tempFilePath; this.setData({ imagePath: tempFilePath }) wx.hideLoading(); }, fail: (res) => { console.log(res); wx.hideLoading(); } }); }, 200); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, onUnload: function () { }, onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })