Skip to content

Commit

Permalink
fixbug: 修复混合模式导航显示问题
Browse files Browse the repository at this point in the history
  • Loading branch information
jsxiaosi committed Jul 6, 2022
1 parent eab7afa commit 87e8ed8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/layouts/pageLayouts/components/Breadcrumb/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
// 获取每个父级路径对应的路由信息
parentRoutes.forEach((path) => {
if (path !== '/') {
matched.push(findRouteByPath(path, routes) as AppRouteRecordRaw);
matched.push(findRouteByPath(path, routes[0].children || []) as AppRouteRecordRaw);
}
});
const item = multiTabs.find((item) => {
Expand Down
4 changes: 2 additions & 2 deletions src/layouts/pageLayouts/components/Sidebar/MinSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
const resolvePath = (routeRaw: AppRouteRecordRaw): string => {
let path = routeRaw.path;
if (routeRaw.children && routeRaw.children.length) {
if (routeRaw.children && routeRaw.children.length && !routeRaw.children[0].hidden) {
path = routeRaw.children[0].path;
}
return path;
Expand All @@ -49,7 +49,7 @@
// 当前路由的父级路径
const parentRoutes = getParentPaths(path, wholeMenus)[0];
const routeByPath = findRouteByPath(parentRoutes, wholeMenus);
if (routeByPath?.children && routeByPath.children.length) {
if (routeByPath?.children && routeByPath.children.length && !routeByPath.children[0].hidden) {
return routeByPath.children[0].path;
}
return path;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { sidebarRouteList } from '@/router';
import { AppRouteRecordRaw } from '#/route';
import { findRouteByPath } from '@/router/utils';
import { emitter } from '@/utils/mitt';
import { useRouter } from 'vue-router';

export const useSelectMenu = () => {
const router = useRouter().options.routes as AppRouteRecordRaw[];
const selectMenu = (path: string) => {
const findRoute = findRouteByPath(path, sidebarRouteList);
const findRoute = findRouteByPath(path, router[0]?.children || []);
if (findRoute) {
if (findRoute.redirect && findRoute.children && findRoute.children.length) {
selectMenu(findRoute.children[0].path);
Expand Down
3 changes: 2 additions & 1 deletion src/layouts/pageLayouts/components/Sidebar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
// 当前路由的信息
const parenetRoute = findRouteByPath(parentPathArr[0], usePermissionStoreHook().wholeMenus);
if (parenetRoute) {
if (parenetRoute.children) subMenuData.value = parenetRoute.children;
if (parenetRoute.children && !parenetRoute.children[0].hidden)
subMenuData.value = parenetRoute.children;
else subMenuData.value = [parenetRoute];
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/router/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function privilegeRouting(routeList: RouteRecordRaw[], dataRouter: AppRouteRecor
dataRouter.forEach((i) => {
routeList[homeIndex].children?.push(i as RouteRecordRaw);
});
console.log('routeList[homeIndex]', routeList[homeIndex]);
router.addRoute(routeList[homeIndex]);
}
}
Expand Down Expand Up @@ -187,9 +188,11 @@ function getParentPaths(routePath: string, routes: AppRouteRecordRaw[]) {
// 查找对应path的路由信息
function findRouteByPath(path: string, routes: AppRouteRecordRaw[]): AppRouteRecordRaw | null {
const res = routes.find((item: { path: string }) => item.path == path) || null;
console.log(res);
if (res) {
return res;
} else {
console.log('什么情况下才走这里?');
for (let i = 0; i < routes.length; i++) {
if (routes[i].children instanceof Array && routes[i].children?.length) {
const miRes = findRouteByPath(path, routes[i].children as AppRouteRecordRaw[]);
Expand Down

0 comments on commit 87e8ed8

Please sign in to comment.