摘要:在里使用进行小程序页面授权,里面包含了用户点击取消的重新授权方案警告您点击了拒绝授权将无法正常显示个人信息点击确定重新获取授权。
在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.latitude
var longitude = res.longitude
var speed = res.speed
var accuracy = res.accuracy
context.$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.globalData
if(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()
}
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/94362.html
摘要:在里使用进行小程序页面授权,里面包含了用户点击取消的重新授权方案警告您点击了拒绝授权将无法正常显示个人信息点击确定重新获取授权。 在wepy里使用进行小程序页面授权,里面包含了用户点击取消的重新授权方案: //auth.js /* * @Author: Porco_Mar * @Date: 2018-04-11 15:49:55 * @Last Modified by: Por...
摘要:除官方外的参考文章微信小程序实例创建下发模板消息实例手把手教你开发微信小程序之模版消息开发教你突破小程序模板消息的推送限制获取用户信息接口的废弃问题接口是获取用户信息昵称,头像等的接口,在官方文档上写是即将废弃。 ----------------更新-------------- 2018年10月10日官网3个接口废弃的通知: 1、分享监听接口分享消息给好友时,开发者将无法从callba...
摘要:大家好,我是平头哥联盟的首席填坑官苏南,今天要给大家分享的是最近公司做的一个小程序项目,过程中的一些好的总结和遇到的坑,希望能给其他攻城狮带来些许便利,更希望能做完之后老板给你加薪今天是中秋节的第一天,假日的清晨莫名的醒的特别早,不知道为什 showImg(https://segmentfault.com/img/bVbhAYf?w=1278&h=722); 大家好,我是@IT·平...
摘要:功能三滴滴费用计算古人云细节决定成败,一个良好的微信小程序往往就是一些细节打动人心,居然是模仿,虽做不到百分百,至少还是很希望一模一样。 最近时常感叹道:时间总是那么的快,转瞬即逝。对于像我这种刚入门的小生来讲,技术每天都在更新,框架也层出不穷,有时候还没弄懂这个知识大牛们又推出了更好的技术。当然学习好的技术也是十分重要的。但是在学习之后怎样才能够得到自己想要的呢,一个好的建议便是静...
阅读 2883·2021-10-14 09:42
阅读 962·2021-10-11 10:57
阅读 844·2019-08-30 15:54
阅读 1994·2019-08-30 13:50
阅读 1755·2019-08-30 11:19
阅读 1094·2019-08-29 12:38
阅读 1516·2019-08-26 11:51
阅读 1485·2019-08-26 10:48