摘要:在里使用進(jìn)行小程序頁(yè)面授權(quán),里面包含了用戶點(diǎn)擊取消的重新授權(quán)方案警告您點(diǎn)擊了拒絕授權(quán)將無(wú)法正常顯示個(gè)人信息點(diǎn)擊確定重新獲取授權(quán)。
在wepy里使用進(jìn)行小程序頁(yè)面授權(quán),里面包含了用戶點(diǎn)擊取消的重新授權(quán)方案:
//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: "您點(diǎn)擊了拒絕授權(quán),將無(wú)法正常顯示個(gè)人信息,點(diǎn)擊確定重新獲取授權(quán)。", success:function(res){ if (res.confirm) { wepy.openSetting({ success: (res) => { if (res.authSetting["scope.userInfo"] || res.authSetting["scope.userLocation"]){////如果用戶重新同意了授權(quán)登錄 wepy.getUserInfo({ success:function(res){ resolve(res.userInfo) that.$parent.globalData.userInfo = res.userInfo; } }) } },fail: function(res){ resolve({"avatarUrl":"","nickName":"翠花"}) console.log("沒(méi)有選擇授權(quán)") } }) }else{ console.log("還是不同意授權(quán)") } } }) }, 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("沒(méi)有獲取到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){ //第一次不執(zhí)行 isBoolen = false; }else{ wepy.openSetting({ // 點(diǎn)擊自帶取消定位健會(huì)調(diào)用這個(gè)面板 success: (res) => { if (res.authSetting["scope.userLocation"]){////如果用戶在面板重新同意了授權(quán)地理位置 console.log("--有了scope.userLocation--") resolve(getLocation(context)) //點(diǎn)擊面板后再次調(diào)用getLocation返回參數(shù) } },fail: function(res){ console.log("--沒(méi)有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("當(dāng)前頁(yè)面獲取過(guò)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() }
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://m.hztianpu.com/yun/100441.html
摘要:在里使用進(jìn)行小程序頁(yè)面授權(quán),里面包含了用戶點(diǎn)擊取消的重新授權(quán)方案警告您點(diǎn)擊了拒絕授權(quán)將無(wú)法正常顯示個(gè)人信息點(diǎn)擊確定重新獲取授權(quán)。 在wepy里使用進(jìn)行小程序頁(yè)面授權(quán),里面包含了用戶點(diǎn)擊取消的重新授權(quán)方案: //auth.js /* * @Author: Porco_Mar * @Date: 2018-04-11 15:49:55 * @Last Modified by: Por...
摘要:除官方外的參考文章微信小程序?qū)嵗齽?chuàng)建下發(fā)模板消息實(shí)例手把手教你開(kāi)發(fā)微信小程序之模版消息開(kāi)發(fā)教你突破小程序模板消息的推送限制獲取用戶信息接口的廢棄問(wèn)題接口是獲取用戶信息昵稱,頭像等的接口,在官方文檔上寫是即將廢棄。 ----------------更新-------------- 2018年10月10日官網(wǎng)3個(gè)接口廢棄的通知: 1、分享監(jiān)聽(tīng)接口分享消息給好友時(shí),開(kāi)發(fā)者將無(wú)法從callba...
摘要:大家好,我是平頭哥聯(lián)盟的首席填坑官蘇南,今天要給大家分享的是最近公司做的一個(gè)小程序項(xiàng)目,過(guò)程中的一些好的總結(jié)和遇到的坑,希望能給其他攻城獅帶來(lái)些許便利,更希望能做完之后老板給你加薪今天是中秋節(jié)的第一天,假日的清晨莫名的醒的特別早,不知道為什 showImg(https://segmentfault.com/img/bVbhAYf?w=1278&h=722); 大家好,我是@IT·平...
摘要:項(xiàng)目需求寫完有一段時(shí)間了,但是還是想回過(guò)來(lái)總結(jié)一下,一是對(duì)項(xiàng)目的回顧優(yōu)化等,二是對(duì)坑的地方做個(gè)記錄,避免以后遇到類似的問(wèn)題。需求利用微信強(qiáng)大的社交能力通過(guò)小程序達(dá)到裂變的目的,拉取新用戶。摘要: 小程序開(kāi)發(fā)必備技能啊... 原文:小程序如何生成海報(bào)分享朋友圈 作者:小白 Fundebug經(jīng)授權(quán)轉(zhuǎn)載,版權(quán)歸原作者所有。 項(xiàng)目需求寫完有一段時(shí)間了,但是還是想回過(guò)來(lái)總結(jié)一下,一是對(duì)項(xiàng)目的回顧優(yōu)...
閱讀 848·2019-08-30 15:55
閱讀 1606·2019-08-30 15:52
閱讀 2769·2019-08-30 15:44
閱讀 2176·2019-08-30 11:14
閱讀 2684·2019-08-29 13:59
閱讀 1899·2019-08-29 13:45
閱讀 1073·2019-08-29 13:21
閱讀 3437·2019-08-26 13:31