在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. radio 微信小程序 点击取消_微信小程序如何实现radio单选框单击打勾和取消

    前端使用input 来写radio,小程序使用radio标签 也可以使用单标签 1.自定义radio样式. wx默认的是真的丑 /* 单选框样式 */ /* 初始样式 */ radio .wx-rad ...

  2. 微信小程序退出登录取消授权

    退出登录 首先,最近因为要做微信小程序,所以了解了一下相关文档知识. 微信小程序退出登录功能想要取消用户授权这个在微信开发文档上有写,是不能取消的. 以下是截图 其次,根据自己项目经历,发现在获取地理 ...

  3. 微信小程序获取用户信息“授权失败”场景的处理

    很多的时候我们在处理小程序功能的时候需要用户获取用户信息,但是呢为了信息安全,用户不授权导致授权失败场景:但是小程序第二次不在启动授权信息弹层,为了用户体验,可以用以下方式处理: function i ...

  4. 微信小程序开发工具取消用户授权

    仅给和我一样粗心的人提示一下,大神不要见怪. 之前没仔细研究小程序开发工具,对界面不熟悉.开发中对小程序做了个授权,然后想取消程序的授权,在手机上可以直接操作,但是在开发工具上不行. 其实,直接把缓存 ...

  5. 微信小程序点击按钮弹出弹窗_转载 | 广东大学生就业创业微信小程序操作流程详解(一)...

    广东大学生就业创业微信小程序 操作流程详解(一) 转眼来到10月,炎炎夏日也阻挡不了青春的忙碌,同学萌走出校园,迈向社会. 在这段时间,同学们不仅要准备毕业论文,应对毕业答辩,还需要兼顾各种毕业手续的 ...

  6. 快速入门 WePY 小程序

    一.WePY介绍 WePY 是 腾讯 参考了Vue 等框架对原生小程序进行再次封装的框架,更贴近于 MVVM 架构模式, 并支持ES6/7的一些新特性. 二.WePY 使用 1.WePY的安装或更新都 ...

  7. 微信小程序跳过第三方的_微信小程序怎么解除第三方授权?

    平时我们用使用一个新的小程序时,通常都会弹出一些第三方授权的窗口,要授权成功才能正常使用小程序.而其中或多或少会涉及一些个人隐私信息,如果我们不需要再使用这些小程序,想要取消授权应该怎么做呢? 一.在 ...

  8. 微信小程序点击弹出输入框

    微信小程序点击弹出输入框 第一次写博客,我决定不要太old school. let's get it!最近在学习微信开发,刚接触到微信小程序,自己尝试着做了一个简单的小程序,过程中发现类似web开发中 ...

  9. 脱离微信运行环境,小程序如何实现微信授权登录

    据微信 2021 年财报披露,微信小程序 DAU 已经突破 5 亿,微信生态从业者超过 3000 万.阿拉丁研究院基于小程序数据库和公开资料测算,2022 年 H1 期间,微信.支付宝.抖音.快手等多 ...

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

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

最新文章

  1. 微服务2017年度报告出炉:4大客户画像,15%传统企业已领跑
  2. 服务器系统检测报告自动生成,生成allure测试报告之后,服务器端口无法访问查看生成的report,可能是这样引起的。...
  3. .NET项目是否有必要升级到.NET 3.5 + VS 2008
  4. php+gd库的源码安装
  5. pd17虚拟机启动器怎么生成?快来看看吧
  6. 如何设置dedecms自定义表单必填项?
  7. object转换成Integer
  8. js判断字符在另一个字符串中出现次数
  9. Scala对象 转Json字符串
  10. HTML页面在iPhone中电话号码自动检测带来的布局问题
  11. php股票预警,很准的股票底部预警选股指标 通达信公式(附图)
  12. 如何通过给MM修电脑培养感情
  13. android fsck_msdos 分析(二)
  14. 录播服务器系统调试内容,高清录播服务器系统选择注意事项
  15. 【SSM框架】MyBatis
  16. rviz点云渲染卡顿问题
  17. C++ lazy evaluation(延迟计算或惰性求值)介绍
  18. 【毕业设计】深度学习卫星遥感图像检测与识别 -opencv python 目标检测
  19. matlab批量下载网页文件
  20. Unity3d导出的安卓包如何在真机上看log打印

热门文章

  1. 关于gcc的一点小人性化提示
  2. javascript 高级编程系列 - 创建对象
  3. Oracle学习之路-- 案例分析实现行列转换的几种方式
  4. 仿写京东商品详情页面
  5. 谈谈Runtime类中的freeMemory,totalMemory,maxMemory等几个方法
  6. Linux系统常用工具集
  7. DB2 开发系列 从入门开始--概述
  8. Mac原生浏览器Safari,那些你都不知道的使用技巧
  9. Dockerfile 学习:Docker Alpine PHP 安装扩展
  10. Swift编程-闭包Closure