//微信对应的权限
scope.userInfo wx.getUserInfo 用户信息
scope.userLocation wx.getLocation, wx.chooseLocation 地理位置
scope.userLocationBackground wx.startLocationUpdateBackground 后台定位
scope.address wx.chooseAddress 通讯地址
scope.invoiceTitle wx.chooseInvoiceTitle 发票抬头
scope.invoice wx.chooseInvoice 获取发票
scope.werun wx.getWeRunData 微信运动步数
scope.record wx.startRecord 录音功能
scope.writePhotosAlbum wx.saveImageToPhotosAlbum, wx.saveVideoToPhotosAlbum 保存到相册
scope.camera camera 组件 摄像头
chooseAddress: function(){
// 获取用户是否开启用户
wx.getSetting({
success(res) {
//唤醒是否授权
if (!res.authSetting['scope.address']) {
wx.chooseAddress({
success(res) {
//调用成功若不授权则提示授权
},
fail(res){
wx.showModal({
title: '请您授权通讯地址',
content: '如需正常使用此小程序功能,请您按确定并在设置页面授权通讯地址',
confirmText: '确定',
success: res => {
if (res.confirm) {
wx.openSetting({
success: function (res) {
if (res.authSetting['scope.address']) { //设置允许获取摄像头
console.log('设置允许获取微信发票抬头服务')
wx.showToast({
title: '授权成功',
icon: 'success',
duration: 1000
});
} else { //不允许
wx.showToast({
title: '授权失败',
icon: 'none',
duration: 1000
})
}
}
})
} else { //取消
wx.showToast({
title: '授权失败',
icon: 'none',
duration: 1000
})
}
}
})
}
});
} else {
wx.chooseAddress({
success(res) {
console.log("选择地址", res);
thePage.setData({
mail_contacts: res.userName,
mail_contacts_number: res.telNumber,
mail_address: res.detailInfo,
mail_provinces: res.provinceName + res.cityName
});
let data = {};
data.mail_contacts = thePage.data.mail_contacts;
data.mail_contacts_number = thePage.data.mail_contacts_number;
data.mail_address = thePage.data.mail_address;
data.mail_provinces = thePage.data.mail_provinces;
thePage.saveNews(data);
}
});
}
}
})
}
这是本人第一次在csdn写文章,也是平时工作中需要处理的问题。
以便以后遇到类似问题自己和大家快捷解决问题。