| | |
| | | setSidebarRouters(routes) { |
| | | this.sidebarRouters = routes |
| | | }, |
| | | setIndexPages(routes) { |
| | | this.indexPage = routes |
| | | }, |
| | | generateRoutes(roles) { |
| | | return new Promise(resolve => { |
| | | // 向后端请求路由数据 |
| | |
| | | const sdata = JSON.parse(JSON.stringify(res.data)) |
| | | const rdata = JSON.parse(JSON.stringify(res.data)) |
| | | const defaultData = JSON.parse(JSON.stringify(res.data)) |
| | | let firstPage = '' |
| | | //通过权限返回菜单去避免 如有首页权限 出现//index 情况 |
| | | // if (res.data[0].path == '/') { |
| | | // firstPage = res.data[0].path + res.data[0].children[0].path |
| | | // } else{ |
| | | // firstPage = res.data[0].path + '/' + res.data[0].children[0].path |
| | | // } |
| | | if (res.data && res.data.length > 0 && res.data[0]) { |
| | | const firstMenu = res.data[0]; |
| | | // 2. 判断第一个菜单是否有子菜单 |
| | | if (firstMenu.children && firstMenu.children.length > 0) { |
| | | // 有子菜单,按原来的逻辑拼接 |
| | | if (firstMenu.path === '/') { |
| | | firstPage = firstMenu.path + firstMenu.children[0].path; |
| | | } else { |
| | | firstPage = firstMenu.path + '/' + firstMenu.children[0].path; |
| | | } |
| | | } else { |
| | | firstPage = firstMenu.path; |
| | | } |
| | | } else { |
| | | firstPage = '/index'; |
| | | } |
| | | const sidebarRoutes = filterAsyncRouter(sdata) |
| | | const rewriteRoutes = filterAsyncRouter(rdata, false, true) |
| | | const defaultRoutes = filterAsyncRouter(defaultData) |
| | | const asyncRoutes = filterDynamicRoutes(dynamicRoutes) |
| | | asyncRoutes.forEach(route => { router.addRoute(route) }) |
| | | this.setRoutes(rewriteRoutes) |
| | | // this.setRoutes(rewriteRoutes) |
| | | this.setSidebarRouters(constantRoutes.concat(sidebarRoutes)) |
| | | // this.setSidebarRouters(sidebarRoutes) |
| | | this.setDefaultRoutes(sidebarRoutes) |
| | | this.setTopbarRoutes(defaultRoutes) |
| | | this.setIndexPages(firstPage) |
| | | resolve(rewriteRoutes) |
| | | }) |
| | | }) |