在wepy里使用进行小程序页面授权,里面包含了用户点击取消的重新授权方案:

//auth.js
/*
* @Author: Porco_Mar
* @Date:   2018-04-11 15:49:55
* @Last Modified by:   Porco_Mar
* @Last Modified time: 2018-04-18 10:43:36
*/
import wepy from 'wepy'export const _timer = (context) => {return new Promise((resolve, reject) => {let _timer = null;clearInterval(_timer);_timer = setInterval(() =>{resolve(author(context))},500)context.data.timer = _timer; })
}
export const author = (context) => {return new Promise((resolve,reject) => {var that = context;wepy.getUserInfo({success: (res) =>{var userInfo = res.userInfo;that.data.userInfo = userInfo;resolve(res.userInfo)},fail: (res) =>{console.log('.......getUserInfo fail.........')clearInterval(context.data.timer)wepy.showModal({title: '警告',content: '您点击了拒绝授权,将无法正常显示个人信息,点击确定重新获取授权。',success:function(res){if (res.confirm) {wepy.openSetting({success: (res) => {if (res.authSetting["scope.userInfo"] || res.authSetting["scope.userLocation"]){如果用户重新同意了授权登录wepy.getUserInfo({success:function(res){resolve(res.userInfo)that.$parent.globalData.userInfo = res.userInfo;}})}},fail: function(res){resolve({'avatarUrl':'','nickName':'翠花'})console.log('没有选择授权')}})               }else{console.log('还是不同意授权')}}})},complete: function (res){}})})
}let isBoolen = true;
export const location = (context) => {return new Promise((resolve, reject) => {if(context.$parent.globalData.location != null){resolve(context.$parent.globalData.location)console.log('已获取location')}else{console.log('没有获取到location ')wepy.getSetting({success(res) {console.log(res)if(!res.authSetting['scope.userLocation']) {wx.showModal({title: '温馨提醒',content: '需要获取您的地理位置才能使用小程序',cancelText: '不使用',confirmText: '获取位置',success: function(res) {if(res.confirm) {getLocation(context).then((res) => {// console.log(res)if (res.code == 1){if(isBoolen){ //第一次不执行isBoolen = false;}else{wepy.openSetting({  //  点击自带取消定位健会调用这个面板success: (res) => {if (res.authSetting["scope.userLocation"]){如果用户在面板重新同意了授权地理位置console.log('--有了scope.userLocation--')resolve(getLocation(context)) //点击面板后再次调用getLocation返回参数}},fail: function(res){console.log('--没有scope.userLocation--')}})}}else{resolve(getLocation(context))}})} else if(res.cancel) {//resolve(getLocation(context))//不做任何操作}}})}                    }})}})
}export const getLocation = (context) => {return new Promise((resolve, reject) => {wx.getLocation({type: 'wgs84',success: function(res) {var latitude = res.latitudevar longitude = res.longitudevar speed = res.speedvar accuracy = res.accuracycontext.$parent.globalData.location = {'code': 0, 'latitude':latitude, 'longitude':longitude, 'speed':speed, 'accuracy':accuracy}resolve(context.$parent.globalData.location)},fail: function(res){resolve({'code': 1, 'latitude':'', 'longitude':'', 'speed':'', 'accuracy':''})}})})
}// index.wepy
import wepy from 'wepy'
import {_timer, author, location} from '../utils/auth'onShow() {let globalDt = this.$parent.globalDataif(globalDt.userInfo.nickName && globalDt.userInfo.avatarUrl){this.userInfo = globalDt.userInfo;}else{this.getValue(); // 获取userInfo}if(globalDt.location === null){this.getLt(this); // 获取地理位置}else{console.log('当前页面获取过location了')//console.log(globalDt.location)this.location = globalDt.location;}}async getValue () {const datam = await _timer(this)console.log(datam)this.userInfo = datam;this.$apply();}async getLt (context) {const local = await location(context)console.log(local)this.location = local;this.$apply()}

小程序 wepy 用户取消授权以及取消获取地理位置后的处理方法相关推荐

  1. 微信小程序,用户拒绝授权后重新授权;uni-app小程序,用户拒绝授权后点击无效;重新进入后拉起位置授权框;

    问题:当用户第一次进入小程序,点击授权按钮后,点了拒绝,再次点击不会出现授权页面,只有再次进入小程序的时候,才会出发请求授权 . 案例: 假如我们获取微信位置,第一次点击的时候弹起授权,用户点击的拒绝 ...

  2. 微信小程序判断用户是否授权定位

    当授权地理位置时候用户点击了拒绝之后的流程图 点击允许授权则获取当前定位信息进行一些业务操作 //在uniapp/小程序全局文件中app.vue/main.js onLoad(){this.check ...

  3. 微信小程序实现用户登录授权java代码

    1.微信官方文档 auth.code2Session | 微信开放文档 2.我们来实现这个登录功能, 直接上完整代码  controller <!-- 工具类-JSONUtil --> & ...

  4. uniapp - 编译微信小程序项目的微信授权登录、获取微信手机号登录、最新版微信直接登录、手机与验证码登录的示例源码(适用于 uniapp 微信小程序项目,源代码直接开箱即用)超级详细的代码及注释

    效果图 uniapp 项目编译微信小程序,一些常见的登录方式及源代码,示例代码干净整洁无BUG拿来即用. 本文示例实现了 uniapp 微信小程序项目的登录功能,包含微信授权登录.获取微信手机号登录. ...

  5. 微信小程序使用腾讯定位服务api获取经纬度后调取导航功能

    腾讯定位服务官网申请key 申请key: https://lbs.qq.com/dev/console/key/add 签名效验文档: https://lbs.qq.com/FAQ/server_fa ...

  6. 微信小程序发起用户授权

    第一步 先通过wx.getSetting()获取用户的当前设置,返回值中只会出现小程序已经向用户请求过的权限. 第二步 判断用户是否已经授权某项设置, 如果某项设置(如:scope.userLocat ...

  7. 微信小程序如何进行登录授权和获取用户信息

    微信小程序如何进行登录授权和获取用户信息

  8. 【微信小程序】用户授权及getUserProfile接口使用

    小程序登录.用户信息相关接口调整说明 为优化用户的使用体验,平台将进行以下调整: 1,2021年2月23日起,若小程序已在微信开放平台进行绑定,则通过wx.login接口获取的登录凭证可直接换取un ...

  9. 微信小程序通过web-view网页授权获取用户公众号OpenID

    小程序中实现网页授权获取微信公众号OpenID 1.准备工作 2.应用场景说明 3.实现步骤 结语 1.准备工作 第一步: 通过该地址https://mp.weixin.qq.com/debug/cg ...

最新文章

  1. “参数”vs“参数”[重复]
  2. python代码编写规范有哪些_Python代码编写规范(适合于小团体,低强度)
  3. Ayoub's function CodeForces - 1301C(组合数学)
  4. MSP430G2553 移植 Contiki RTOS 实时操作系统
  5. RHEL6 grub修复
  6. 题目1003:A+B(字符串转数字)
  7. java 数组大数乘法_java – 在数组中查找3个数字的最大乘积
  8. LeetCode刷题(15)
  9. winform C#中Byte与String的转换方法,相互转换
  10. ad15的stc元件库_AltiumDesigner常用元件库
  11. 分享一个Xshell注册码
  12. 在Ubuntu18上使用fusedav挂载城通网盘webdav
  13. 教学实验平台之三极管放大特性测试
  14. php 图片生成vr_vr全景技术难吗?vr全景技术原理和应用讲解
  15. Qt ‘tr‘ was not declared in this scop
  16. 机器学习之模拟退火算法
  17. evict和clear
  18. A Multi-task Ensemble Framework for Emotion, Sentiment and Intensity Prediction
  19. 【Flutter 问题系列第 22 篇】在 Flutter 中如何截取屏幕并显示到页面中,以及如何将截图保存到相册
  20. 雨课堂研究生压力应对与健康心理期末考试,学堂云

热门文章

  1. 苹果手机各版本分辨率
  2. python后端开发学习重点
  3. go编译mips程序的方法(君正M150平台)
  4. 大数据可视化展示工具:Grafana简介
  5. VR中的动画就是这么玩哒
  6. 【Linux】日志管理及日志轮询
  7. 面试官让我滚,我用了20分钟,狠狠装了一回逼!
  8. 对​ e 妹儿公司的字符串处理
  9. 【疑】checkpoint防火墙双链路负载均衡无法配置权重问题
  10. 关于行框盒子与vertical-align(一)