1 Star 0 Fork 6

上善若水/微信小程序demo

forked from Kevin/微信小程序demo 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
app.js 1.58 KB
一键复制 编辑 原始数据 按行查看 历史
Kevin 提交于 2019-09-20 20:24 +08:00 . first push
//app.js
App({
onLaunch: function () {
this.getStatusBarHeight()
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
this.handleReady(res)
},
fail: () => {
this.handleReady(false)
}
})
} else {
this.handleReady(false)
}
},
fail: () => {
this.handleReady(false)
}
})
},
handleReady(data) {
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(data)
} else {
this.globalData.isReady = true
}
},
/**
* 获取标题栏和状态栏高度,使用自定义标题时需要
*/
getStatusBarHeight() {
try {
const res = wx.getSystemInfoSync()
this.globalData.statusBarHeight = res.statusBarHeight
if (res.system.indexOf('ios') >= 0) {
res.titleBarHeight = 32 + 6 * 2
} else {
res.titleBarHeight = 32 + 8 * 2
}
this.globalData.titleBarHeight = res.titleBarHeight
return res
} catch (e) {
return null;
}
},
globalData: {
isReady: false,
userInfo: null
}
})
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
微信
1
https://gitee.com/ssrss_admin/wxapp-demo.git
git@gitee.com:ssrss_admin/wxapp-demo.git
ssrss_admin
wxapp-demo
微信小程序demo
master

搜索帮助