From 268cda59aaad552c94b01c6ff319438842191bba Mon Sep 17 00:00:00 2001 From: yxh Date: Thu, 16 Mar 2023 11:44:24 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=E5=88=86=E6=A0=8F?= =?UTF-8?q?=E5=B8=83=E5=B1=80bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/component/columnsAside.vue | 43 +++++++++++++++++---------- src/router/backEnd.ts | 9 ++++++ 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/layout/component/columnsAside.vue b/src/layout/component/columnsAside.vue index 7fd7806..079ef5f 100644 --- a/src/layout/component/columnsAside.vue +++ b/src/layout/component/columnsAside.vue @@ -102,7 +102,9 @@ export default defineComponent({ state.liOldPath = path; state.liOldIndex = k; state.liHoverIndex = k; - proxy.mittBus.emit('setSendColumnsChildren', setSendChildren(path)); + if(v.children&&v.children.length>0){ + proxy.mittBus.emit('setSendColumnsChildren', setSendChildren(v.children[0].path)); + } stores.setColumnsMenuHover(false); stores.setColumnsNavHover(true); }; @@ -130,16 +132,21 @@ export default defineComponent({ }; // 传送当前子级数据到菜单中 const setSendChildren = (path: string) => { - const currentPathSplit = path.split('/'); let currentData: any = {}; - state.columnsAsideList.map((v: any, k: number) => { - if (v.path === `/${currentPathSplit[1]}`) { - v['k'] = k; - currentData['item'] = [{ ...v }]; - currentData['children'] = [{ ...v }]; - if (v.children) currentData['children'] = v.children; - } - }); + state.columnsAsideList.some((v:any,k:number)=>{ + if(v.children){ + v.children.some((sv:any)=>{ + if(sv.path===path){ + v['k'] = k; + currentData['item'] = [{ ...v }]; + currentData['children'] = [{ ...v }]; + if (v.children) currentData['children'] = v.children; + return true + } + }) + } + return false + }) return currentData; }; // 路由过滤递归函数 @@ -154,11 +161,17 @@ export default defineComponent({ }; // tagsView 点击时,根据路由查找下标 columnsAsideList,实现左侧菜单高亮 const setColumnsMenuHighlight = (path: string) => { - state.routeSplit = path.split('/'); - state.routeSplit.shift(); - const routeFirst = `/${state.routeSplit[0]}`; - const currentSplitRoute = state.columnsAsideList.find((v: any) => v.path === routeFirst); - if (!currentSplitRoute) return false; + const currentSplitRoute = state.columnsAsideList.some((v:any)=>{ + if(v.children){ + v.children.some((sv:any)=>{ + if(sv.path===path){ + return true + } + }) + } + return false + }) + if (!currentSplitRoute) return false; // 延迟拿值,防止取不到 setTimeout(() => { onColumnsAsideDown((currentSplitRoute).k); diff --git a/src/router/backEnd.ts b/src/router/backEnd.ts index 7c2d78e..c957492 100644 --- a/src/router/backEnd.ts +++ b/src/router/backEnd.ts @@ -142,6 +142,15 @@ export function setBackEndControlRefreshRoutes() { export function backEndComponent(routes: any) { if (!routes) return; return routes.map((item: any) => { + if(item.children&&item.children.length>0){ + item.children.some((ci:any)=>{ + if(!ci.meta.isHide){ + item.redirect = ci + return true + } + return false + }) + } if (item.component) item.component = dynamicImport(dynamicViewsModules, item.component as string); item.children && backEndComponent(item.children); return item;