app.js 1.4 KB

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