123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- const app = require('../../utils/util.js');
- const tool = require('../../utils/tool.js');
- Page({
- data: {
- codeImg: '../../images/ewm.png',
- bj: '../../images/ewmbj.jpg'
- },
- 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() {
- tool.isFinishInfo().then(result2 => {
- wx.request({
- url: app.globalData.publicUrl + '/wx/mpuser/wxeef6678b92b6c856/qrCode',
- method: "get",
- data: {
- memberId:result2.id
- },
- success: (res) => {
- console.log(res)
- this.draw(res.data);
- },
- fail() {
- wx.hideLoading();
- }
- })
- }).catch(err => {
- // wx.showLoading();
- wx.request({
- url: app.globalData.publicUrl + '/wx/mpuser/wxeef6678b92b6c856/qrCode',
- method: "get",
- data: {
- memberId:0
- },
- success: (res) => {
- console.log(res)
- this.draw(res.data);
- },
- fail() {
- wx.hideLoading();
- }
- })
- })
- },
- draw(qrcode) {
- wx.downloadFile({
- url: qrcode,
- success: (res) => {
- const ctx = wx.createCanvasContext('myCanvasId');
- ctx.drawImage(this.data.bj, 0, 0, 355, 392); //里面的参数无非就是图片放置的位置即图片的横纵坐标,图片的宽高
- ctx.drawImage(res.tempFilePath, 96, 110, 148, 148);
- let strArr = ['谁没对象给谁','码上有对象'];
- ctx.setFillStyle("#999");
- ctx.setFontSize(18); //字大小
- ctx.setTextAlign('center'); //是否居中显示,参考点画布中线
- // let leftPositionAarr = []
- for (let i = 0; i < strArr.length; i++) {
- console.log(i);
- ctx.fillText(strArr[i], 170,300 + i * 30);
- }
- ctx.draw();
- 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);
- }
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- // getInfos() {
- // wx.request({
- // url: app.globalData.publicUrl + '/wx/member/' + this.data.openid + '/info',
- // method: "get",
- // success: (res) => {
- // console.log(res, '我是获取的信息')
- // if (res.data.code == 0) {
- // // this.setData({
- // // myInfo: res.data.info
- // // })
- // this.getEwm(res.data.info.id);
- // }
- // }
- // })
- // },
- onLoad: function (options) {
- wx.showLoading();
- tool.openidStatus().then(result => {
- this.setData({
- openid: result[0],
- sessionkey: result[1]
- })
- this.getEwm();
- })
- }
- })
|