permission.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import { constantRoutes } from '@/router'
  2. import { getRouters } from '@/api/menu'
  3. import Layout from '@/layout/index'
  4. const permission = {
  5. state: {
  6. routes: [],
  7. addRoutes: []
  8. },
  9. mutations: {
  10. SET_ROUTES: (state, routes) => {
  11. state.addRoutes = routes
  12. state.routes = constantRoutes.concat(routes)
  13. }
  14. },
  15. actions: {
  16. // 生成路由
  17. GenerateRoutes({ commit }) {
  18. return new Promise(resolve => {
  19. // 向后端请求路由数据
  20. getRouters().then(res => {
  21. let arr = [
  22. // {
  23. // path: 'business/Middleware/Subsystem',
  24. // component: () =>
  25. // import ('@/views/business/Middleware/Subsystem'),
  26. // hidden: true,
  27. // },
  28. {
  29. component: "Layout",
  30. hidden: false,
  31. path: "/",
  32. children: [{
  33. component: "business/Middleware/subsystem",
  34. hidden: true,
  35. meta: { title: "子系统管理", icon: "cascader", noCache: true, link: null },
  36. name: "Middleware/subsystem",
  37. path: "Middleware/subsystem",
  38. }]
  39. },
  40. {
  41. component: "Layout",
  42. hidden: false,
  43. path: "/",
  44. children: [{
  45. component: "business/Middleware/functionalInterface",
  46. hidden: true,
  47. meta: { title: "功能接口管理", icon: "guide", noCache: true, link: null },
  48. name: "Middleware/functionalInterface",
  49. path: "Middleware/functionalInterface",
  50. }]
  51. },
  52. {
  53. component: "Layout",
  54. hidden: false,
  55. path: "/",
  56. children: [{
  57. component: "business/Middleware/hostEquipment",
  58. hidden: true,
  59. meta: { title: "主机设备管理", icon: "international", noCache: true, link: null },
  60. name: "Middleware/hostEquipment",
  61. path: "Middleware/hostEquipment",
  62. }]
  63. },
  64. {
  65. component: "Layout",
  66. hidden: false,
  67. path: "/",
  68. children: [{
  69. component: "business/Middleware/bpmn/index",
  70. hidden: false,
  71. meta: { title: "流程图", icon: "international", noCache: true, link: null },
  72. name: "Middleware/bpmn/index",
  73. path: "Middleware/bpmn/index",
  74. }]
  75. },
  76. {
  77. component: "Layout",
  78. hidden: false,
  79. path: "/",
  80. children: [{
  81. component: "business/Middleware/bpmn/customModeler",
  82. hidden: true,
  83. meta: { title: "流程图绘制", icon: "international", noCache: true, link: null },
  84. name: "Middleware/bpmn/customModeler",
  85. path: "Middleware/bpmn/customModeler",
  86. }]
  87. },
  88. {
  89. component: "Layout",
  90. hidden: false,
  91. path: "/",
  92. children: [{
  93. component: "business/Middleware/bpmn/executionRecord",
  94. hidden: false,
  95. meta: { title: "历史流程图执行记录", icon: "international", noCache: true, link: null },
  96. name: "Middleware/bpmn/executionRecord",
  97. path: "Middleware/bpmn/executionRecord",
  98. }]
  99. },
  100. {
  101. component: "Layout",
  102. hidden: false,
  103. path: "/",
  104. children: [{
  105. component: "business/Middleware/bpmn/executionLog",
  106. hidden: true,
  107. meta: { title: "历史流程图执行日志", icon: "international", noCache: true, link: null },
  108. name: "Middleware/bpmn/executionLog",
  109. path: "Middleware/bpmn/executionLog",
  110. }]
  111. },
  112. // {
  113. // path: '/Middleware/',
  114. // component: Layout,
  115. // meta: {
  116. // icon: "system",
  117. // link: null,
  118. // noCache: false,
  119. // title: "中间件管理",
  120. // name: "Middleware",
  121. // path: "/business/Middleware",
  122. // redirect: "noRedirect"
  123. // },
  124. // children: [
  125. // {
  126. // path: 'Subsystem',
  127. // name: 'Subsystem',
  128. // component: () =>
  129. // import ('@/views/business/Middleware/Subsystem/index'),
  130. // meta: { title: '子系统管理', icon: 'home' }
  131. // },
  132. // {
  133. // path: 'functionalInterface',
  134. // name: 'functionalInterface',
  135. // component: () =>
  136. // import ('@/views/business/Middleware/functionalInterface/index'),
  137. // meta: { title: '功能接口管理', icon: 'home' }
  138. // }
  139. // ]
  140. // }
  141. ]
  142. const accessedRoutes = filterAsyncRouter(arr)
  143. //const accessedRoutes = filterAsyncRouter(res.data)
  144. accessedRoutes.push({ path: '*', redirect: '/404', hidden: true })
  145. commit('SET_ROUTES', accessedRoutes)
  146. resolve(accessedRoutes)
  147. })
  148. })
  149. }
  150. }
  151. }
  152. // 遍历后台传来的路由字符串,转换为组件对象
  153. function filterAsyncRouter(asyncRouterMap) {
  154. return asyncRouterMap.filter(route => {
  155. if (route.component) {
  156. // Layout组件特殊处理
  157. if (route.component === 'Layout') {
  158. route.component = Layout
  159. } else {
  160. route.component = loadView(route.component)
  161. }
  162. }
  163. if (route.children != null && route.children && route.children.length) {
  164. route.children = filterAsyncRouter(route.children)
  165. }
  166. return true
  167. })
  168. }
  169. export const loadView = (view) => { // 路由懒加载
  170. return (resolve) => require([`@/views/${view}`], resolve)
  171. }
  172. export default permission