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

略,官网链接: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
              })
            }
          }
        })
      }
    })
  },
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 每天的学习记录,可能有的地方写的不对,因为刚学,以后发现错的话会回来改掉整体流程 https://develope...
    有点健忘阅读 4,771评论 0 7
  • 大家好,我是IT修真院深圳分院第07期学员,一枚正直善良的web程序员。 今天给大家分享一下,修真院官网 JS-1...
    SIRengar阅读 1,285评论 0 0
  • 诗前小序:2006年7月16日,本人因工作需要从一家医院调到另一家附属医院。今年马上要退居二线,面临去留两难选择。...
    阳学风阅读 402评论 2 4
  • 春天从孩子们的身上产生,先染了他们的课桌,然后漫出窗子,染了山川。和孩子们在一起,就是和春天在一起。我想起了一位诗...
    小青童画阅读 1,202评论 42 55