1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
| import { createRouter, createWebHistory } from 'vue-router'
| import { useUserStore } from '@/stores/user'
|
| const routes = [
| {
| path: '/login',
| name: 'Login',
| component: () => import('@/views/Login.vue'),
| meta: { title: '登录' }
| },
| {
| path: '/',
| component: () => import('@/layout/MainLayout.vue'),
| redirect: '/dashboard',
| children: [
| {
| path: 'dashboard',
| name: 'Dashboard',
| component: () => import('@/views/Dashboard.vue'),
| meta: { title: '首页' }
| },
| {
| path: 'system/user',
| name: 'User',
| component: () => import('@/views/system/User.vue'),
| meta: { title: '用户管理' }
| },
| {
| path: 'system/department',
| name: 'Department',
| component: () => import('@/views/system/Department.vue'),
| meta: { title: '部门管理' }
| },
| {
| path: 'data/excel',
| name: 'Excel',
| component: () => import('@/views/data/Excel.vue'),
| meta: { title: 'Excel上传' }
| },
| {
| path: 'data/unit-task',
| name: 'UnitTask',
| component: () => import('@/views/data/UnitTask.vue'),
| meta: { title: '单位上传任务' }
| },
| {
| path: 'statistics/unit',
| name: 'UnitStatistics',
| component: () => import('@/views/statistics/UnitStatistics.vue'),
| meta: { title: '各单位数据统计' }
| }
| ]
| }
| ]
|
| const router = createRouter({
| history: createWebHistory(),
| routes
| })
|
| router.beforeEach((to, from, next) => {
| document.title = to.meta.title || '数据管理系统'
| const userStore = useUserStore()
|
| if (to.path !== '/login' && !userStore.token) {
| next('/login')
| } else {
| next()
| }
| })
|
| export default router
|
|