getSystemInfo.js 848 B

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * 获取系统信息
  3. */
  4. class SystemInfo {
  5. static fetchAllInfo() {
  6. const menuButton = wx.getMenuButtonBoundingClientRect()
  7. const systemInfo = wx.getSystemInfoSync()
  8. const statusBarHeight = systemInfo.statusBarHeight
  9. const headerHeight = (menuButton.top - systemInfo.statusBarHeight) * 2 + menuButton.height
  10. let data = {
  11. source: {
  12. menu: menuButton,
  13. system: systemInfo
  14. },
  15. statusBarHeight: statusBarHeight,
  16. headerHeight: headerHeight,
  17. headerRight: systemInfo.windowWidth - menuButton.left
  18. }
  19. wx.setStorageSync('SystemInfo', data)
  20. return data
  21. }
  22. static getInfo() {
  23. let storageInfoSync = wx.getStorageSync('SystemInfo')
  24. if (!storageInfoSync) {
  25. storageInfoSync = this.fetchAllInfo()
  26. }
  27. return storageInfoSync
  28. }
  29. }
  30. export default SystemInfo