Commit da2d88a984dc308b929fac0fbeeae34a53d5f573

Authored by Vben
1 parent 50915c97

wip(menu): add hideChildrenInMenu option

package.json
... ... @@ -108,7 +108,7 @@
108 108 "stylelint-order": "^4.1.0",
109 109 "ts-node": "^9.1.1",
110 110 "typescript": "4.2.3",
111   - "vite": "2.1.1",
  111 + "vite": "2.0.5",
112 112 "vite-plugin-compression": "^0.2.3",
113 113 "vite-plugin-html": "^2.0.3",
114 114 "vite-plugin-imagemin": "^0.2.9",
... ...
src/components/Menu/src/components/BasicSubMenuItem.vue
... ... @@ -39,6 +39,7 @@
39 39 const getShowMenu = computed(() => !props.item.meta?.hideMenu);
40 40 function menuHasChildren(menuTreeItem: MenuType): boolean {
41 41 return (
  42 + !menuTreeItem.meta?.hideChildrenInMenu &&
42 43 Reflect.has(menuTreeItem, 'children') &&
43 44 !!menuTreeItem.children &&
44 45 menuTreeItem.children.length > 0
... ...
src/components/SimpleMenu/src/SimpleSubMenu.vue
... ... @@ -91,6 +91,7 @@
91 91  
92 92 function menuHasChildren(menuTreeItem: Menu): boolean {
93 93 return (
  94 + !menuTreeItem.meta?.hideChildrenInMenu &&
94 95 Reflect.has(menuTreeItem, 'children') &&
95 96 !!menuTreeItem.children &&
96 97 menuTreeItem.children.length > 0
... ...
src/layouts/default/header/components/Breadcrumb.vue
... ... @@ -54,7 +54,13 @@
54 54 watchEffect(async () => {
55 55 if (currentRoute.value.name === REDIRECT_NAME) return;
56 56 const menus = await getMenus();
57   - const path = currentRoute.value.path;
  57 + const routeMatched = currentRoute.value.matched;
  58 + const cur = routeMatched?.[routeMatched.length - 1];
  59 + let path = currentRoute.value.path;
  60 +
  61 + if (cur && cur?.meta?.currentActiveMenu) {
  62 + path = cur.meta.currentActiveMenu as string;
  63 + }
58 64  
59 65 const parent = getAllParentPath(menus, path);
60 66  
... ... @@ -70,27 +76,23 @@
70 76 (item) => item.path !== PageEnum.BASE_HOME
71 77 );
72 78  
73   - // if (filterBreadcrumbList.length === breadcrumbList.length) {
74   - // filterBreadcrumbList.unshift(({
75   - // path: PageEnum.BASE_HOME,
76   - // meta: {
77   - // title: t('layout.header.home'),
78   - // isLink: true,
79   - // },
80   - // } as unknown) as RouteLocationMatched);
81   - // }
82   -
83 79 if (currentRoute.value.meta?.currentActiveMenu) {
84   - filterBreadcrumbList.push((currentRoute.value as unknown) as RouteLocationMatched);
  80 + filterBreadcrumbList.push(({
  81 + ...currentRoute.value,
  82 + name: currentRoute.value.meta?.title || currentRoute.value.name,
  83 + } as unknown) as RouteLocationMatched);
85 84 }
86   - routes.value = subRouteExtraction(filterBreadcrumbList);
  85 + routes.value = filterBreadcrumbList;
87 86 });
88 87  
89 88 function getMatched(menus: Menu[], parent: string[]) {
90 89 const metched: Menu[] = [];
91 90 menus.forEach((item) => {
92 91 if (parent.includes(item.path)) {
93   - metched.push(item);
  92 + metched.push({
  93 + ...item,
  94 + name: item.meta?.title || item.name,
  95 + });
94 96 }
95 97 if (item.children?.length) {
96 98 metched.push(...getMatched(item.children, parent));
... ... @@ -99,22 +101,6 @@
99 101 return metched;
100 102 }
101 103  
102   - function subRouteExtraction(routeList: RouteLocationMatched[]) {
103   - const resultRoutes: RouteLocationMatched[] = [];
104   - routeList.forEach((route) => {
105   - if (route.children?.length === 1) {
106   - const subRoute = route.children[0] as RouteLocationMatched;
107   - const subRouteName = subRoute.name as string;
108   - const routeName = route.name;
109   - if (subRouteName && `${subRouteName}Parent` === routeName) {
110   - route = subRoute;
111   - }
112   - }
113   - resultRoutes.push(route);
114   - });
115   - return resultRoutes;
116   - }
117   -
118 104 function filterItem(list: RouteLocationMatched[]) {
119 105 let resultList = filter(list, (item) => {
120 106 const { meta } = item;
... ...
src/layouts/default/header/index.less
... ... @@ -67,7 +67,7 @@
67 67 .@{header-trigger-prefix-cls} {
68 68 display: flex;
69 69 height: 100%;
70   - padding: 1px 10px 0 16px;
  70 + padding: 1px 10px 0 10px;
71 71 cursor: pointer;
72 72 align-items: center;
73 73  
... ...
src/router/routes/modules/dashboard.ts
... ... @@ -11,6 +11,7 @@ const dashboard: AppRouteModule = {
11 11 meta: {
12 12 icon: 'ion:grid-outline',
13 13 title: t('routes.dashboard.dashboard'),
  14 + hideChildrenInMenu: true,
14 15 },
15 16 children: [
16 17 {
... ...
src/router/routes/modules/demo/feat.ts
... ... @@ -81,7 +81,7 @@ const feat: AppRouteModule = {
81 81 component: () => import('/@/views/demo/feat/breadcrumb/ChildrenList.vue'),
82 82 meta: {
83 83 title: t('routes.demo.feat.breadcrumbChildren'),
84   - hideBreadcrumb: true,
  84 + // hideBreadcrumb: true,
85 85 },
86 86 },
87 87 {
... ...
src/router/types.ts
... ... @@ -30,6 +30,9 @@ export interface RouteMeta {
30 30 // Whether the route has been dynamically added
31 31 hideBreadcrumb?: boolean;
32 32  
  33 + // Hide submenu
  34 + hideChildrenInMenu?: boolean;
  35 +
33 36 // Carrying parameters
34 37 carryParam?: boolean;
35 38  
... ...
src/settings/designSetting.ts
... ... @@ -31,8 +31,8 @@ export const HEADER_PRESET_BG_COLOR_LIST: string[] = [
31 31  
32 32 // sider preset color
33 33 export const SIDE_BAR_BG_COLOR_LIST: string[] = [
34   - '#273352',
35 34 '#001529',
  35 + '#273352',
36 36 '#ffffff',
37 37 '#191b24',
38 38 '#191a23',
... ...
yarn.lock
... ... @@ -4734,7 +4734,7 @@ esbuild-register@^2.2.0:
4734 4734 dependencies:
4735 4735 jsonc-parser "^3.0.0"
4736 4736  
4737   -esbuild@^0.8.57:
  4737 +esbuild@^0.8.52, esbuild@^0.8.57:
4738 4738 version "0.8.57"
4739 4739 resolved "https://registry.npmjs.org/esbuild/-/esbuild-0.8.57.tgz#a42d02bc2b57c70bcd0ef897fe244766bb6dd926"
4740 4740 integrity sha512-j02SFrUwFTRUqiY0Kjplwjm1psuzO1d6AjaXKuOR9hrY0HuPsT6sV42B6myW34h1q4CRy+Y3g4RU/cGJeI/nNA==
... ... @@ -11634,12 +11634,12 @@ vite-plugin-windicss@0.8.4:
11634 11634 "@windicss/plugin-utils" "0.8.4"
11635 11635 windicss "^2.4.5"
11636 11636  
11637   -vite@2.1.1:
11638   - version "2.1.1"
11639   - resolved "https://registry.npmjs.org/vite/-/vite-2.1.1.tgz#13c7a7a5665b435f28fe8549caab181e0ad9af7b"
11640   - integrity sha512-nlTQrfYIkahcElD8O/oogbLbuKgAZRbvoFOth3GmRSglfPdY4RgfBjj0Fu7HeCU/2u3Jxc6jW4UuV22LGw1Yaw==
  11637 +vite@2.0.5:
  11638 + version "2.0.5"
  11639 + resolved "https://registry.npmjs.org/vite/-/vite-2.0.5.tgz#ac46857a3fa8686d077921e61bd48a986931df1d"
  11640 + integrity sha512-QTgEDbq1WsTtr6j+++ewjhBFEk6c8v0xz4fb/OWJQKNYU8ZZtphOshwOqAlnarSstPBtWCBR0tsugXx6ajfoUg==
11641 11641 dependencies:
11642   - esbuild "^0.9.2"
  11642 + esbuild "^0.8.52"
11643 11643 postcss "^8.2.1"
11644 11644 resolve "^1.19.0"
11645 11645 rollup "^2.38.5"
... ...