app.js 1.1 KB

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