app.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // app.js
  2. App({
  3. globalData: {},
  4. onLaunch() {
  5. // 获取胶囊信息
  6. let menuButtonObject = wx.getMenuButtonBoundingClientRect()
  7. // 获取设备信息
  8. wx.getSystemInfo({
  9. success: res => {
  10. // 整个导航栏的高度
  11. let navHeight = menuButtonObject.top + menuButtonObject.height + (menuButtonObject.top - res.statusBarHeight) * 2
  12. // 导航栏的高度
  13. let nav = navHeight - res.statusBarHeight
  14. // 挂载到全区变量 globalData 上
  15. this.globalData.navHeight = navHeight
  16. this.globalData.nav = nav
  17. // 胶囊与左边的距离
  18. this.globalData.menuLeft = menuButtonObject.left
  19. // 胶囊的高度
  20. this.globalData.menuHeight = menuButtonObject.height
  21. // 胶囊距离顶部的高度
  22. this.globalData.menuBot = menuButtonObject.top - res.statusBarHeight
  23. // 整个设备的宽度
  24. this.globalData.windowWidth = res.windowWidth
  25. },
  26. fail: err => {
  27. console.log(err)
  28. }
  29. })
  30. // 展示本地存储能力
  31. // const logs = wx.getStorageSync('logs') || []
  32. // logs.unshift(Date.now())
  33. // wx.setStorageSync('logs', logs)
  34. // 登录
  35. wx.login({
  36. success: res => {
  37. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  38. }
  39. })
  40. this.getSystemInfo()
  41. },
  42. getSystemInfo: function () {
  43. let t = this;
  44. wx.getSystemInfo({
  45. success: function (res) {
  46. t.globalData.systemInfo = res;
  47. }
  48. });
  49. },
  50. globalData: {
  51. // isIPhoneX: false, //当前设备是否为 iPhone
  52. userInfo: null
  53. }
  54. })
  55. /**
  56. *
  57. */