Commit e49072c31339ba58473ffa883308cc3c2c4c43e9
1 parent
6883b21b
fix: ensure the breadcrumb level is correct
Showing
6 changed files
with
58 additions
and
46 deletions
build/vite/plugin/html.ts
@@ -7,7 +7,7 @@ import type { ViteEnv } from '../../utils'; | @@ -7,7 +7,7 @@ import type { ViteEnv } from '../../utils'; | ||
7 | 7 | ||
8 | import html from 'vite-plugin-html'; | 8 | import html from 'vite-plugin-html'; |
9 | 9 | ||
10 | -import pkg from '../../../package.json'; | 10 | +import pkg from './package.json'; |
11 | import { GLOB_CONFIG_FILE_NAME } from '../../constant'; | 11 | import { GLOB_CONFIG_FILE_NAME } from '../../constant'; |
12 | 12 | ||
13 | export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) { | 13 | export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) { |
package.json
@@ -108,7 +108,7 @@ | @@ -108,7 +108,7 @@ | ||
108 | "stylelint-order": "^4.1.0", | 108 | "stylelint-order": "^4.1.0", |
109 | "ts-node": "^9.1.1", | 109 | "ts-node": "^9.1.1", |
110 | "typescript": "4.2.3", | 110 | "typescript": "4.2.3", |
111 | - "vite": "2.0.5", | 111 | + "vite": "2.1.1", |
112 | "vite-plugin-compression": "^0.2.3", | 112 | "vite-plugin-compression": "^0.2.3", |
113 | "vite-plugin-html": "^2.0.3", | 113 | "vite-plugin-html": "^2.0.3", |
114 | "vite-plugin-imagemin": "^0.2.9", | 114 | "vite-plugin-imagemin": "^0.2.9", |
src/components/Application/src/search/AppSearchModal.vue
@@ -259,6 +259,12 @@ | @@ -259,6 +259,12 @@ | ||
259 | box-shadow: 0 1px 3px 0 #d4d9e1; | 259 | box-shadow: 0 1px 3px 0 #d4d9e1; |
260 | align-items: center; | 260 | align-items: center; |
261 | 261 | ||
262 | + > div:first-child, | ||
263 | + > div:last-child { | ||
264 | + display: flex; | ||
265 | + align-items: center; | ||
266 | + } | ||
267 | + | ||
262 | &--active { | 268 | &--active { |
263 | color: #fff; | 269 | color: #fff; |
264 | background: @primary-color; | 270 | background: @primary-color; |
src/layouts/default/header/components/Breadcrumb.vue
@@ -4,10 +4,10 @@ | @@ -4,10 +4,10 @@ | ||
4 | <template #itemRender="{ route, routes, paths }"> | 4 | <template #itemRender="{ route, routes, paths }"> |
5 | <Icon :icon="route.meta.icon" v-if="getShowBreadCrumbIcon && route.meta.icon" /> | 5 | <Icon :icon="route.meta.icon" v-if="getShowBreadCrumbIcon && route.meta.icon" /> |
6 | <span v-if="!hasRedirect(routes, route)"> | 6 | <span v-if="!hasRedirect(routes, route)"> |
7 | - {{ t(route.meta.title) }} | 7 | + {{ t(route.name || route.meta.title) }} |
8 | </span> | 8 | </span> |
9 | <router-link v-else to="" @click="handleClick(route, paths, $event)"> | 9 | <router-link v-else to="" @click="handleClick(route, paths, $event)"> |
10 | - {{ t(route.meta.title) }} | 10 | + {{ t(route.name || route.meta.title) }} |
11 | </router-link> | 11 | </router-link> |
12 | </template> | 12 | </template> |
13 | </a-breadcrumb> | 13 | </a-breadcrumb> |
@@ -15,26 +15,29 @@ | @@ -15,26 +15,29 @@ | ||
15 | </template> | 15 | </template> |
16 | <script lang="ts"> | 16 | <script lang="ts"> |
17 | import type { RouteLocationMatched } from 'vue-router'; | 17 | import type { RouteLocationMatched } from 'vue-router'; |
18 | + import type { Menu } from '/@/router/types'; | ||
18 | 19 | ||
19 | - import { defineComponent, ref, toRaw, watchEffect } from 'vue'; | ||
20 | - import { Breadcrumb } from 'ant-design-vue'; | 20 | + import { defineComponent, ref, watchEffect } from 'vue'; |
21 | 21 | ||
22 | - import { useRouter } from 'vue-router'; | ||
23 | - import { filter } from '/@/utils/helper/treeHelper'; | ||
24 | - import { REDIRECT_NAME } from '/@/router/constant'; | 22 | + import { Breadcrumb } from 'ant-design-vue'; |
25 | import Icon from '/@/components/Icon'; | 23 | import Icon from '/@/components/Icon'; |
26 | 24 | ||
27 | import { PageEnum } from '/@/enums/pageEnum'; | 25 | import { PageEnum } from '/@/enums/pageEnum'; |
28 | 26 | ||
29 | import { useDesign } from '/@/hooks/web/useDesign'; | 27 | import { useDesign } from '/@/hooks/web/useDesign'; |
30 | import { useRootSetting } from '/@/hooks/setting/useRootSetting'; | 28 | import { useRootSetting } from '/@/hooks/setting/useRootSetting'; |
29 | + import { useGo } from '/@/hooks/web/usePage'; | ||
30 | + import { useI18n } from '/@/hooks/web/useI18n'; | ||
31 | + import { useRouter } from 'vue-router'; | ||
31 | 32 | ||
32 | import { propTypes } from '/@/utils/propTypes'; | 33 | import { propTypes } from '/@/utils/propTypes'; |
33 | - import { useGo } from '/@/hooks/web/usePage'; | ||
34 | import { isString } from '/@/utils/is'; | 34 | import { isString } from '/@/utils/is'; |
35 | - import { useI18n } from '/@/hooks/web/useI18n'; | 35 | + import { filter } from '/@/utils/helper/treeHelper'; |
36 | import { getMenus } from '/@/router/menus'; | 36 | import { getMenus } from '/@/router/menus'; |
37 | 37 | ||
38 | + import { REDIRECT_NAME } from '/@/router/constant'; | ||
39 | + import { getAllParentPath } from '/@/router/helper/menuHelper'; | ||
40 | + | ||
38 | export default defineComponent({ | 41 | export default defineComponent({ |
39 | name: 'LayoutBreadcrumb', | 42 | name: 'LayoutBreadcrumb', |
40 | components: { Icon, [Breadcrumb.name]: Breadcrumb }, | 43 | components: { Icon, [Breadcrumb.name]: Breadcrumb }, |
@@ -50,25 +53,32 @@ | @@ -50,25 +53,32 @@ | ||
50 | const { t } = useI18n(); | 53 | const { t } = useI18n(); |
51 | watchEffect(async () => { | 54 | watchEffect(async () => { |
52 | if (currentRoute.value.name === REDIRECT_NAME) return; | 55 | if (currentRoute.value.name === REDIRECT_NAME) return; |
56 | + const menus = await getMenus(); | ||
57 | + const path = currentRoute.value.path; | ||
58 | + | ||
59 | + const parent = getAllParentPath(menus, path); | ||
60 | + | ||
61 | + const filterMenus = menus.filter((item) => item.path === parent[0]); | ||
62 | + | ||
63 | + const matched = getMatched(filterMenus, parent) as any; | ||
53 | 64 | ||
54 | - const matched = currentRoute.value?.matched; | ||
55 | if (!matched || matched.length === 0) return; | 65 | if (!matched || matched.length === 0) return; |
56 | 66 | ||
57 | - let breadcrumbList = filterItem(toRaw(matched)); | 67 | + let breadcrumbList = filterItem(matched); |
58 | 68 | ||
59 | const filterBreadcrumbList = breadcrumbList.filter( | 69 | const filterBreadcrumbList = breadcrumbList.filter( |
60 | (item) => item.path !== PageEnum.BASE_HOME | 70 | (item) => item.path !== PageEnum.BASE_HOME |
61 | ); | 71 | ); |
62 | 72 | ||
63 | - if (filterBreadcrumbList.length === breadcrumbList.length) { | ||
64 | - filterBreadcrumbList.unshift(({ | ||
65 | - path: PageEnum.BASE_HOME, | ||
66 | - meta: { | ||
67 | - title: t('layout.header.home'), | ||
68 | - isLink: true, | ||
69 | - }, | ||
70 | - } as unknown) as RouteLocationMatched); | ||
71 | - } | 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 | + // } | ||
72 | 82 | ||
73 | if (currentRoute.value.meta?.currentActiveMenu) { | 83 | if (currentRoute.value.meta?.currentActiveMenu) { |
74 | filterBreadcrumbList.push((currentRoute.value as unknown) as RouteLocationMatched); | 84 | filterBreadcrumbList.push((currentRoute.value as unknown) as RouteLocationMatched); |
@@ -76,6 +86,19 @@ | @@ -76,6 +86,19 @@ | ||
76 | routes.value = subRouteExtraction(filterBreadcrumbList); | 86 | routes.value = subRouteExtraction(filterBreadcrumbList); |
77 | }); | 87 | }); |
78 | 88 | ||
89 | + function getMatched(menus: Menu[], parent: string[]) { | ||
90 | + const metched: Menu[] = []; | ||
91 | + menus.forEach((item) => { | ||
92 | + if (parent.includes(item.path)) { | ||
93 | + metched.push(item); | ||
94 | + } | ||
95 | + if (item.children?.length) { | ||
96 | + metched.push(...getMatched(item.children, parent)); | ||
97 | + } | ||
98 | + }); | ||
99 | + return metched; | ||
100 | + } | ||
101 | + | ||
79 | function subRouteExtraction(routeList: RouteLocationMatched[]) { | 102 | function subRouteExtraction(routeList: RouteLocationMatched[]) { |
80 | const resultRoutes: RouteLocationMatched[] = []; | 103 | const resultRoutes: RouteLocationMatched[] = []; |
81 | routeList.forEach((route) => { | 104 | routeList.forEach((route) => { |
@@ -112,22 +135,9 @@ | @@ -112,22 +135,9 @@ | ||
112 | 135 | ||
113 | function handleClick(route: RouteLocationMatched, paths: string[], e: Event) { | 136 | function handleClick(route: RouteLocationMatched, paths: string[], e: Event) { |
114 | e?.preventDefault(); | 137 | e?.preventDefault(); |
115 | - const { | ||
116 | - children, | ||
117 | - redirect, | ||
118 | - meta, | ||
119 | - | ||
120 | - // components | ||
121 | - } = route; | ||
122 | - | ||
123 | - // const isParent = | ||
124 | - // components?.default?.name === 'DefaultLayout' || (components?.default as any)?.parentView; | ||
125 | - | ||
126 | - if ( | ||
127 | - children?.length && | ||
128 | - !redirect | ||
129 | - // && !isParent | ||
130 | - ) { | 138 | + const { children, redirect, meta } = route; |
139 | + | ||
140 | + if (children?.length && !redirect) { | ||
131 | e?.stopPropagation(); | 141 | e?.stopPropagation(); |
132 | return; | 142 | return; |
133 | } | 143 | } |
@@ -145,8 +155,7 @@ | @@ -145,8 +155,7 @@ | ||
145 | } else { | 155 | } else { |
146 | const ps = paths.slice(1); | 156 | const ps = paths.slice(1); |
147 | const lastPath = ps.pop() || ''; | 157 | const lastPath = ps.pop() || ''; |
148 | - const parentPath = ps.pop() || ''; | ||
149 | - goPath = `${parentPath}/${lastPath}`; | 158 | + goPath = `${lastPath}`; |
150 | } | 159 | } |
151 | goPath = /^\//.test(goPath) ? goPath : `/${goPath}`; | 160 | goPath = /^\//.test(goPath) ? goPath : `/${goPath}`; |
152 | go(goPath); | 161 | go(goPath); |
@@ -157,11 +166,6 @@ | @@ -157,11 +166,6 @@ | ||
157 | if (routes.indexOf(route) === routes.length - 1) { | 166 | if (routes.indexOf(route) === routes.length - 1) { |
158 | return false; | 167 | return false; |
159 | } | 168 | } |
160 | - | ||
161 | - // if (route?.meta?.isLink) { | ||
162 | - // return true; | ||
163 | - // } | ||
164 | - | ||
165 | return true; | 169 | return true; |
166 | } | 170 | } |
167 | 171 |
src/router/types.ts
yarn.lock
@@ -11634,7 +11634,7 @@ vite-plugin-windicss@0.8.3: | @@ -11634,7 +11634,7 @@ vite-plugin-windicss@0.8.3: | ||
11634 | "@windicss/plugin-utils" "0.8.3" | 11634 | "@windicss/plugin-utils" "0.8.3" |
11635 | windicss "^2.4.5" | 11635 | windicss "^2.4.5" |
11636 | 11636 | ||
11637 | -vite@^2.1.1: | 11637 | +vite@2.1.1: |
11638 | version "2.1.1" | 11638 | version "2.1.1" |
11639 | resolved "https://registry.npmjs.org/vite/-/vite-2.1.1.tgz#13c7a7a5665b435f28fe8549caab181e0ad9af7b" | 11639 | resolved "https://registry.npmjs.org/vite/-/vite-2.1.1.tgz#13c7a7a5665b435f28fe8549caab181e0ad9af7b" |
11640 | integrity sha512-nlTQrfYIkahcElD8O/oogbLbuKgAZRbvoFOth3GmRSglfPdY4RgfBjj0Fu7HeCU/2u3Jxc6jW4UuV22LGw1Yaw== | 11640 | integrity sha512-nlTQrfYIkahcElD8O/oogbLbuKgAZRbvoFOth3GmRSglfPdY4RgfBjj0Fu7HeCU/2u3Jxc6jW4UuV22LGw1Yaw== |