| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- /**
- * 分包页视口高度:iOS 上 scroll-view 需父级固定 px 高度,避免 flex+height:0 导致空白
- */
- export default {
- data() {
- return {
- pageHeightPx: 0
- }
- },
- computed: {
- pageStyle() {
- if (this.pageHeightPx > 0) {
- return { height: `${this.pageHeightPx}px` }
- }
- return {}
- }
- },
- onLoad() {
- this.applyPageHeight()
- },
- onReady() {
- this.applyPageHeight()
- },
- methods: {
- getNavigationBarHeight() {
- const sys = uni.getSystemInfoSync()
- const statusBar = sys.statusBarHeight || 0
- // #ifdef MP-WEIXIN
- try {
- const menu = uni.getMenuButtonBoundingClientRect()
- if (menu && menu.height) {
- return statusBar + (menu.top - statusBar) * 2 + menu.height
- }
- } catch (e) {
- /* noop */
- }
- // #endif
- return statusBar + 44
- },
- getViewportContentHeight() {
- const sys = uni.getSystemInfoSync()
- const navH = this.getNavigationBarHeight()
- // #ifdef H5
- if (typeof window !== 'undefined' && window.innerHeight) {
- return Math.max(320, window.innerHeight - navH)
- }
- // #endif
- const screenH = sys.screenHeight || sys.windowHeight || 600
- return Math.max(320, screenH - navH)
- },
- applyPageHeight() {
- this.pageHeightPx = this.getViewportContentHeight()
- }
- }
- }
|