|
@@ -11,6 +11,8 @@ import {
|
|
|
Menu,
|
|
Menu,
|
|
|
User,
|
|
User,
|
|
|
} from '@element-plus/icons-vue'
|
|
} from '@element-plus/icons-vue'
|
|
|
|
|
+import {useLoginUserStore} from "../store";
|
|
|
|
|
+import {ElMessage} from "element-plus";
|
|
|
|
|
|
|
|
export const userRoutes:RouteRecordRaw[] = [
|
|
export const userRoutes:RouteRecordRaw[] = [
|
|
|
{
|
|
{
|
|
@@ -51,7 +53,8 @@ export const adminRoutes:RouteRecordRaw[] = [
|
|
|
component: UserView,
|
|
component: UserView,
|
|
|
meta:{
|
|
meta:{
|
|
|
title: '用户管理',
|
|
title: '用户管理',
|
|
|
- icon: User
|
|
|
|
|
|
|
+ icon: User,
|
|
|
|
|
+ requiresAdmin: true
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
@@ -60,10 +63,14 @@ export const adminRoutes:RouteRecordRaw[] = [
|
|
|
component: AdminLayout,
|
|
component: AdminLayout,
|
|
|
meta:{
|
|
meta:{
|
|
|
title: '其他',
|
|
title: '其他',
|
|
|
- icon: Menu
|
|
|
|
|
|
|
+ icon: Menu,
|
|
|
|
|
+ requiresAdmin: true
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- ]
|
|
|
|
|
|
|
+ ],
|
|
|
|
|
+ meta: {
|
|
|
|
|
+ requiresAdmin: true
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
]
|
|
]
|
|
|
|
|
|
|
@@ -79,4 +86,21 @@ const router : Router = createRouter({
|
|
|
...adminRoutes
|
|
...adminRoutes
|
|
|
],
|
|
],
|
|
|
});
|
|
});
|
|
|
|
|
+router.beforeEach((to, _from, next) => {
|
|
|
|
|
+ if (to.matched.some(record => record.meta.requiresAdmin)) {
|
|
|
|
|
+ const loginUserStore = useLoginUserStore()
|
|
|
|
|
+ if (!loginUserStore.loginUser.isLogin) {
|
|
|
|
|
+ ElMessage.warning('请先登录')
|
|
|
|
|
+ next({path: '/login', query: {redirect: to.fullPath}})
|
|
|
|
|
+ } else if (loginUserStore.loginUser.user?.role !== 'admin') {
|
|
|
|
|
+ ElMessage.error('无权访问')
|
|
|
|
|
+ next('/')
|
|
|
|
|
+ } else {
|
|
|
|
|
+ next()
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ next()
|
|
|
|
|
+ }
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
export default router
|
|
export default router
|