Compare commits

...

2 Commits

Author SHA1 Message Date
stefanfeng
1da5f7f10d fix: open logged-in users on avatar management 2026-07-24 17:54:02 +08:00
stefanfeng
cc939b6298 fix: guard avatar entry and hide chat navigation 2026-07-24 17:50:19 +08:00
3 changed files with 22 additions and 6 deletions

View File

@@ -39,13 +39,20 @@ const router = useRouter()
const route = useRoute() const route = useRoute()
const currentRoute = ref<string>(route.path) const currentRoute = ref<string>(route.path)
const showNav = ref<boolean>(true) const showNav = ref<boolean>(shouldShowNav(route.path))
function shouldShowNav(path: string) {
return path !== '/'
&& path !== '/avatar/create'
&& path !== '/login/sms'
&& !path.startsWith('/avatar/edit')
&& !path.startsWith('/avatar/chat')
}
// 监听路由变化 // 监听路由变化
watch(() => route.path, (newPath) => { watch(() => route.path, (newPath) => {
currentRoute.value = newPath currentRoute.value = newPath
// 首页(创建引导)与编辑页隐藏底部导航 showNav.value = shouldShowNav(newPath)
showNav.value = newPath !== '/' && !newPath.startsWith('/avatar/edit')
}) })
// 导航 // 导航
@@ -55,7 +62,7 @@ const navigateTo = (path: string) => {
onMounted(() => { onMounted(() => {
currentRoute.value = route.path currentRoute.value = route.path
showNav.value = route.path !== '/' && !route.path.startsWith('/avatar/edit') showNav.value = shouldShowNav(route.path)
}) })
</script> </script>

View File

@@ -1,9 +1,16 @@
import { createRouter, createWebHashHistory } from 'vue-router' import { createRouter, createWebHashHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router' import type { RouteRecordRaw } from 'vue-router'
import { getAuthToken } from '@/api'
const routes: RouteRecordRaw[] = [ const routes: RouteRecordRaw[] = [
{ {
path: '/', path: '/',
name: 'AvatarHome',
redirect: '/avatar/manage',
meta: { title: '数字分身管理', requiresAuth: true }
},
{
path: '/avatar/create',
name: 'AvatarCreate', name: 'AvatarCreate',
component: () => import('@/views/AvatarCreate.vue'), component: () => import('@/views/AvatarCreate.vue'),
meta: { title: '创建数字分身', requiresAuth: true } meta: { title: '创建数字分身', requiresAuth: true }
@@ -96,7 +103,9 @@ const router = createRouter({
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
document.title = to.meta.title as string || '会会数字分身' 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 } }) next({ path: '/login/sms', query: { redirect: to.fullPath } })
return return
} }

View File

@@ -253,7 +253,7 @@ const goToRecharge = () => {
} }
const goCreate = () => { const goCreate = () => {
router.push('/') router.push('/avatar/create')
} }
const goToKnowledge = () => { const goToKnowledge = () => {