From e05d5e9270e97682715d868cb99a09066885836e Mon Sep 17 00:00:00 2001 From: 13405411873 <1994398261@qq.com> Date: Thu, 24 Oct 2024 00:17:42 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E4=B8=9A=E5=8A=A1=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/permission.js | 59 +++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js index 3aca219..d80e855 100644 --- a/src/store/modules/permission.js +++ b/src/store/modules/permission.js @@ -37,8 +37,9 @@ const permission = { // 将 menus 菜单,转换为 route 路由数组 const sdata = JSON.parse(JSON.stringify(menus)) // 【重要】用于菜单中的数据 const rdata = JSON.parse(JSON.stringify(menus)) // 用于最后添加到 Router 中的数据 - const sidebarRoutes = filterAsyncRouter(sdata) - const rewriteRoutes = filterAsyncRouter(rdata, false, true) + const sss = JSON.parse(JSON.stringify(menus)) + const sidebarRoutes = filterAsyncRouter(sdata,sss) + const rewriteRoutes = filterAsyncRouter(rdata,sss, false, true) rewriteRoutes.push({path: '*', redirect: '/404', hidden: true}) commit('SET_ROUTES', rewriteRoutes) commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes)) @@ -51,13 +52,12 @@ const permission = { } // 遍历后台传来的路由字符串,转换为组件对象 -function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) { +function filterAsyncRouter(asyncRouterMap,sdata, lastRouter = false, type = false) { return asyncRouterMap.filter(function(route,index) { // 将 ruoyi 后端原有耦合前端的逻辑,迁移到此处 // 处理 meta 属性 route.meta = { - title:dealMenuText(index) +' '+ route.name, - icon: route.icon, + title:dealMenuText(index,route,sdata) +' '+ route.name, noCache: !route.keepAlive, } route.hidden = !route.visible @@ -89,23 +89,56 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) { route.children = filterChildren(route.children) } if (route.children != null && route.children && route.children.length) { - route.children = filterAsyncRouter(route.children, route, type) + route.children = filterAsyncRouter(route.children,sdata, route, type) route.alwaysShow = route.alwaysShow !== undefined ? route.alwaysShow : true } else { delete route['children'] delete route['alwaysShow'] // 如果没有子菜单,就不需要考虑 alwaysShow 字段 } - console.log(route,989898) return true }) } -function dealMenuText(num){ - let tempData =['(一)','(二)','(三)','(四)','(五)','(六)','(七)','(八)','(九)','(十)' - ,'(十一)','(十二)','(十三)','(十四)','(十五)','(十六)','(十七)','(十八)','(十九)','(二十)','(二十一)','(二十二)','(二十三)'] - if (num>tempData.length){ - return ""; +function dealMenuText(num,data,list){ + if (data.parentId==0){ + let tempData =['一','二','三','四','五','六','七','八','九','十' + ,'十一','十二','十三','十四','十五','十六','十七','十八','十九','二十','二十一','二十二','二十三'] + if (num>tempData.length){ + return ""; + } + return tempData[num] +'、' + }else { + let level =1; + let parData ={}; + for (const item of list) { + if ( data.parentId == item.id){ + parData = item + level++ + break; + } + } + for (const item of list) { + if ( parData.parentId == 0){ + parData = item + level++ + break; + } + } + if (level==2){ + let tempData2 =['(一)','(二)','(三)','(四)','(五)','(六)','(七)','(八)','(九)','(十)' + ,'(十一)','(十二)','(十三)','(十四)','(十五)','(十六)','(十七)','(十八)','(十九)','(二十)','(二十一)','(二十二)','(二十三)'] + if (num>tempData2.length){ + return ""; + } + return tempData2[num] + }else if (level == 3){ + return (num+1)+'.' + }else { + return "" + } + + } - return tempData[num] + } function filterChildren(childrenMap, lastRouter = false) { let children = [];