菜单修复

This commit is contained in:
陈红丽 2024-08-06 16:19:23 +08:00
parent f7b5247e0c
commit e21b444cdb
4 changed files with 33 additions and 8 deletions

View File

@ -385,7 +385,8 @@
//
const closeAll = () => {
tabsViewStore.closeAllTabs();
router.replace(PageEnum.BASE_HOME_REDIRECT);
router.replace(storage.get('FIRST-PATH'));
// router.replace(PageEnum.BASE_HOME_REDIRECT);
updateNavScroll();
};

View File

@ -164,3 +164,10 @@ export const dynamicImport = (
return;
}
};
/**
*
* */
export const findFirstRoutePath = (routes)=>{
return routes[0].redirect?routes[0].redirect:routes[0].path
}

View File

@ -6,6 +6,8 @@ import { ACCESS_TOKEN } from '@/store/mutation-types';
import { storage } from '@/utils/Storage';
import { PageEnum } from '@/enums/pageEnum';
import { ErrorPageRoute,AboutPageRoute } from '@/router/base';
import { findFirstRoutePath } from '@/router/generator-routers';
import {findTreeByPath} from "@/utils/auth";
import NProgress from 'nprogress';
const LOGIN_PATH = PageEnum.BASE_LOGIN;
@ -17,10 +19,6 @@ export function createRouterGuards(router: Router) {
const asyncRouteStore = useAsyncRouteStoreWidthOut();
router.beforeEach(async (to, from, next) => {
NProgress.start();
if (from.path === LOGIN_PATH && to.name === 'errorPage') {
next(PageEnum.BASE_HOME);
return;
}
// Whitelist can be directly entered
if (whitePathList.includes(to.path as PageEnum)) {
@ -64,15 +62,20 @@ export function createRouterGuards(router: Router) {
routes.forEach((item) => {
router.addRoute(item as unknown as RouteRecordRaw);
});
//添加404
const isErrorPage = router.getRoutes().findIndex((item) => item.name === ErrorPageRoute.name);
if (isErrorPage === -1) {
router.addRoute(ErrorPageRoute as unknown as RouteRecordRaw);
}
router.addRoute(AboutPageRoute as unknown as RouteRecordRaw);
const redirectPath = (from.query.redirect || to.path) as string;
const firstRoutePath = findFirstRoutePath(routes)
storage.set('FIRST-PATH',firstRoutePath)
if (from.path === LOGIN_PATH && (to.name === 'errorPage' || !to.name)) {
next(firstRoutePath);
return;
}
let formPath = findTreeByPath(routes,from.query.redirect).length > 0 ? from.query.redirect:to.path
const redirectPath = (formPath) as string;
const redirect = decodeURIComponent(redirectPath);
const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect };
asyncRouteStore.setDynamicAddedRoute(true);

View File

@ -175,6 +175,20 @@ export const buildTree =(array)=> {
}
});
return result;
}
/***
*
*/
export const findTreeByPath =(tree, path, result = []) =>{
for (const node of tree) {
if (node.path === path) {
result.push(node);
}
if (node.children && node.children.length > 0) {
findTreeByPath(node.children, path, result);
}
}
return result;
}
export const getComponentName = (route: RouteLocationNormalized) => {