123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- const app = require('../../utils/util.js');
- const tool = require('../../utils/tool.js');
- Page({
- data: {
- codeImg: '../../images/ewm.png',
- bj: '../../images/ewmbj.png'
- },
- save() {
- console.log('我调取save了')
- wx.saveImageToPhotosAlbum({
- filePath: this.data.imagePath,
- success(res) {
- wx.showToast({
- title: '图片保存成功!',
- icon: 'none'
- })
- },
- fail: (res) => {
- console.log(res)
- if (res.errMsg === "saveImageToPhotosAlbum:fail auth deny" || res.errMsg === "saveImageToPhotosAlbum:fail:auth denied") {
- this.doAuth()
- }
- }
- })
- },
- // 获取授权
- doAuth() {
- wx.showModal({
- title: '获取授权',
- content: '您是否同意重新授权保存图片',
- cancelText: '不同意',
- confirmText: '同意',
- confirmColor: '#21c0ae',
- success: function (res) {
- if (res.confirm) { // 点击确认
- wx.openSetting({
- success(settingdata) {
- if (settingdata.authSetting["scope.writePhotosAlbum"]) {
- console.log("获取权限成功,再次点击图片保存到相册")
- } else {
- console.log("获取权限失败")
- }
- },
- fail: function (res) {
- console.log(res)
- }
- })
- }
- }
- })
- },
- getEwm() {
- wx.request({
- url: app.globalData.publicUrl + '/wx/member/' + this.data.openid + '/share',
- method: "get",
- success: (res) => {
- if (res.data.code == 0) {
- console.log(res.data.qrcode, '我是获取的二维码')
- this.draw(res.data.qrcode);
- }
- }
- })
- },
- draw(qrcode) {
- wx.downloadFile({
- url: qrcode,
- success: (res) => {
- const ctx = wx.createCanvasContext('myCanvasId');
- ctx.drawImage(this.data.bj, 0, 0, 302, 256); //里面的参数无非就是图片放置的位置即图片的横纵坐标,图片的宽高
- ctx.drawImage(res.tempFilePath, 88, 114, 114, 114);
- ctx.draw();
- setTimeout(() => {
- wx.canvasToTempFilePath({
- canvasId: 'myCanvasId',
- success: (res) => {
- var tempFilePath = res.tempFilePath;
- this.setData({
- imagePath: tempFilePath
- })
- },
- fail: (res) => {
- console.log(res);
- }
- });
- }, 200);
- }
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- tool.openidStatus().then(result => {
- this.setData({
- openid: result[0],
- sessionkey: result[1]
- })
- this.getEwm();
- })
- }
- })
|