| | |
| | | import { getRouters } from '@/api/menu' |
| | | import Layout from '@/layout/index' |
| | | import ParentView from '@/components/ParentView'; |
| | | import InnerLink from '@/layout/components/InnerLink' |
| | | |
| | | const permission = { |
| | | state: { |
| | | routes: [], |
| | | addRoutes: [], |
| | | defaultRoutes: [], |
| | | topbarRouters: [], |
| | | sidebarRouters: [] |
| | | }, |
| | | mutations: { |
| | |
| | | state.addRoutes = routes |
| | | state.routes = constantRoutes.concat(routes) |
| | | }, |
| | | SET_SIDEBAR_ROUTERS: (state, routers) => { |
| | | state.sidebarRouters = constantRoutes.concat(routers) |
| | | SET_DEFAULT_ROUTES: (state, routes) => { |
| | | state.defaultRoutes = constantRoutes.concat(routes) |
| | | }, |
| | | SET_TOPBAR_ROUTES: (state, routes) => { |
| | | // 顶部导航菜单默认添加统计报表栏指向首页 |
| | | const index = [{ |
| | | path: 'index', |
| | | meta: { title: '统计报表', icon: 'dashboard'} |
| | | }] |
| | | state.topbarRouters = routes.concat(index); |
| | | }, |
| | | SET_SIDEBAR_ROUTERS: (state, routes) => { |
| | | state.sidebarRouters = routes |
| | | }, |
| | | }, |
| | | actions: { |
| | |
| | | const rewriteRoutes = filterAsyncRouter(rdata, false, true) |
| | | rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true }) |
| | | commit('SET_ROUTES', rewriteRoutes) |
| | | commit('SET_SIDEBAR_ROUTERS', sidebarRoutes) |
| | | commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes)) |
| | | commit('SET_DEFAULT_ROUTES', sidebarRoutes) |
| | | commit('SET_TOPBAR_ROUTES', sidebarRoutes) |
| | | resolve(rewriteRoutes) |
| | | }) |
| | | }) |
| | |
| | | route.component = Layout |
| | | } else if (route.component === 'ParentView') { |
| | | route.component = ParentView |
| | | } else if (route.component === 'InnerLink') { |
| | | route.component = InnerLink |
| | | } else { |
| | | route.component = loadView(route.component) |
| | | } |
| | |
| | | var children = [] |
| | | childrenMap.forEach((el, index) => { |
| | | if (el.children && el.children.length) { |
| | | if (el.component === 'ParentView') { |
| | | if (el.component === 'ParentView' && !lastRouter) { |
| | | el.children.forEach(c => { |
| | | c.path = el.path + '/' + c.path |
| | | if (c.children && c.children.length) { |
| | |
| | | return children |
| | | } |
| | | |
| | | export const loadView = (view) => { // 路由懒加载 |
| | | return (resolve) => require([`@/views/${view}`], resolve) |
| | | export const loadView = (view) => { |
| | | if (process.env.NODE_ENV === 'development') { |
| | | return (resolve) => require([`@/views/${view}`], resolve) |
| | | } else { |
| | | // 使用 import 实现生产环境的路由懒加载 |
| | | return () => import(`@/views/${view}`) |
| | | } |
| | | } |
| | | |
| | | export default permission |