|
@@ -46,6 +46,7 @@ export const adminRoutes:RouteRecordRaw[] = [
|
|
|
path: '/admin',
|
|
path: '/admin',
|
|
|
name: 'adminLayout',
|
|
name: 'adminLayout',
|
|
|
component: AdminLayout,
|
|
component: AdminLayout,
|
|
|
|
|
+ redirect: '/admin/problems',
|
|
|
children:[
|
|
children:[
|
|
|
{
|
|
{
|
|
|
path: '/admin/users',
|
|
path: '/admin/users',
|
|
@@ -56,20 +57,10 @@ export const adminRoutes:RouteRecordRaw[] = [
|
|
|
icon: User,
|
|
icon: User,
|
|
|
requiresAdmin: true
|
|
requiresAdmin: true
|
|
|
}
|
|
}
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- path:'/admin/other',
|
|
|
|
|
- name:'other',
|
|
|
|
|
- component: AdminLayout,
|
|
|
|
|
- meta:{
|
|
|
|
|
- title: '其他',
|
|
|
|
|
- icon: Menu,
|
|
|
|
|
- requiresAdmin: true
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
],
|
|
],
|
|
|
meta: {
|
|
meta: {
|
|
|
- requiresAdmin: true
|
|
|
|
|
|
|
+ requiresCoach: true
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
]
|
|
]
|
|
@@ -87,12 +78,23 @@ const router : Router = createRouter({
|
|
|
],
|
|
],
|
|
|
});
|
|
});
|
|
|
router.beforeEach((to, _from, next) => {
|
|
router.beforeEach((to, _from, next) => {
|
|
|
|
|
+ const loginUserStore = useLoginUserStore()
|
|
|
|
|
+ const role = loginUserStore.loginUser.user?.role
|
|
|
if (to.matched.some(record => record.meta.requiresAdmin)) {
|
|
if (to.matched.some(record => record.meta.requiresAdmin)) {
|
|
|
- const loginUserStore = useLoginUserStore()
|
|
|
|
|
if (!loginUserStore.loginUser.isLogin) {
|
|
if (!loginUserStore.loginUser.isLogin) {
|
|
|
ElMessage.warning('请先登录')
|
|
ElMessage.warning('请先登录')
|
|
|
next({path: '/login', query: {redirect: to.fullPath}})
|
|
next({path: '/login', query: {redirect: to.fullPath}})
|
|
|
- } else if (loginUserStore.loginUser.user?.role !== 'admin') {
|
|
|
|
|
|
|
+ } else if (role !== 'admin') {
|
|
|
|
|
+ ElMessage.error('无权访问')
|
|
|
|
|
+ next('/')
|
|
|
|
|
+ } else {
|
|
|
|
|
+ next()
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (to.matched.some(record => record.meta.requiresCoach)) {
|
|
|
|
|
+ if (!loginUserStore.loginUser.isLogin) {
|
|
|
|
|
+ ElMessage.warning('请先登录')
|
|
|
|
|
+ next({path: '/login', query: {redirect: to.fullPath}})
|
|
|
|
|
+ } else if (role !== 'admin' && role !== 'coach') {
|
|
|
ElMessage.error('无权访问')
|
|
ElMessage.error('无权访问')
|
|
|
next('/')
|
|
next('/')
|
|
|
} else {
|
|
} else {
|