微信小程序 授权相册完整流程(拒绝后,再次打开设置授权)

微信小程序 授权相册完整流程(拒绝后,再次打开设置授权)_第1张图片

// 按钮

  
  

// 保存海报到相册
savePoster(){
  let that = this
  wx.getSetting({
    success(res) {
      if (res.authSetting['scope.writePhotosAlbum']) {
        that.saveImg();
      } 
      else if (res.authSetting['scope.writePhotosAlbum'] === undefined) {
        wx.authorize({
          scope: 'scope.writePhotosAlbum',
          success() {
            that.saveImg();
          },
          fail() {
            that.authConfirm()
          }
        })
      } 
      else {
        that.authConfirm()
      }
    }
  })
},
// 授权拒绝后,再次授权提示弹窗
authConfirm(){
  let that = this
  wx.showModal({
    content: '检测到您没打开保存图片权限,是否去设置打开?',
    confirmText: "确认",
    cancelText: "取消",
    success: function (res) {
      if (res.confirm) {
        wx.openSetting({
          success(res) {
            if (res.authSetting['scope.writePhotosAlbum']) {
              that.saveImg();
            }
            else {
              wx.showToast({
                title: '您没有授权,无法保存到相册',
                icon: 'none'
              })
            }
          }
        })
      } else {
        wx.showToast({
          title: '您没有授权,无法保存到相册',
          icon: 'none'
        })
      }
    }
  });
},
// 图片保存到本地
saveImg(){
  wx.downloadFile({
    url: 'https://www.oneh5.com/thq/FLH/backend_api/api/../images/upload/20190111/qj.jpg',//this.data.posterImg,
    success: function (res) {
      wx.saveImageToPhotosAlbum({
        filePath: res.tempFilePath,
        success: function (data) {
          wx.showToast({
            title: '保存成功',
            icon: 'none'
          })
        }
      })
    }
  })
}

你可能感兴趣的:(微信小程序 授权相册完整流程(拒绝后,再次打开设置授权))