From cc939b6298410ecc83d391639b972e4fb75d8dc8 Mon Sep 17 00:00:00 2001 From: stefanfeng Date: Fri, 24 Jul 2026 17:50:19 +0800 Subject: [PATCH] fix: guard avatar entry and hide chat navigation --- digital-avatar-app/src/App.vue | 14 ++++++++++---- digital-avatar-app/src/router/index.ts | 5 ++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/digital-avatar-app/src/App.vue b/digital-avatar-app/src/App.vue index 5a2797d..2a82d21 100644 --- a/digital-avatar-app/src/App.vue +++ b/digital-avatar-app/src/App.vue @@ -39,13 +39,19 @@ const router = useRouter() const route = useRoute() const currentRoute = ref(route.path) -const showNav = ref(true) +const showNav = ref(shouldShowNav(route.path)) + +function shouldShowNav(path: string) { + return path !== '/' + && path !== '/login/sms' + && !path.startsWith('/avatar/edit') + && !path.startsWith('/avatar/chat') +} // 监听路由变化 watch(() => route.path, (newPath) => { currentRoute.value = newPath - // 首页(创建引导)与编辑页隐藏底部导航 - showNav.value = newPath !== '/' && !newPath.startsWith('/avatar/edit') + showNav.value = shouldShowNav(newPath) }) // 导航 @@ -55,7 +61,7 @@ const navigateTo = (path: string) => { onMounted(() => { currentRoute.value = route.path - showNav.value = route.path !== '/' && !route.path.startsWith('/avatar/edit') + showNav.value = shouldShowNav(route.path) }) diff --git a/digital-avatar-app/src/router/index.ts b/digital-avatar-app/src/router/index.ts index 37283d4..fea212a 100644 --- a/digital-avatar-app/src/router/index.ts +++ b/digital-avatar-app/src/router/index.ts @@ -1,5 +1,6 @@ import { createRouter, createWebHashHistory } from 'vue-router' import type { RouteRecordRaw } from 'vue-router' +import { getAuthToken } from '@/api' const routes: RouteRecordRaw[] = [ { @@ -96,7 +97,9 @@ const router = createRouter({ router.beforeEach((to, from, next) => { document.title = to.meta.title as string || '会会数字分身' - if (to.meta.requiresAuth && !localStorage.getItem('hh_app_token')) { + const hasLocalSession = Boolean(localStorage.getItem('hh_app_token')) + const hasInjectedSession = Boolean(getAuthToken()) + if (to.meta.requiresAuth && !hasLocalSession && !hasInjectedSession) { next({ path: '/login/sms', query: { redirect: to.fullPath } }) return }