app.js 734 B

12345678910111213141516171819202122232425262728
  1. //app.js
  2. App({
  3. onLaunch: function () {
  4. // 获取用户信息
  5. wx.getSetting({
  6. success: res => {
  7. if (res.authSetting['scope.userInfo']) {
  8. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  9. wx.getUserInfo({
  10. success: res => {
  11. // 可以将 res 发送给后台解码出 unionId
  12. this.globalData.userInfo = res.userInfo
  13. this.globalData.login = false
  14. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  15. // 所以此处加入 callback 以防止这种情况
  16. if (this.userInfoReadyCallback) {
  17. this.userInfoReadyCallback(res)
  18. }
  19. }
  20. })
  21. }
  22. }
  23. })
  24. },
  25. globalData: {
  26. userInfo: null
  27. }
  28. })