lrj
2 天以前 dc643ba44fd2a426263015491268a0f0d6b4671d
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import { isLoggedIn } from '@/utils/auth'
 
const routes: RouteRecordRaw[] = [
  {
    path: '/',
    component: () => import('@/layout/index.vue'),
    children: [
      { path: '', redirect: '/dashboard' },
      {
        path: '/dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index.vue'),
        meta: { title: '工作台', icon: 'Grid' }
      },
      {
        path: '/activity',
        name: 'Activity',
        component: () => import('@/views/activity/index.vue'),
        meta: { title: '比赛管理', icon: 'Trophy' }
      },
      {
        path: '/activity/:id',
        name: 'ActivityDetail',
        component: () => import('@/views/ActivityDetail.vue'),
        meta: { title: '比赛详情', icon: 'Trophy' }
      },
      {
        path: '/activity/new',
        name: 'ActivityCreate',
        component: () => import('@/views/ActivityForm.vue'),
        meta: { title: '新增比赛', icon: 'Trophy' }
      },
      {
        path: '/activity/edit/:id',
        name: 'ActivityEdit',
        component: () => import('@/views/ActivityForm.vue'),
        meta: { title: '编辑比赛', icon: 'Trophy' }
      },
      {
        path: '/judge',
        name: 'Judge',
        component: () => import('@/views/judge/index.vue'),
        meta: { title: '评委管理', icon: 'UserFilled' }
      },
      {
        path: '/rating-scheme',
        name: 'RatingScheme',
        component: () => import('@/views/rating/index.vue'),
        meta: { title: '评分模板', icon: 'Score' }
      },
      {
        path: '/rating-scheme/new',
        name: 'RatingSchemeCreate',
        component: () => import('@/views/rating/Form.vue'),
        meta: { title: '新增评分模板', icon: 'Score' }
      },
      {
        path: '/rating-scheme/edit/:id',
        name: 'RatingSchemeEdit',
        component: () => import('@/views/rating/Form.vue'),
        meta: { title: '编辑评分模板', icon: 'Score' }
      },
      {
        path: '/player',
        name: 'Player',
        component: () => import('@/views/player/index.vue'),
        meta: { title: '报名审核', icon: 'UserFilled' }
      },
      {
        path: '/player/:id/detail',
        name: 'PlayerDetail',
        component: () => import('@/views/player/detail.vue'),
        meta: { title: '报名详情', icon: 'UserFilled' }
      },
      {
        path: '/activity-player/:id/rating',
        name: 'ActivityPlayerRating',
        component: () => import('@/views/activity-player/rating.vue'),
        meta: { title: '评分详情', icon: 'Edit' }
      },
      {
        path: '/carousel',
        name: 'Carousel',
        component: () => import('@/views/carousel/index.vue'),
        meta: { title: '新闻与推广', icon: 'Picture' }
      },
      {
        path: '/region',
        name: 'Region',
        component: () => import('@/views/region/index.vue'),
        meta: { title: '区域管理', icon: 'Location' }
      },
      {
        path: '/employee',
        name: 'Employee',
        component: () => import('@/views/employee/index.vue'),
        meta: { title: '员工管理', icon: 'Avatar' }
      },
      {
        path: '/project-review',
        name: 'ProjectReview',
        component: () => import('@/views/project-review/index.vue'),
        meta: { title: '项目评审', icon: 'View' }
      },
      {
        path: '/project-review/:id/detail',
        name: 'ProjectReviewDetail',
        component: () => import('@/views/project-review/detail.vue'),
        meta: { title: '项目评审详情', hidden: true }
      },
      {
        path: '/review',
        name: 'Review',
        component: () => import('@/views/review/index.vue'),
        meta: { title: '项目评审', icon: 'Edit' }
      },
      {
        path: '/review/:id/detail',
        name: 'ReviewDetail',
        component: () => import('@/views/review/detail.vue'),
        meta: { title: '项目评审详情', hidden: true }
      },
      {
        path: '/competition-promotion',
        name: 'CompetitionPromotion',
        component: () => import('@/views/competition-promotion/index.vue'),
        meta: { title: '比赛晋级', icon: 'Promotion' }
      },
      {
        path: '/test/graphql',
        name: 'GraphQLTest',
        component: () => import('@/views/test/graphql-test.vue'),
        meta: { title: 'GraphQL测试', icon: 'Connection' }
      },
      {
        path: '/test/user-prefill',
        name: 'TestUserPrefill',
        component: () => import('@/pages/TestUserPrefill.vue'),
        meta: { title: '用户信息预填充测试', icon: 'User' }
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index.vue'),
    meta: { title: '登录' }
  }
]
 
const router = createRouter({
  history: createWebHashHistory(),
  routes
})
 
// 路由守卫
router.beforeEach((to, from, next) => {
  // 如果是登录页面,直接放行
  if (to.path === '/login') {
    // 如果已经登录,重定向到首页
    if (isLoggedIn()) {
      next('/')
    } else {
      next()
    }
    return
  }
 
  // 检查是否已登录
  if (!isLoggedIn()) {
    // 未登录,重定向到登录页
    next('/login')
    return
  }
 
  // 已登录,正常访问
  next()
})
 
export default router