Files
gym-manage/gym-manage-uniapp/App.vue
T
2026-06-11 14:51:07 +08:00

83 lines
2.0 KiB
Vue

<template>
<view>
<GlobalLoading />
</view>
</template>
<script>
import GlobalLoading from '@/components/global/GlobalLoading.vue'
export default {
components: {
GlobalLoading
},
onLaunch: function() {
console.log('App Launch')
this.preloadTabData()
},
onShow: function() {
console.log('App Show')
// #ifdef APP-PLUS
this.hideNativeTabBar()
// #endif
},
onHide: function() {
console.log('App Hide')
},
methods: {
// 隐藏原生 TabBar - 这里是核心修复
hideNativeTabBar() {
// 尝试多次执行,确保执行成功
const tryHide = (times = 0) => {
if (times > 10) return // 最多尝试10次
uni.hideTabBar({
animation: false,
success: () => {
console.log('✅ 原生TabBar隐藏成功')
// 强制 CSS 覆盖(双重保险)
this.forceCSSHide()
},
fail: (err) => {
console.log(`❌ 第${times+1}次隐藏失败,1秒后重试`, err)
setTimeout(() => tryHide(times + 1), 1000)
}
})
}
// 延迟 300ms 执行,确保页面挂载完成
setTimeout(() => tryHide(), 300)
},
// 强制 CSS 覆盖(最终保险)
forceCSSHide() {
// #ifdef APP-PLUS
const style = document.createElement('style')
style.innerHTML = `
uni-tabbar,
uni-tabbar .uni-tabbar,
.uni-tabbar,
uni-tabbar > .uni-tabbar,
[class*="uni-tabbar"] {
display: none !important;
height: 0 !important;
opacity: 0 !important;
visibility: hidden !important;
pointer-events: none !important;
}
`
document.head.appendChild(style)
console.log('✅ CSS 强制覆盖已注入')
// #endif
},
// 预加载所有 Tab 页面的核心数据
preloadTabData() {
// 延迟执行,不阻塞首屏
setTimeout(() => {
// 预加载课程数据等...
}, 1000)
}
}
}
</script>