提交 24a1e3a3 编写于 作者: fxy060608's avatar fxy060608

增加应用初始化前调用 getWindowOffset,getCurrentPages 的兼容性处理

上级 69d41a17
......@@ -9,6 +9,10 @@ export function getApp () {
export function getCurrentPages (isAll = false) {
const pages = []
const app = getApp()
if (!app) {
console.error('app is not ready')
return []
}
const childrenVm = app.$children[0]
if (childrenVm && childrenVm.$children.length) {
const tabBarVm = childrenVm.$children.find(vm => vm.$options.name === 'TabBar')
......@@ -47,7 +51,7 @@ export function getCurrentPages (isAll = false) {
if (currentPage.$page.path !== app.$route.path) { // 删除已经准备销毁的上个页面
pages.splice(length - 1, 1)
}
}
}
return pages
}
......
......@@ -7,19 +7,24 @@ export default function getWindowOffset () {
if (uni.canIUse('css.var')) {
const style = document.documentElement.style
return {
top: parseInt(style.getPropertyValue('--window-top')),
bottom: parseInt(style.getPropertyValue('--window-bottom'))
top: parseInt(style.getPropertyValue('--window-top')) || 0,
bottom: parseInt(style.getPropertyValue('--window-bottom')) || 0
}
}
let top = 0
let bottom = 0
const pages = getCurrentPages()
if (pages.length) {
const pageVm = pages[pages.length - 1].$parent.$parent
top = pageVm.showNavigationBar && pageVm.navigationBar.type !== 'transparent' ? NAVBAR_HEIGHT : 0
}
const app = getApp()
if (app) {
bottom = app.$children[0].showTabBar ? TABBAR_HEIGHT : 0
}
return {
top,
bottom: getApp().$children[0].showTabBar ? TABBAR_HEIGHT : 0
bottom
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册