现在老板一般都需要线上推广功能,通过给用户好处来刺激用户裂变分销,这就需要我们给用户生成专属的推广海报 因为小程序的用户uid是唯一的并且是不变的,所以我们后台大哥就以用户的uid作为生成专属二维码的图片名称,这里我们用canvas来绘制海报,废话不多说,上前端代码: wxml:view class=’box’ canvas canvas-id=’post’ style=’width:750rpx;height:1334rpx;’/canvas view style=’width:100%;text-align:center;color:#cc181d;font-size:24rpx;margin-top:15rpx;’这是您的专属二维码,将图片保存至手机后发朋友圈推广/view button class=’btn’ bindtap=’save’保存图片/button/viewjs:data: { src1: ‘https://www.qiaolibeilang.com/qrcode/’, src3: ‘.png’, }, onLoad: function (options) { var that = this var winWidth = wx.getSystemInfoSync().windowWidth;// 获取当前设备的可视宽度 var winHeight = wx.getSystemInfoSync().windowHeight;// 获取当前设备的可视高度 that.setData({ winWidth: winWidth, winHeight: winHeight }) let promise1 = new Promise(function (resolve, reject) { wx.getImageInfo({ src: ‘https://www.qiaolibeilang.com//public/uploads/images/20180809/free.png’, success: function (res) { resolve(res); } }) }); let promise2 = new Promise(function (resolve, reject) { var uid = wx.getStorageSync(‘uid’) console.log(uid) wx.getImageInfo({ src: that.data.src1 + uid + that.data.src3, success: function (res) { resolve(res); } }) }); Promise.all([ promise1, promise2 ]).then(res = { var that = this var winWidth = wx.getSystemInfoSync().windowWidth;// 获取当前设备的可视宽度 var winHeight = wx.getSystemInfoSync().windowHeight;// 获取当前设备的可视高度 that.setData({ winWidth: winWidth, winHeight: winHeight }) console.log(winWidth) console.log(winHeight) const ctx = wx.createCanvasContext(‘post’) ctx.setFillStyle(‘red’) ctx.drawImage(res[0].path, 0, 0, that.data.winWidth, that.data.winWidth * 1.778) ctx.drawImage(res[1].path, that.data.winWidth – 160, that.data.winWidth * 1.778 – 105, 80, 80) console.log(res) ctx.draw(true) }) }, save: function (e) { var that = this wx.canvasToTempFilePath({ x: 0, y: 0, canvasId: ‘post’, success: function (res) { // 获得图片临时路径 console.log(res.tempFilePath) wx.saveImageToPhotosAlbum({ filePath: res.tempFilePath, success(res) { console.log(res); wx.showToast({ title: ‘保存成功’, }); }, fail(res) { console.log(“保存图片:fail”); console.log(res); } }) } }) },wxss代码就不写了,每个人风格都不一样,我的最终效果是就是这样,二维码是每个人单独的,剩下的就让后台去处理后续的业务逻辑就好了
微信小程序之生成专属推广海报
未经允许不得转载:E企盈小程序开发-热线:4006-838-530 » 微信小程序之生成专属推广海报
相关推荐
数据恢复软件(二):用C++重写恢复B乐都县E企盈小程序MP位图文件的小程序
公众号再次改版高坪区E企盈小程序小程序又多了一个入口
微信小程序加载图片时,湘桥区E企盈小程序先拉长,再恢复正常
转:(很有用)有多个按钮,点击一个变色,点击另吴中区E企盈小程序一个变色,原来的恢复颜色的方法
第12课微信小程序Component构造器自道里区E企盈小程序定义组件:
导航中的南海区E企盈小程序小竖线总结
小程序:after实现德格县E企盈小程序1px纵向分割线
汉沽区E企盈小程序企业微信内测朋友圈和客户群功能:小程序C位出道!
小程序运行加载密山市E企盈小程序机制
小程通城县E企盈小程序序中间有字的分隔线
公众号和小程序可以同名了名称支持同主体复盘锦E企盈小程序用
微信小程序修改主潜江市E企盈小程序体信息
最新评论
独特万商直播系统,直播系统技术开发公司
万商直播系统开发公司
优秀的团队,万商直播管理系统
不错的小程序案例
优秀的团队,不错的服务!
讲的很好
主播长的帅气
好系统好服务