大屏项目初始化

This commit is contained in:
2026-02-24 23:26:41 +08:00
commit 412e2ac1f7
236 changed files with 5907 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login.vue'
import Dashboard from '@/views/desktop/index.vue'
// 路由规则
const routes = [
{
path: '/',
redirect: '/login' // 默认跳登录页
},
{
path: '/login',
name: 'Login',
component: Login,
meta: {
isPublic: true // 标记为公开页面,无需登录
}
},
{
path: '/dashboard',
name: 'Dashboard',
component: Dashboard,
meta: {
requiresAuth: true // 需要登录验证
}
},
// 关键补充404兜底路由匹配所有未定义的前端路由
{
path: '/:pathMatch(.*)*',
redirect: '/login' // 未知路径重定向到登录页
}
]
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL || '/'),
routes,
scrollBehavior() {
return { top: 0 }
}
})
// 路由守卫:验证登录状态(优化版,增加容错)
router.beforeEach((to, from, next) => {
// 公开页面直接放行
if (to.meta.isPublic) {
next()
return
}
// 非公开页面校验token
try {
const token = localStorage.getItem('token')
if (token && token.trim() !== '') {
next()
} else {
next({ path: '/login', query: { redirect: to.fullPath } })
}
} catch (error) {
next('/login')
}
})
export default router