我们在开发微信小程序时都会需要用到一些用户权限,如:录像头、录音、保存到相册等等权限
以下是我封装的js,提供给大家使用
checkAnth.js
export default class checkAnth {
constructor() {
}
// 初始化授权获取(授权wxSetting,授权名称)
initcheckAuth(authName, authtype) {
var _that=this
this.checkAuth().then(setRes => {
if (!setRes[authName]) {
wx.authorize({
scope: authName,
success(authRes) {
console.log(authRes, authtype);
},
fail(authErr) {
_that.checkAuth(true, authName, authtype)
}
})
}
})
}
// 检测授权和提示
checkAuth(showModel = false, authName, authtype) {
return new Promise((resolve, reject) => {
wx.getSetting({
success(res) {
if (!res.authSettin