diff --git a/src/router/generator-routers.ts b/src/router/generator-routers.ts index b40dddf..f78efc0 100644 --- a/src/router/generator-routers.ts +++ b/src/router/generator-routers.ts @@ -20,28 +20,28 @@ LayoutMap.set('IFRAME', Iframe); */ export const routerGenerator = (routerMap): any[] => { return routerMap.map((item) => { - const names = item.target == 2 ? item.component : item.path.replaceAll('/', ''); + const names = item.target == 2 ? item.component : item.path.replaceAll('/', ''); item.meta = { - title:item.parentId==0 && item.children.length==0?'':item.name, - icon:constantRouterIcon[item.icon2]|| null, - sort:item.sort, - permissions:item.permission, - hidden: item.hide?true:false, - isRoot:item.parentId==0 && item.children.length==0?true:false, - alwaysShow: item.parentId==0 && item.children.length==0?true:false, - frameSrc: item.target==1?item.component:'', - target:item.target==2?true:false - } - let components = '' - if(item.parentId==0 && (item.children.length==0 || item.children.length>0) ) { - components ='LAYOUT' - } else if(item.target==0) { - components = item.component - } else if(item.target==1) { - components ='IFRAME' + title: item.parentId == 0 && item.children.length == 0 ? '' : item.name, + icon: constantRouterIcon[item.icon2] || null, + sort: item.sort, + permissions: item.permission, + hidden: item.hide ? true : false, + isRoot: item.parentId == 0 && item.children.length == 0 ? true : false, + alwaysShow: item.parentId == 0 && item.children.length == 0 ? true : false, + frameSrc: item.target == 1 ? item.component : '', + target: item.target == 2 ? true : false, + }; + let components = ''; + if (item.parentId == 0 && (item.children.length == 0 || item.children.length > 0)) { + components = 'LAYOUT'; + } else if (item.target == 0) { + components = item.component; + } else if (item.target == 1) { + components = 'IFRAME'; } const currentRouter: any = { - path:item.target==2?'':item.path, + path: item.target == 2 ? '' : item.path, // 路由名称,建议唯一 name: names, // 该路由对应页面的 组件 @@ -64,33 +64,33 @@ export const routerGenerator = (routerMap): any[] => { // Recursion currentRouter.children = routerGenerator(item.children, currentRouter); } else { - if(item.parentId==0 && item.children.length==0) { - currentRouter.children =[] - if(item.target==1 && (/http(s)?:/.test(item.component))){ + if (item.parentId == 0 && item.children.length == 0) { + currentRouter.children = []; + if (item.target == 1 && /http(s)?:/.test(item.component)) { currentRouter.children.push({ path: item.path, name: names, meta: { title: item.name, frameSrc: item.component, - icon:constantRouterIcon[item.icon2], - hidden: item.hide?true:false, + icon: constantRouterIcon[item.icon2], + hidden: item.hide ? true : false, }, component: 'IFRAME', - }) + }); } else { currentRouter.children.push({ path: item.path, name: names, meta: { title: item.name, - icon:constantRouterIcon[item.icon2], + icon: constantRouterIcon[item.icon2], activeMenu: names, - target:item.target==2?true:false, - hidden: item.hide?true:false, + target: item.target == 2 ? true : false, + hidden: item.hide ? true : false, }, component: item.component, - }) + }); } } } @@ -106,8 +106,7 @@ export const generatorDynamicRouter = (): Promise => { return new Promise((resolve, reject) => { adminMenus() .then((result) => { - const routeList = routerGenerator(result) - console.log(routeList) + const routeList = routerGenerator(result); asyncImportRoute(routeList); resolve(routeList); }) @@ -172,6 +171,6 @@ export const dynamicImport = ( /** * 查找第一个路由 * */ -export const findFirstRoutePath = (routes)=>{ - return routes.length > 0?(routes[0].redirect?routes[0].redirect:routes[0].path):'' -} +export const findFirstRoutePath = (routes) => { + return routes.length > 0 ? (routes[0].redirect ? routes[0].redirect : routes[0].path) : ''; +}; diff --git a/src/views/system/role/auth.vue b/src/views/system/role/auth.vue index 73f8c2d..cc866d7 100644 --- a/src/views/system/role/auth.vue +++ b/src/views/system/role/auth.vue @@ -8,8 +8,12 @@ >