getStatusBar.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import store from '@/store/index.js';
  2. export const getStatusBar = () => {
  3. return new Promise((success, fail) => {
  4. uni.getSystemInfo({
  5. success: (e) => {
  6. // 获取手机状态栏高度
  7. let statusBar = e.statusBarHeight
  8. let customBar
  9. // #ifndef MP
  10. customBar = statusBar + (e.platform == 'android' ? 50 : 45)
  11. // #endif
  12. // #ifdef MP-WEIXIN
  13. // 获取胶囊按钮的布局位置信息
  14. let menu = wx.getMenuButtonBoundingClientRect()
  15. // 导航栏高度 = 胶囊下距离 + 胶囊上距离 - 状态栏高度
  16. customBar = menu.bottom + menu.top - statusBar
  17. // #endif
  18. // #ifdef MP-ALIPAY
  19. customBar = statusBar + e.titleBarHeight
  20. // #endif
  21. const compensateHeight = 10; //非刘海屏状态栏高度偏低,补充10
  22. store.commit('SET_STATUSBAR', {
  23. statusBar: statusBar + compensateHeight,
  24. customBar: customBar + compensateHeight,
  25. // #ifdef MP
  26. statusBar: statusBar + compensateHeight + 10,
  27. customBar: customBar + compensateHeight + 10
  28. // #endif
  29. });
  30. success({
  31. statusBar,
  32. customBar
  33. })
  34. }
  35. })
  36. })
  37. }