_1 链接复制到【浏览器打开】2 跳出【二维码保存手机相册】3">
当前位置:   article > 正文

生成二维码,保存图片到手机相册,点击复制链接_1 链接复制到【浏览器打开】2 跳出【二维码保存手机相册】3

1 链接复制到【浏览器打开】2 跳出【二维码保存手机相册】3

wxml

<!--pages/share/share.wxml-->
<view class="container share">
  <image src="/icon/fenxiang_beijing.png"></image>
  <view class="share-con">
    <image src="/icon/fenxiang_juxing.png" class="white"></image>
    <view class="a-tit">{{code.title}}</view>
    <canvas class='code' canvas-id='canvas'></canvas>
    <!-- <image src="/icon/erweima.png" class="code"></image> -->
    <!-- <button class="btn" open-type="share" bindtap="save">保存二维码</button> -->
    <view class="my_code">邀请码:{{my_code}}</view>
    <button class="btn" bindtap="save">保存二维码</button>
    <button class="copy-btn" bindtap="copywxtap">复制链接</button>
  </view>
</view>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

js

// pages/share/share.js
var QRCode= require('../../utils/qrcode.js')
const App = getApp();
var qrcode;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    code: {},
    my_code: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      my_code: options.code
    })
    this.my_share();
  },
  my_share(){
    let _this = this;
    App._post_form('user/my_share',{}, function (res) {   
      if(res.code==1){
        qrcode = new QRCode('canvas', {
          text: res.data.share_url,
          width: 120,
          height: 120,
          colorDark: "#000000",
          colorLight: "#ffffff",
          correctLevel: QRCode.CorrectLevel.H,
        });
        // qrcode.makeCode(res.data.share_url);
        _this.setData({
          code: res.data
        })
      }
    });
  },
  
copywxtap: function () {
  let _this = this;
  wx.setClipboardData({
    data: _this.data.code.share_url,
    success: function (res) {
      wx.getClipboardData({
        success: function (res) {
          // console.log(res.data);
        }
      })
    }
  })
},
save: function() {
  wx.showActionSheet({
    itemList: ['保存图片'],
    success: function(res) {
      if (res.tapIndex == 0) {
        qrcode.exportImage(function(path) {
          wx.saveImageToPhotosAlbum({
            filePath: path,
            success(){
            },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('获取权限失败,给出不给权限就无法正常使用的提示')
                  }
                }
              })
            }
          })
        }  
            }
          })
        })
      }     
    }
  })
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that = this;
  var shareObj = {
      title: 'APP分享',
    path: '/pages/share/share?code='+that.data.my_code,        // 默认是当前页面,必须是以‘/’开头的完整路径
    success: function(res){
          if(res.errMsg == 'shareAppMessage:ok'){
      } 
    }
  } 
    return shareObj;
  }
})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签