|
- import { constantRoutes } from '@/router'
-
- const permission = {
- state: {
- routes: [],
- addRoutes: [],
- sidebarRouters: []
- },
- mutations: {
- SET_ROUTES: (state, routes) => {
- state.addRoutes = routes
- state.routes = constantRoutes.concat(routes)
- },
- SET_SIDEBAR_ROUTERS: (state, routers) => {
- state.sidebarRouters = constantRoutes.concat(routers)
- },
- },
- actions: {
- }
- }
-
-
- function filterChildren (childrenMap) {
- var children = []
- childrenMap.forEach((el, index) => {
- if (el.children && el.children.length) {
- if (el.component === 'ParentView') {
- el.children.forEach(c => {
- c.path = el.path + '/' + c.path
- if (c.children && c.children.length) {
- children = children.concat(filterChildren(c.children, c))
- return
- }
- children.push(c)
- })
- return
- }
- }
- children = children.concat(el)
- })
- return children
- }
- 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
|