hejianhao
2025-05-09 a982b6de0096cebfe51629c34d77b111bdee2f79
culture/src/router/index.js
@@ -26,7 +26,7 @@
const routes = [
    {
        path: "/",
        redirect: "/projectList/list",
        redirect: "/login",
    },
    {
        path: "/login",
@@ -48,7 +48,7 @@
                path: "list",
                name: "ProjectList",
                meta: {
                    title: "项目组管理",
                    title: "菌种库项目组管理",
                },
                component: () => import("../views/projectList"),
            },
@@ -56,7 +56,7 @@
                path: "addProject",
                name: "AddProject",
                meta: {
                    title: "新增项目组",
                    title: "新增菌种库项目组",
                    hide: true,
                    keepAlive: true,
                },
@@ -345,17 +345,28 @@
    document.title = to.meta.title || '实验室流程';
    // 登录验证
    // if (to.path === "/login") {
    //     sessionStorage.removeItem('userInfo')
    //     next()
    // } else if (!sessionStorage.getItem('userInfo')) {
    //     next('/login')
    // } else {
    //     // 判断是否拥有要跳转菜单权限
    //     let menus = store.state.menus
    //     if (to.meta.hasOwnProperty('privilege') && !menus.includes(to.meta.privilege)) {
    //         return
    //     }
    // 排除登录页的校验
    if (to.path === "/login") {
        if (sessionStorage.getItem('token')) {
            next('/projectList');  // 已登录状态访问登录页时重定向到系统首页
            return;
        }
        next();
        return;
    }
    // 登录状态校验
    const isAuthenticated = sessionStorage.getItem('token');
    // if (!isAuthenticated) {
    //     next('/login');  // 未登录用户重定向到登录页
    //     return;
    // }
    // 判断是否拥有要跳转菜单权限
    let menus = store.state.menus
    if (to.meta.hasOwnProperty('privilege') && !menus.includes(to.meta.privilege)) {
        return
    }
    // 设置标签列表
    if (!to.meta.hide || !to.meta.oneself) {
@@ -367,7 +378,8 @@
            const tagInfo = {
                path: to.path,
                name: to.name,
                meta: to.meta
                meta: to.meta,
                query: to.query,
            }
            tagList.push(tagInfo)
            sessionStorage.setItem('tagList', JSON.stringify(tagList))
@@ -388,7 +400,6 @@
    }
    next()
    // }
});
export default router;