发布到线上的openSetting界面,没有权限开关
开发工具、开发工具生成预览二维码,手机扫码后查看都有权限开关
// 引导用户手动开启权限
showPermissionGuide() {
wx.showModal({
title: '权限申请',
content: '需要相册权限才能保存图片,请前往设置开启',
success: (res) => {
if (res.confirm) {
// 打开系统设置页
wx.openSetting()
}
},
complete: () => {}
})
},
下载功能,当用户没有权限的时候弹出框模态框,然后如果用户点击“确定”,就openSetting(),没有开关按钮
async downloadPicture() {
this.setData({
downloadLoading: true
})
//判断用户是否授权存储到相册
const hasPermission = await this.checkPhotoAlbumPermission()
if (hasPermission === true) {
console.log("有权限")
this.downloadAvatar() // 执行保存操作
} else {
console.log("没有权限,请求权限")
// 未授权时请求权限
wx.authorize({
scope: 'scope.writePhotosAlbum',
success: () => this.downloadAvatar(),
fail: () => {
this.hideDownloadLoading()
this.showPermissionGuide()
}
})
}
},

这题我会解,在审核发布的时候要选择采集用户信息
async downloadPicture() {
this.setData({
downloadLoading: true
})
//判断用户是否授权存储到相册
const hasPermission = await this.checkPhotoAlbumPermission()
if (hasPermission === true) {
console.log("有权限")
this.downloadAvatar() // 执行保存操作
} else {
console.log("没有权限,请求权限")
// 未授权时请求权限
wx.authorize({
scope: 'scope.writePhotosAlbum',
success: () => this.downloadAvatar(),
fail: () => {
this.hideDownloadLoading()
this.showPermissionGuide()
}
})
}
},
需要你先授权这个权限,才会在对应用户的小程序设置中出现对应权限。