2025-03-05 23:13:24 +08:00
|
|
|
import Vue from 'vue'
|
|
|
|
|
import VueRouter from 'vue-router'
|
|
|
|
|
|
|
|
|
|
Vue.use(VueRouter)
|
|
|
|
|
|
|
|
|
|
const routes = [
|
|
|
|
|
{
|
|
|
|
|
path: '/',
|
|
|
|
|
name: 'welcome',
|
2025-03-14 23:48:59 +08:00
|
|
|
component: function () {
|
|
|
|
|
return import('../views/login.vue')
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/role-config',
|
|
|
|
|
name: 'RoleConfig',
|
|
|
|
|
component: function () {
|
|
|
|
|
return import('../views/roleConfig.vue')
|
|
|
|
|
}
|
2025-03-05 23:13:24 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/login',
|
|
|
|
|
name: 'login',
|
|
|
|
|
component: function () {
|
2025-03-14 23:48:59 +08:00
|
|
|
return import('../views/login.vue')
|
2025-03-05 23:13:24 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/home',
|
|
|
|
|
name: 'home',
|
|
|
|
|
component: function () {
|
2025-03-14 23:48:59 +08:00
|
|
|
return import('../views/home.vue')
|
2025-03-05 23:13:24 +08:00
|
|
|
}
|
2025-03-12 13:38:44 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/register',
|
|
|
|
|
name: 'Register',
|
|
|
|
|
component: function () {
|
2025-03-14 23:48:59 +08:00
|
|
|
return import('../views/register.vue')
|
2025-03-12 13:38:44 +08:00
|
|
|
}
|
|
|
|
|
},
|
2025-03-20 14:08:38 +08:00
|
|
|
// 设备管理页面路由
|
2025-03-18 21:49:57 +08:00
|
|
|
{
|
|
|
|
|
path: '/device-management',
|
|
|
|
|
name: 'DeviceManagement',
|
|
|
|
|
component: function () {
|
|
|
|
|
return import('../views/DeviceManagement.vue')
|
|
|
|
|
}
|
2025-03-20 14:08:38 +08:00
|
|
|
},
|
|
|
|
|
// 添加用户管理路由
|
|
|
|
|
{
|
|
|
|
|
path: '/user-management',
|
|
|
|
|
name: 'UserManagement',
|
|
|
|
|
component: function () {
|
|
|
|
|
return import('../views/UserManagement.vue')
|
|
|
|
|
}
|
2025-03-20 18:11:37 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/model-config',
|
|
|
|
|
name: 'ModelConfig',
|
|
|
|
|
component: function () {
|
|
|
|
|
return import('../views/ModelConfig.vue')
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-03-18 21:49:57 +08:00
|
|
|
|
2025-03-05 23:13:24 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
const router = new VueRouter({
|
|
|
|
|
routes
|
|
|
|
|
})
|
|
|
|
|
|
2025-03-30 00:20:09 +08:00
|
|
|
// 需要登录才能访问的路由
|
|
|
|
|
const protectedRoutes = ['home', 'RoleConfig', 'DeviceManagement', 'UserManagement', 'ModelConfig']
|
|
|
|
|
|
|
|
|
|
// 路由守卫
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
|
// 检查是否是需要保护的路由
|
|
|
|
|
if (protectedRoutes.includes(to.name)) {
|
|
|
|
|
// 从localStorage获取token
|
|
|
|
|
const token = localStorage.getItem('token')
|
|
|
|
|
if (!token) {
|
|
|
|
|
// 未登录,跳转到登录页
|
|
|
|
|
next({ name: 'login', query: { redirect: to.fullPath } })
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
next()
|
|
|
|
|
})
|
|
|
|
|
|
2025-03-05 23:13:24 +08:00
|
|
|
export default router
|