修复:修复前后台切换底部导航闪现

This commit is contained in:
xiaowang
2026-03-26 10:57:46 +08:00
parent b1177c4f75
commit 51eb734ada
2 changed files with 38 additions and 6 deletions
+18 -6
View File
@@ -16,20 +16,27 @@
</template>
<script setup lang="ts">
import { computed, ref, provide, watch } from 'vue'
import { useRoute } from 'vue-router'
import { computed, onMounted, provide, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ConfigProvider } from 'ant-design-vue'
import BottomNav from './components/BottomNav.vue'
import { cartApi } from './api/cart'
import antdLocale from './config/antdv-locale'
const route = useRoute()
const router = useRouter()
const routerReady = ref(false)
const isHiddenNav = computed(() => {
// 检查当前路由及其所有父路由是否有 hideNav: true
// 或者检查是否是后台页面
const result = route.matched.some(r => r.meta.hideNav) || route.matched.some(r => r.meta.isAdmin)
return result
if (!routerReady.value) {
return true
}
if (route.path === '/' || route.path.startsWith('/admin')) {
return true
}
return route.matched.some(r => r.meta.hideNav) || route.matched.some(r => r.meta.isAdmin)
})
// 全局购物车数量状态
@@ -74,6 +81,11 @@ watch(() => route.path, async () => {
// 页面加载时获取购物车数量
loadCartCount()
onMounted(async () => {
await router.isReady()
routerReady.value = true
})
</script>
<style>
@@ -0,0 +1,20 @@
# 2026-03-26 前后台切换底部导航闪现修复
## 问题
- 在前台与后台页面切换时,底部导航栏会短暂闪现一下。
- 原因是应用初始化阶段路由尚未完全就绪,`route.matched` 会短暂为空,导致 `BottomNav` 被误判为可显示。
## 修改
- 调整 [App.vue](/E:/code/xiaowang/Frontend/src/App.vue)
- 增加 `router.isReady()` 就绪标记,在路由未完成初始化前强制隐藏底部导航。
- 增加基于 `route.path` 的兜底判断:
- `/` 直接隐藏
- `/admin` 开头的后台路径直接隐藏
- 保留原有 `hideNav` / `isAdmin` 元信息判断作为正常路由态下的显示规则。
## 结果
- 前后台整页切换时,底部导航不再出现短暂闪现。
- 正常前台页面的底部导航显示逻辑不受影响。