1 其他授权与授权设置面板
https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html
在wxml中
<button bind:tap="onAuthLocation">授权位置</button>
在 app.json中
{
"pages": [
"pages/index/index",
"pages/logs/logs",
"pages/movie/movie",
"pages/about/about"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle": "black",
"backgroundColor": "#ff00ff",
"enablePullDownRefresh": true
},
"tabBar": {
"list": [
{
"text": "首页",
"pagePath": "pages/index/index",
"selectedIconPath": "common/pj.png",
"iconPath": "common/cake.png"
},
{
"text": "日志",
"pagePath": "pages/logs/logs",
"iconPath": "common/juli.png",
"selectedIconPath": "common/sng.png"
}
],
"color": "#707070",
"selectedColor": "#1296db"
},
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
}
}
在wxjs中
onAuthLocation:function(){
wx.authorize({
scope:"scope.userLocation",
success:msg=>{
console.log(msg,"location succ")
},
fail:e=>{
console.log(e,"location fail")
}
})
}
scope.userLocation 获取用户当前的定位信息
scope.userLocation 地理位置
scope.address 通讯地址
scope.werun 微信运动步数
scope.record 录音功能
scope.writePhotosAlbum 保存到相册
scope.camera 获取用户的照相权限
*******************************************************************************************************************************
获取定位信息
在wxml中
<button bind:tap="onGetLocation">授权位置位置</button>
在wxjs中
onGetLocation:function(){
wx.authorize({
scope:"scope.userLocation",
success:msg=>{//成功获取到定位权限
console.log(msg,"scope.userLocation succ")
wx.getLocation({ //获取定位信息
success:function(info){
console.log(info,"info")
},
fail:function(e){
console.log(e,"e")
}
})
},
fail:e=>{
console.log(e,"scope.userLocation fail")
}
})
}
****************************************************************************************
获取授权设置信息
1 在wxml里面
<button bind:tap="onGetSetting">获取授权信息</button>
2 在wxjs里面 获取用户配置信息 是否有开启定位权限, 个人信息权限
onGetSetting:function(){
wx.getSetting({
success:msg=>{
console.log(msg,"succ")
console.log(msg.authSetting,"succ")
},
fail:e=>{
console.log(e,"fail")
}
})
}
***************************************************************************************************
手动设置,必须有某个权限,用户又不允许的情况下,
1wxml里面
<button bind:tap="onGoToSetting">去到设置页面</button>
2 wxjs里面 只能获取已经请求过的设置
onGoToSetting:function(){
wx.openSetting({
success:msg=>{
console.log(msg,"设置完成")
},
})
}