routes.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /**
  2. * @author chuzhixin 1204505056@qq.com
  3. * @description 路由拦截状态管理,目前两种模式:all模式与intelligence模式,其中partialRoutes是菜单暂未使用
  4. */
  5. import { asyncRoutes, constantRoutes } from '@/router'
  6. import { getRouterList } from '@/api/router'
  7. import { convertRouter, filterRoutes } from '@/utils/routes'
  8. import { ElMessage } from 'element-plus'
  9. import store from '..'
  10. // import { Layout } from 'ant-design-vue'
  11. const state = () => ({
  12. routes: [],
  13. partialRoutes: [],
  14. })
  15. const getters = {
  16. routes: (state) => state.routes,
  17. partialRoutes: (state) => state.partialRoutes,
  18. }
  19. const mutations = {
  20. setRoutes(state, routes) {
  21. state.routes = routes
  22. },
  23. setPartialRoutes(state, routes) {
  24. state.partialRoutes = routes
  25. },
  26. }
  27. const actions = {
  28. /**
  29. * @author chuzhixin 1204505056@qq.com
  30. * @description intelligence模式设置路由
  31. * @param {*} { commit }
  32. * @returns
  33. */
  34. async setRoutes({ commit }) {
  35. const finallyRoutes = filterRoutes([...constantRoutes, ...asyncRoutes])
  36. commit('setRoutes', finallyRoutes)
  37. return [...asyncRoutes]
  38. },
  39. /**
  40. * @author chuzhixin 1204505056@qq.com
  41. * @description all模式设置路由
  42. * @param {*} { commit }
  43. * @returns
  44. */
  45. async setAllRoutes({ commit }) {
  46. let { data } = await getRouterList();
  47. if (data.length == 0) {
  48. store.state.auth = 0
  49. ElMessage.warning('此角色暂无分配权限,请先联系超级管理员分配权限 ! ')
  50. } else {
  51. store.state.auth = 1
  52. }
  53. data[0].meta.affix = false
  54. data.unshift({
  55. path: "/home",
  56. hidden: false,
  57. redirect: "/index/index",
  58. component: "Layout",
  59. meta: {
  60. title: "数据看板",
  61. icon: "home",
  62. },
  63. children: [{
  64. path: "/index/index",
  65. hidden: false,
  66. component: "@/views/index/index",
  67. meta: {
  68. title: "数据看板",
  69. icon: "home",
  70. affix: true
  71. }
  72. }]
  73. })
  74. data.push({
  75. path: "/tenantManage",
  76. hidden: false,
  77. redirect: "/tenantManage/tenantUnit",
  78. component: "Layout",
  79. meta: {
  80. title: "租户管理",
  81. icon: "systemManage",
  82. },
  83. children: [{
  84. meta: {
  85. title: "租户单位配置",
  86. icon: "systemManage",
  87. },
  88. path: "/tenantUnit",
  89. hidden: false,
  90. component: "@/views/tenantManage/tenantUnit",
  91. }, {
  92. meta: {
  93. title: "管理员配置",
  94. icon: "systemManage",
  95. },
  96. path: "/adminConfig",
  97. hidden: false,
  98. component: "@/views/tenantManage/adminConfig",
  99. }, {
  100. meta: {
  101. title: "系统配置",
  102. icon: "systemManage",
  103. },
  104. path: "/systemConfig",
  105. hidden: false,
  106. component: "@/views/tenantManage/systemConfig",
  107. }, {
  108. meta: {
  109. title: "权限配置",
  110. icon: "systemManage",
  111. },
  112. path: "/authConfig",
  113. hidden: false,
  114. component: "@/views/tenantManage/authConfig",
  115. }, ]
  116. })
  117. // data.push({
  118. // "path": "/systemManage",
  119. // "hidden": false,
  120. // "redirect": "/systemManage/userManage",
  121. // "component": "Layout",
  122. // "meta": {
  123. // "title": "租户管理",
  124. // "icon": "systemManage",
  125. // "affix": null
  126. // },
  127. // "children": [{
  128. // "path": "userManage",
  129. // "hidden": false,
  130. // "component": "@/views/systemManage/userManage/index",
  131. // "meta": {
  132. // "title": "租户单位配置",
  133. // "icon": "systemManage",
  134. // "affix": null
  135. // }
  136. // }, {
  137. // "path": "rolePermission1",
  138. // "hidden": false,
  139. // "component": "@/views/tenantManage/rolePermission1/index",
  140. // "meta": {
  141. // "title": "管理员配置",
  142. // "icon": "systemManage",
  143. // "affix": null
  144. // }
  145. // }]
  146. // })
  147. data.forEach(function(item) {
  148. if (item.children.length > 1) {
  149. item.children.forEach(function(i) {
  150. i.meta.icon = ''
  151. })
  152. }
  153. })
  154. console.log('data')
  155. console.log(data)
  156. store.state.middleList = data
  157. // if (data[data.length - 1].path !== '*')
  158. // data.push({ path: '/*', redirect: '/404', hidden: true })
  159. const asyncRoutes = convertRouter(data)
  160. const finallyRoutes = filterRoutes([...constantRoutes, ...asyncRoutes])
  161. commit('setRoutes', finallyRoutes)
  162. return [...asyncRoutes]
  163. },
  164. /**
  165. * @author chuzhixin 1204505056@qq.com
  166. * @description 画廊布局、综合布局设置路由
  167. * @param {*} { commit }
  168. * @param accessedRoutes 画廊布局、综合布局设置路由
  169. */
  170. setPartialRoutes({ commit }, accessedRoutes) {
  171. commit('setPartialRoutes', accessedRoutes)
  172. },
  173. }
  174. export default { state, getters, mutations, actions }