Commit e0dc5cf2f299fd4c1efdf4f00b9f0f72f07d5937
1 parent
d5d4c4b4
fix(breadcrumb): ensure that the single-level breadcrumbs jump correctly close #321
Showing
3 changed files
with
38 additions
and
16 deletions
CHANGELOG.zh_CN.md
@@ -21,6 +21,7 @@ | @@ -21,6 +21,7 @@ | ||
21 | - 修复树组件 demo 示例样式错误 | 21 | - 修复树组件 demo 示例样式错误 |
22 | - 修复账号管理新增未清空旧数据 | 22 | - 修复账号管理新增未清空旧数据 |
23 | - form 组件应允许 setFieldsValue 方法值为 null 或者 undefined | 23 | - form 组件应允许 setFieldsValue 方法值为 null 或者 undefined |
24 | +- 确保单级面包屑正确跳转 | ||
24 | 25 | ||
25 | ## 2.0.2 (2021-03-04) | 26 | ## 2.0.2 (2021-03-04) |
26 | 27 |
src/layouts/default/header/components/Breadcrumb.vue
@@ -72,10 +72,25 @@ | @@ -72,10 +72,25 @@ | ||
72 | if (currentRoute.value.meta?.currentActiveMenu) { | 72 | if (currentRoute.value.meta?.currentActiveMenu) { |
73 | filterBreadcrumbList.push((currentRoute.value as unknown) as RouteLocationMatched); | 73 | filterBreadcrumbList.push((currentRoute.value as unknown) as RouteLocationMatched); |
74 | } | 74 | } |
75 | - // routes.value = filterBreadcrumbList.length === 1 ? [] : filterBreadcrumbList; | ||
76 | - routes.value = filterBreadcrumbList; | 75 | + routes.value = subRouteExtraction(filterBreadcrumbList); |
77 | }); | 76 | }); |
78 | 77 | ||
78 | + function subRouteExtraction(routeList: RouteLocationMatched[]) { | ||
79 | + const resultRoutes: RouteLocationMatched[] = []; | ||
80 | + routeList.forEach((route) => { | ||
81 | + if (route.children?.length === 1) { | ||
82 | + const subRoute = route.children[0] as RouteLocationMatched; | ||
83 | + const subRouteName = subRoute.name as string; | ||
84 | + const routeName = route.name; | ||
85 | + if (subRouteName && `${subRouteName}Parent` === routeName) { | ||
86 | + route = subRoute; | ||
87 | + } | ||
88 | + } | ||
89 | + resultRoutes.push(route); | ||
90 | + }); | ||
91 | + return resultRoutes; | ||
92 | + } | ||
93 | + | ||
79 | function filterItem(list: RouteLocationMatched[]) { | 94 | function filterItem(list: RouteLocationMatched[]) { |
80 | let resultList = filter(list, (item) => { | 95 | let resultList = filter(list, (item) => { |
81 | const { meta } = item; | 96 | const { meta } = item; |
@@ -83,15 +98,14 @@ | @@ -83,15 +98,14 @@ | ||
83 | if (!meta) { | 98 | if (!meta) { |
84 | return false; | 99 | return false; |
85 | } | 100 | } |
101 | + | ||
86 | const { title, hideBreadcrumb, hideMenu } = meta; | 102 | const { title, hideBreadcrumb, hideMenu } = meta; |
87 | if (!title || hideBreadcrumb || hideMenu) { | 103 | if (!title || hideBreadcrumb || hideMenu) { |
88 | return false; | 104 | return false; |
89 | } | 105 | } |
90 | - | ||
91 | return true; | 106 | return true; |
92 | }).filter((item) => !item.meta?.hideBreadcrumb || !item.meta?.hideMenu); | 107 | }).filter((item) => !item.meta?.hideBreadcrumb || !item.meta?.hideMenu); |
93 | 108 | ||
94 | - // resultList = resultList.filter((item) => item.path !== PageEnum.BASE_HOME); | ||
95 | return resultList; | 109 | return resultList; |
96 | } | 110 | } |
97 | 111 | ||
@@ -101,7 +115,8 @@ | @@ -101,7 +115,8 @@ | ||
101 | children, | 115 | children, |
102 | redirect, | 116 | redirect, |
103 | meta, | 117 | meta, |
104 | - // components | 118 | + |
119 | + // components | ||
105 | } = route; | 120 | } = route; |
106 | 121 | ||
107 | // const isParent = | 122 | // const isParent = |
@@ -123,23 +138,29 @@ | @@ -123,23 +138,29 @@ | ||
123 | if (redirect && isString(redirect)) { | 138 | if (redirect && isString(redirect)) { |
124 | go(redirect); | 139 | go(redirect); |
125 | } else { | 140 | } else { |
126 | - const ps = paths.slice(1); | ||
127 | - const lastPath = ps.pop() || ''; | ||
128 | - const parentPath = ps.pop() || ''; | ||
129 | - let path = `${parentPath}/${lastPath}`; | ||
130 | - path = /^\//.test(path) ? path : `/${path}`; | ||
131 | - go(path); | 141 | + let goPath = ''; |
142 | + if (paths.length === 1) { | ||
143 | + goPath = paths[0]; | ||
144 | + } else { | ||
145 | + const ps = paths.slice(1); | ||
146 | + const lastPath = ps.pop() || ''; | ||
147 | + const parentPath = ps.pop() || ''; | ||
148 | + goPath = `${parentPath}/${lastPath}`; | ||
149 | + } | ||
150 | + goPath = /^\//.test(goPath) ? goPath : `/${goPath}`; | ||
151 | + go(goPath); | ||
132 | } | 152 | } |
133 | } | 153 | } |
134 | 154 | ||
135 | function hasRedirect(routes: RouteLocationMatched[], route: RouteLocationMatched) { | 155 | function hasRedirect(routes: RouteLocationMatched[], route: RouteLocationMatched) { |
136 | - if (route?.meta?.isLink) { | ||
137 | - return true; | ||
138 | - } | ||
139 | - | ||
140 | if (routes.indexOf(route) === routes.length - 1) { | 156 | if (routes.indexOf(route) === routes.length - 1) { |
141 | return false; | 157 | return false; |
142 | } | 158 | } |
159 | + | ||
160 | + // if (route?.meta?.isLink) { | ||
161 | + // return true; | ||
162 | + // } | ||
163 | + | ||
143 | return true; | 164 | return true; |
144 | } | 165 | } |
145 | 166 |
src/main.ts
@@ -51,7 +51,7 @@ import { isDevMode } from '/@/utils/env'; | @@ -51,7 +51,7 @@ import { isDevMode } from '/@/utils/env'; | ||
51 | 51 | ||
52 | // The development environment takes effect | 52 | // The development environment takes effect |
53 | if (isDevMode()) { | 53 | if (isDevMode()) { |
54 | - app.config.performance = true; | 54 | + // app.config.performance = true; |
55 | window.__APP__ = app; | 55 | window.__APP__ = app; |
56 | } | 56 | } |
57 | })(); | 57 | })(); |