微信小程序之用户授权设置信息

略,官网链接:https://developers.weixin.qq.com/miniprogram/dev/api/AuthSetting.html


目录

一、授权地理位置

二、授权通讯地址

三、授权发票抬头

四、授权获取发票

五、授权微信运动步数

六、授权保存到相册

七、授权摄像头


二、授权通讯地址


  chooseAddress: function (e) {
    ut.log("选择联系人信息");
    var that = this
    //一、判断用户是否开启权限
    wx.getSetting({
      success: function (res) {
        if (res.authSetting["scope.address"] == true) {
          console.log("用户已开启地址访问");
          wx.chooseAddress({
            success(res) {
              that.setData({
                addressShow: true,
                name: res.userName,
                phone_num: res.telNumber,
                detail_address: res.provinceName + res.cityName + res.countyName + res.detailInfo ,
                allAddress: res.userName + "    " + res.telNumber + "    " + res.provinceName + res.cityName + res.countyName + res.detailInfo
              })
            }
          })
        } else {
          console.log("用户未开启地址访问");
          var status = res.authSetting["scope.address"]
          if (typeof (status) == "undefined") {
            console.log("--------未定义------");
            wx.chooseAddress({
              success(res) {
                that.setData({
                  addressShow: true,
                  name: res.userName,
                  phone_num: res.telNumber,
                  detail_address: res.provinceName + res.cityName + res.countyName + res.detailInfo,
                  allAddress: res.userName + "    " + res.telNumber + "    " + res.provinceName + res.cityName + res.countyName + res.detailInfo
                })
              }
            })
          } else {
            wx.showModal({
              title: '地址访问授权',
              content: '地址访问授权未开启,无法完成操作',
              confirmText: '开启授权',
              confirmColor: '#345391',
              cancelText: '仍然拒绝',
              cancelColor: '#999999',
              success: function (res) {
                if (res.confirm) {
                  wx.openSetting({
                  })
                }
                if (res.cancel) {
                  wx.showModal({
                    title: '操作失败',
                    content: '地址访问授权未开启,操作失败',
                    confirmText: '太遗憾了',
                    confirmColor: '#345391',
                    showCancel: false
                  })
                }
              }
            })
          }
        }
      }
    })

六、授权保存到相册

boolean scope.writePhotosAlbum

是否授权保存到相册 wx.saveImageToPhotosAlbum, wx.saveVideoToPhotosAlbum
相关代码:

/**
   * 保存到相册
   */
  savePhone: function() {
    var that = this
    //一、判断用户是否开启权限
    wx.getSetting({
      success: function(res) {
        if (res.authSetting["scope.writePhotosAlbum"] == true) {
          console.log("用户已开启相册访问");
        } else {
          console.log("用户未开启相册访问");
          var status = res.authSetting["scope.writePhotosAlbum"]
          if (typeof(status) == "undefined") {
            console.log("--------未定义------");
          } else {
            wx.showModal({
              title: '相册访问授权',
              content: '相册访问授权未开启,无法完成操作',
              confirmText: '开启授权',
              confirmColor: '#345391',
              cancelText: '仍然拒绝',
              cancelColor: '#999999',
              success: function(res) {
                if (res.confirm) {
                  wx.openSetting({
                  })
                }
                if (res.cancel) {
                  wx.showModal({
                    title: '操作失败',
                    content: '相册访问授权未开启,操作失败',
                    confirmText: '太遗憾了',
                    confirmColor: '#345391',
                    showCancel: false
                  })
                }
              }
            })
          }
        }
      } 
    })
    //二、保存图片到相册
    wx.saveImageToPhotosAlbum({
      filePath: that.data.prurl,
      success(res) {
        wx.showModal({
          content: '图片已保存到相册,赶紧晒一下吧~',
          showCancel: false,
          confirmText: '好哒',
          confirmColor: '#72B9C3',
          success: function(res) {
            if (res.confirm) {
              console.log('用户点击确定');
              that.setData({
                canvasHidden: true
              })
            }
          }
        })
      }
    })
  },

你可能感兴趣的:(微信小程序之用户授权设置信息)