updateCustomBarInfo.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * 更新自定义顶部导航栏的高度
  3. */
  4. function updateCustomBarInfo () {
  5. return new Promise((resolve, reject) => {
  6. uni.getSystemInfo({
  7. success: (e) => {
  8. let statusBarHeight = 0
  9. let customBarHeight = 0
  10. // #ifndef MP
  11. statusBarHeight = e.statusBarHeight
  12. if (e.platform == 'android') {
  13. customBarHeight = e.statusBarHeight + 50
  14. } else {
  15. customBarHeight = e.statusBarHeight + 45
  16. };
  17. // #endif
  18. // #ifdef MP-WEIXIN
  19. statusBarHeight = e.statusBarHeight
  20. let custom = wx.getMenuButtonBoundingClientRect()
  21. customBarHeight = custom.bottom + ((custom.top - e.statusBarHeight) <= 4 ? (custom.top - e
  22. .statusBarHeight) + 4 : (custom.top - e.statusBarHeight))
  23. // #endif
  24. // #ifdef MP-ALIPAY
  25. statusBarHeight = e.statusBarHeight
  26. customBarHeight = e.statusBarHeight + e.titleBarHeight
  27. // #endif
  28. resolve({
  29. statusBarHeight,
  30. customBarHeight
  31. })
  32. },
  33. fail: (err) => {
  34. console.log("获取设备信息失败", err);
  35. reject()
  36. }
  37. })
  38. })
  39. }
  40. export default updateCustomBarInfo