西藏巴青项目

pageViewport.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * 分包页视口高度:iOS 上 scroll-view 需父级固定 px 高度,避免 flex+height:0 导致空白
  3. */
  4. export default {
  5. data() {
  6. return {
  7. pageHeightPx: 0
  8. }
  9. },
  10. computed: {
  11. pageStyle() {
  12. if (this.pageHeightPx > 0) {
  13. return { height: `${this.pageHeightPx}px` }
  14. }
  15. return {}
  16. }
  17. },
  18. onLoad() {
  19. this.applyPageHeight()
  20. },
  21. onReady() {
  22. this.applyPageHeight()
  23. },
  24. methods: {
  25. getNavigationBarHeight() {
  26. const sys = uni.getSystemInfoSync()
  27. const statusBar = sys.statusBarHeight || 0
  28. // #ifdef MP-WEIXIN
  29. try {
  30. const menu = uni.getMenuButtonBoundingClientRect()
  31. if (menu && menu.height) {
  32. return statusBar + (menu.top - statusBar) * 2 + menu.height
  33. }
  34. } catch (e) {
  35. /* noop */
  36. }
  37. // #endif
  38. return statusBar + 44
  39. },
  40. getViewportContentHeight() {
  41. const sys = uni.getSystemInfoSync()
  42. const navH = this.getNavigationBarHeight()
  43. // #ifdef H5
  44. if (typeof window !== 'undefined' && window.innerHeight) {
  45. return Math.max(320, window.innerHeight - navH)
  46. }
  47. // #endif
  48. const screenH = sys.screenHeight || sys.windowHeight || 600
  49. return Math.max(320, screenH - navH)
  50. },
  51. applyPageHeight() {
  52. this.pageHeightPx = this.getViewportContentHeight()
  53. }
  54. }
  55. }