123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- import { constantRoutes } from '@/router'
- import { getRouters } from '@/api/menu'
- import Layout from '@/layout/index'
- const permission = {
- state: {
- routes: [],
- addRoutes: []
- },
- mutations: {
- SET_ROUTES: (state, routes) => {
- state.addRoutes = routes
- state.routes = constantRoutes.concat(routes)
- }
- },
- actions: {
- // 生成路由
- GenerateRoutes({ commit }) {
- return new Promise(resolve => {
- // 向后端请求路由数据
- getRouters().then(res => {
- let arr = [
- // {
- // path: 'business/Middleware/Subsystem',
- // component: () =>
- // import ('@/views/business/Middleware/Subsystem'),
- // hidden: true,
- // },
- {
- component: "Layout",
- hidden: false,
- path: "/",
- children: [{
- component: "business/Middleware/subsystem",
- hidden: true,
- meta: { title: "子系统管理", icon: "cascader", noCache: true, link: null },
- name: "Middleware/subsystem",
- path: "Middleware/subsystem",
- }]
- },
- {
- component: "Layout",
- hidden: false,
- path: "/",
- children: [{
- component: "business/Middleware/functionalInterface",
- hidden: true,
- meta: { title: "功能接口管理", icon: "guide", noCache: true, link: null },
- name: "Middleware/functionalInterface",
- path: "Middleware/functionalInterface",
- }]
- },
- {
- component: "Layout",
- hidden: false,
- path: "/",
- children: [{
- component: "business/Middleware/hostEquipment",
- hidden: true,
- meta: { title: "主机设备管理", icon: "international", noCache: true, link: null },
- name: "Middleware/hostEquipment",
- path: "Middleware/hostEquipment",
- }]
- },
- {
- component: "Layout",
- hidden: false,
- path: "/",
- children: [{
- component: "business/Middleware/bpmn/index",
- hidden: false,
- meta: { title: "流程图", icon: "international", noCache: true, link: null },
- name: "Middleware/bpmn/index",
- path: "Middleware/bpmn/index",
- }]
- },
- {
- component: "Layout",
- hidden: false,
- path: "/",
- children: [{
- component: "business/Middleware/bpmn/customModeler",
- hidden: true,
- meta: { title: "流程图绘制", icon: "international", noCache: true, link: null },
- name: "Middleware/bpmn/customModeler",
- path: "Middleware/bpmn/customModeler",
- }]
- },
- {
- component: "Layout",
- hidden: false,
- path: "/",
- children: [{
- component: "business/Middleware/bpmn/executionRecord",
- hidden: false,
- meta: { title: "历史流程图执行记录", icon: "international", noCache: true, link: null },
- name: "Middleware/bpmn/executionRecord",
- path: "Middleware/bpmn/executionRecord",
- }]
- },
- {
- component: "Layout",
- hidden: false,
- path: "/",
- children: [{
- component: "business/Middleware/bpmn/executionLog",
- hidden: true,
- meta: { title: "历史流程图执行日志", icon: "international", noCache: true, link: null },
- name: "Middleware/bpmn/executionLog",
- path: "Middleware/bpmn/executionLog",
- }]
- },
- // {
- // path: '/Middleware/',
- // component: Layout,
- // meta: {
- // icon: "system",
- // link: null,
- // noCache: false,
- // title: "中间件管理",
- // name: "Middleware",
- // path: "/business/Middleware",
- // redirect: "noRedirect"
- // },
- // children: [
- // {
- // path: 'Subsystem',
- // name: 'Subsystem',
- // component: () =>
- // import ('@/views/business/Middleware/Subsystem/index'),
- // meta: { title: '子系统管理', icon: 'home' }
- // },
- // {
- // path: 'functionalInterface',
- // name: 'functionalInterface',
- // component: () =>
- // import ('@/views/business/Middleware/functionalInterface/index'),
- // meta: { title: '功能接口管理', icon: 'home' }
- // }
- // ]
- // }
- ]
- const accessedRoutes = filterAsyncRouter(arr)
- //const accessedRoutes = filterAsyncRouter(res.data)
- accessedRoutes.push({ path: '*', redirect: '/404', hidden: true })
- commit('SET_ROUTES', accessedRoutes)
- resolve(accessedRoutes)
- })
- })
- }
- }
- }
- // 遍历后台传来的路由字符串,转换为组件对象
- function filterAsyncRouter(asyncRouterMap) {
- return asyncRouterMap.filter(route => {
- if (route.component) {
- // Layout组件特殊处理
- if (route.component === 'Layout') {
- route.component = Layout
- } else {
- route.component = loadView(route.component)
- }
- }
- if (route.children != null && route.children && route.children.length) {
- route.children = filterAsyncRouter(route.children)
- }
- return true
- })
- }
- export const loadView = (view) => { // 路由懒加载
- return (resolve) => require([`@/views/${view}`], resolve)
- }
- export default permission
|