大屏页面初始化

This commit is contained in:
2026-03-02 14:33:24 +08:00
parent 1de57f2089
commit e21ced5c40
3 changed files with 20 additions and 16 deletions

View File

@@ -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');
}

View File

@@ -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
})
}
})