diff --git a/screen-vue/src/components/Layout/index.vue b/screen-vue/src/components/Layout/index.vue index a1c3d40..16a3a4e 100644 --- a/screen-vue/src/components/Layout/index.vue +++ b/screen-vue/src/components/Layout/index.vue @@ -318,7 +318,7 @@ const handleFullScreen = () => { const handleBigScreen = () => { if (!isMounted.value) return - const baseUrl = window.location.origin + "/bigScreen"; + const baseUrl = window.location.origin + "/#/bigScreen"; window.open(baseUrl, '_blank'); } diff --git a/screen-vue/src/router/index.js b/screen-vue/src/router/index.js index b73619d..380b50f 100644 --- a/screen-vue/src/router/index.js +++ b/screen-vue/src/router/index.js @@ -1,4 +1,4 @@ -import { createRouter, createWebHistory } from 'vue-router' +import { createRouter, createWebHashHistory } from 'vue-router' import Login from '@/views/Login.vue' import Page404 from '@/views/error/404.vue' import Layout from '@/components/Layout/index.vue' @@ -52,16 +52,16 @@ const routes = [ component: Login, meta: { isPublic: true } }, - { - path: '/', - redirect: '/login' - }, { path: '/bigScreen', name: 'bigScreen', component: bigScreen, meta: { requiresAuth: true } }, + { + path: '/', + redirect: '/login' + }, { path: '/layout', component: Layout, @@ -83,37 +83,41 @@ const routes = [ ] const router = createRouter({ - history: createWebHistory(import.meta.env.BASE_URL || '/'), + history: createWebHashHistory(import.meta.env.BASE_URL || './'), routes, scrollBehavior() { return { top: 0 } } }) -// 优化路由守卫逻辑:更健壮的登录校验 +// 优化路由守卫:适配hash模式,增强容错 router.beforeEach((to, from, next) => { - // 公开页面直接放行 + // 1. 公开页面直接放行(登录页) if (to.meta.isPublic) { next() return } - // 非公开页面校验token + // 2. 非公开页面校验token(兼容hash模式) try { const token = localStorage.getItem('token') - // 严格校验token有效性 - if (token && typeof token === 'string' && token.trim() !== '') { + const isValidToken = token.trim().length > 0 + + if (isValidToken) { next() } else { next({ path: '/login', query: { redirect: to.fullPath }, - replace: true // 替换历史记录,避免回退问题 + replace: true }) } } catch (error) { - console.error('路由守卫校验token失败:', error) - next({ path: '/login', replace: true }) + console.error('路由守卫校验失败:', error) + next({ + path: '/login', + replace: true + }) } }) diff --git a/src/main/java/com/mini/mybigscreen/Config/LoginInterceptor.java b/src/main/java/com/mini/mybigscreen/Config/LoginInterceptor.java index 1ee48d7..613c609 100644 --- a/src/main/java/com/mini/mybigscreen/Config/LoginInterceptor.java +++ b/src/main/java/com/mini/mybigscreen/Config/LoginInterceptor.java @@ -31,7 +31,7 @@ public class LoginInterceptor implements HandlerInterceptor { } String token = (String) session.getAttribute("token"); - if (StringUtils.isEmpty(token)){ + if (StringUtils.isEmpty(token)) { String json = objectMapper.writeValueAsString(Result.unauthorized()); try (PrintWriter writer = response.getWriter()) { writer.write(json);