|
|
@@ -251,25 +251,42 @@ export default {
|
|
|
activeRoutes(key) {
|
|
|
const routes = []
|
|
|
const normalizedKey = this.normPath(key)
|
|
|
- const childrenMenus = this.buildChildrenMenus()
|
|
|
- childrenMenus.forEach(item => {
|
|
|
- if (this.normPath(item.parentPath) === normalizedKey) {
|
|
|
- routes.push(item)
|
|
|
- }
|
|
|
- })
|
|
|
- if (routes.length === 0) {
|
|
|
- const router = this.topbarRouters.find(r => !r.hidden && this.normPath(r.path) === normalizedKey)
|
|
|
- if (router && router.children) {
|
|
|
- router.children.forEach(child => {
|
|
|
- if (!child.hidden) routes.push(child)
|
|
|
- })
|
|
|
- }
|
|
|
+ const topRouter = this.topbarRouters.find(r => !r.hidden && this.normPath(r.path) === normalizedKey)
|
|
|
+ if (topRouter && topRouter.children && topRouter.children.length) {
|
|
|
+ topRouter.children.forEach(child => {
|
|
|
+ if (!child.hidden) {
|
|
|
+ routes.push(this.prefixSidebarRouteTree(child, normalizedKey))
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ const childrenMenus = this.buildChildrenMenus()
|
|
|
+ childrenMenus.forEach(item => {
|
|
|
+ if (this.normPath(item.parentPath) === normalizedKey) {
|
|
|
+ routes.push(item)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
if (routes.length > 0) {
|
|
|
this.$store.commit('SET_SIDEBAR_ROUTERS', routes)
|
|
|
}
|
|
|
return routes
|
|
|
},
|
|
|
+ /** 为侧栏嵌套菜单补全相对 path,避免子菜单链接跳到 /operLog 等错误路径 */
|
|
|
+ prefixSidebarRouteTree(route, parentPath) {
|
|
|
+ const cloned = { ...route }
|
|
|
+ const seg = (cloned.path || '').replace(/^\//, '')
|
|
|
+ if (seg && !this.ishttp(cloned.path) && !cloned.path.startsWith('/')) {
|
|
|
+ cloned.path = this.normPath(parentPath) + '/' + seg
|
|
|
+ } else if (cloned.path && !cloned.path.startsWith('/') && !this.ishttp(cloned.path)) {
|
|
|
+ cloned.path = '/' + cloned.path
|
|
|
+ }
|
|
|
+ if (cloned.children && cloned.children.length) {
|
|
|
+ cloned.children = cloned.children.map(child =>
|
|
|
+ this.prefixSidebarRouteTree(child, cloned.path)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ return cloned
|
|
|
+ },
|
|
|
getFirstRoutePath(routes) {
|
|
|
if (!routes || !routes.length) return null
|
|
|
for (let i = 0; i < routes.length; i++) {
|