1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee
Files
epp/frontend/src/router/index.ts

104 lines
2.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
import { usePermissStore } from '../store/permiss';
import Home from '../views/home.vue';
import settings from '../utils/settings'
const routes: RouteRecordRaw[] = [
{
path: '/',
redirect: '/dashboard',
},
{
path: '/',
name: 'Home',
component: Home,
children: [
{
path: '/dashboard',
name: 'dashboard',
meta: {
title: '系统首页',
permiss: 'dashboard',
},
component: () => import('../views/dashboard.vue'),
},
{
path: '/shop-good-setting',
name: 'shop-good-setting',
meta: {
title: '商品管理',
permiss: 'shop-good-setting',
},
component: () => import('../views/shop-good-setting.vue'),
},
{
path: '/privilege-user-setting',
name: 'privilege-user-setting',
meta: {
title: '用户管理',
permiss: 'privilege-user-setting',
},
component: () => import('../views/privilege-user-setting.vue'),
},
{
path: '/user',
name: 'user',
meta: {
title: '个人中心',
},
component: () => import('../views/user.vue'),
},
],
},
{
path: '/login',
name: 'Login',
meta: {
title: '登录',
},
component: () => import('../views/login.vue'),
},
{
path: '/403',
name: '403',
meta: {
title: '没有权限',
},
component: () => import('../views/error-page/403.vue'),
},
];
const router = createRouter({
history: createWebHashHistory(),
routes,
});
router.beforeEach((to, from, next) => {
document.title = `${to.meta.title} | ${settings.siteTitle}`;
const username = localStorage.getItem('ms_username');
const roleId = localStorage.getItem('ms_role_id');
const permiss = usePermissStore();
const currentUserPermiss = permiss[roleId as string];
// console.log("currentUserPermiss", currentUserPermiss)
if (!username && to.path !== '/login') {
next({
path: '/login',
query: {
redirectTo: router.currentRoute.value.path // window.location.href
},
});
return
} else if (
to.meta.permiss &&
!(currentUserPermiss && currentUserPermiss.includes(to.meta.permiss as string))
) {
// 如果没有权限则进入403
next('/403');
return
} else {
next();
}
});
export default router;