feat(route): add hideChildrenInMenu option close #346

This commit is contained in:
Vben
2021-03-18 21:13:15 +08:00
parent f55ad2f90a
commit b67cf22dfc
11 changed files with 43 additions and 70 deletions

View File

@@ -13,11 +13,15 @@ export function getAllParentPath<T = Recordable>(treeData: T[], path: string) {
function joinParentPath(menus: Menu[], parentPath = '') {
for (let index = 0; index < menus.length; index++) {
const menu = menus[index];
const p = menu.path.startsWith('/') ? menu.path : `/${menu.path}`;
const parent = isUrl(menu.path) ? menu.path : `${parentPath}${p}`;
menus[index].path = parent;
// https://next.router.vuejs.org/guide/essentials/nested-routes.html
// Note that nested paths that start with / will be treated as a root path.
// This allows you to leverage the component nesting without having to use a nested URL.
if (!(menu.path.startsWith('/') || isUrl(menu.path))) {
// path doesn't start with /, nor is it a url, join parent path
menu.path = `${parentPath}/${menu.path}`;
}
if (menu?.children?.length) {
joinParentPath(menu.children, parent);
joinParentPath(menu.children, menu.path);
}
}
}

View File

@@ -66,9 +66,9 @@ export async function getShallowMenus(): Promise<Menu[]> {
// Get the children of the menu
export async function getChildrenMenus(parentPath: string) {
const menus = await getAsyncMenus();
const menus = await getMenus();
const parent = menus.find((item) => item.path === parentPath);
if (!parent || !parent.children) return [] as Menu[];
if (!parent || !parent.children || !!parent?.meta?.hideChildrenInMenu) return [] as Menu[];
const routes = router.getRoutes();
return !isBackMode() ? filter(parent.children, basicFilter(routes)) : parent.children;

View File

@@ -11,7 +11,6 @@ const dashboard: AppRouteModule = {
meta: {
icon: 'ion:grid-outline',
title: t('routes.dashboard.dashboard'),
hideChildrenInMenu: true,
},
children: [
{