大屏项目初始化

This commit is contained in:
2026-03-05 22:32:39 +08:00
parent 6cd69428af
commit 3ee4fbfd8c
26 changed files with 198 additions and 153 deletions

View File

@@ -4,6 +4,8 @@ import Page404 from '@/views/error/404.vue'
import Layout from '@/components/Layout/index.vue'
import Dashboard from '@/views/desktop/index.vue'
import bigScreen from '@/views/screen/index.vue'
import { useUserStore } from '@/stores/user'
import { ElMessage } from 'element-plus'
const modules = import.meta.glob('../views/**/{index,list}.vue', {
eager: false,
@@ -90,22 +92,18 @@ const router = createRouter({
}
})
// 优化路由守卫适配hash模式增强容错
router.beforeEach((to, from, next) => {
// 1. 公开页面直接放行(登录页)
if (to.meta.isPublic) {
next()
return
}
// 2. 非公开页面校验token兼容hash模式
const userStore = useUserStore()
try {
const token = localStorage.getItem('token')
const isValidToken = token.trim().length > 0
if (isValidToken) {
if (userStore.isLoggedIn()) {
next()
} else {
ElMessage.warning('请先登录后再操作!')
next({
path: '/login',
query: { redirect: to.fullPath },
@@ -114,6 +112,7 @@ router.beforeEach((to, from, next) => {
}
} catch (error) {
console.error('路由守卫校验失败:', error)
ElMessage.error('登录状态校验失败,请重新登录!')
next({
path: '/login',
replace: true