1 Star 0 Fork 0

LL刘刘刘刘刘刘刘刘刘刘/ky-Smallprogram

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.js 1.74 KB
一键复制 编辑 原始数据 按行查看 历史
LL刘刘刘刘刘刘刘刘刘刘 提交于 2018-12-27 11:03 +08:00 . 小程序map层级
//app.js
App({
onLaunch: function () {
var that = this;
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
that.requestUserInfo();
}else{
wx.authorize({
scope: 'scope.userInfo',
success(res) {
that.requestUserInfo();
},
fail() {
wx.showModal({
title: '提示',
content: '获取用户信息失败',
success: function (res) {
if (res.confirm) {
wx.openSetting({
success: function (res) {
if (res.authSetting['scope.userLocation']) {
that.requestUserInfo();
} else {
consoleUtil.log('用户未同意获取用户信息权限');
}
}
})
}
}
})
}
})
}
}
})
},
requestUserInfo: function(){
var that = this;
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
that.globalData.userInfo = res.userInfo;
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (that.userInfoReadyCallback) {
that.userInfoReadyCallback(res);
}
}
})
},
globalData: {
userInfo: null,
header: {
'Cookie': '',
'content-type': 'application/json'
},
}
})
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/myliu/ky-Smallprogram.git
git@gitee.com:myliu/ky-Smallprogram.git
myliu
ky-Smallprogram
ky-Smallprogram
master

搜索帮助