99 lines
2.7 KiB
TypeScript
99 lines
2.7 KiB
TypeScript
import { createRouter, createWebHistory } from 'vue-router'
|
|
import { useUserStore } from '@/stores/user'
|
|
import Layout from '@/views/Layout.vue'
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
routes: [
|
|
{
|
|
path: '/login',
|
|
name: 'Login',
|
|
component: () => import('@/views/auth/Login.vue')
|
|
},
|
|
{
|
|
path: '/',
|
|
component: Layout,
|
|
redirect: '/dashboard',
|
|
children: [
|
|
{
|
|
path: 'dashboard',
|
|
name: 'Dashboard',
|
|
component: () => import('@/views/Dashboard.vue'),
|
|
meta: { title: '仪表盘' }
|
|
},
|
|
{
|
|
path: 'system/users',
|
|
name: 'Users',
|
|
component: () => import('@/views/system/Users.vue'),
|
|
meta: { title: '用户管理' }
|
|
},
|
|
{
|
|
path: 'system/roles',
|
|
name: 'Roles',
|
|
component: () => import('@/views/system/Roles.vue'),
|
|
meta: { title: '角色管理' }
|
|
},
|
|
{
|
|
path: 'system/permissions',
|
|
name: 'Permissions',
|
|
component: () => import('@/views/system/Permissions.vue'),
|
|
meta: { title: '权限管理' }
|
|
},
|
|
{
|
|
path: 'system/audit',
|
|
name: 'Audit',
|
|
component: () => import('@/views/system/Audit.vue'),
|
|
meta: { title: '审计日志' }
|
|
},
|
|
{
|
|
path: 'system/settings',
|
|
name: 'Settings',
|
|
component: () => import('@/views/system/Settings.vue'),
|
|
meta: { title: '系统设置' }
|
|
},
|
|
{
|
|
path: 'project/list',
|
|
name: 'ProjectList',
|
|
component: () => import('@/views/project/List.vue'),
|
|
meta: { title: '项目管理' }
|
|
},
|
|
{
|
|
path: 'project/detail/:id',
|
|
name: 'ProjectDetail',
|
|
component: () => import('@/views/project/Detail.vue'),
|
|
meta: { title: '项目详情' }
|
|
},
|
|
{
|
|
path: 'project/:id/space',
|
|
name: 'ProjectSpace',
|
|
component: () => import('@/views/space/Space.vue'),
|
|
meta: { title: '空间管理' }
|
|
},
|
|
{
|
|
path: 'equipment/list',
|
|
name: 'EquipmentList',
|
|
component: () => import('@/views/equipment/EquipmentList.vue'),
|
|
meta: { title: '设备管理' }
|
|
},
|
|
{
|
|
path: 'equipment/detail/:id',
|
|
name: 'EquipmentDetail',
|
|
component: () => import('@/views/equipment/EquipmentDetail.vue'),
|
|
meta: { title: '设备详情' }
|
|
}
|
|
]
|
|
}
|
|
]
|
|
})
|
|
|
|
router.beforeEach((to, _from, next) => {
|
|
const userStore = useUserStore()
|
|
if (to.path !== '/login' && !userStore.isLoggedIn()) {
|
|
next('/login')
|
|
} else {
|
|
next()
|
|
}
|
|
})
|
|
|
|
export default router
|