routes.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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[0].children[0].meta.affix = true
  55. // data.unshift({
  56. // path: "/home",
  57. // hidden: false,
  58. // redirect: "/index/index",
  59. // component: "Layout",
  60. // meta: {
  61. // title: "数据看板",
  62. // icon: "home",
  63. // },
  64. // children: [{
  65. // path: "/index/index",
  66. // hidden: false,
  67. // component: "@/views/index/index",
  68. // meta: {
  69. // title: "数据看板",
  70. // icon: "home",
  71. // affix: true
  72. // }
  73. // }]
  74. // })
  75. // data.push({
  76. // path: "/tenantManage",
  77. // hidden: false,
  78. // redirect: "/tenantManage/tenantUnit",
  79. // component: "Layout",
  80. // meta: {
  81. // title: "租户管理",
  82. // icon: "tenantManage",
  83. // },
  84. // children: [{
  85. // meta: {
  86. // title: "租户单位配置",
  87. // icon: "tenantManage",
  88. // },
  89. // path: "/tenantUnit",
  90. // hidden: false,
  91. // component: "@/views/tenantManage/tenantUnit",
  92. // }, {
  93. // meta: {
  94. // title: "管理员配置",
  95. // icon: "tenantManage",
  96. // },
  97. // path: "/adminConfig",
  98. // hidden: false,
  99. // component: "@/views/tenantManage/adminConfig",
  100. // }, {
  101. // meta: {
  102. // title: "系统配置",
  103. // icon: "tenantManage",
  104. // },
  105. // path: "/systemConfig",
  106. // hidden: false,
  107. // component: "@/views/tenantManage/systemConfig",
  108. // }, {
  109. // meta: {
  110. // title: "权限配置",
  111. // icon: "tenantManage",
  112. // },
  113. // path: "/authConfig",
  114. // hidden: false,
  115. // component: "@/views/tenantManage/authConfig",
  116. // }, ]
  117. // })
  118. data.forEach(function(item) {
  119. if (item.children.length > 1) {
  120. item.children.forEach(function(i) {
  121. i.meta.icon = ''
  122. })
  123. }
  124. })
  125. console.log('data')
  126. console.log(data)
  127. store.state.middleList = data
  128. // if (data[data.length - 1].path !== '*')
  129. // data.push({ path: '/*', redirect: '/404', hidden: true })
  130. const asyncRoutes = convertRouter(data)
  131. const finallyRoutes = filterRoutes([...constantRoutes, ...asyncRoutes])
  132. commit('setRoutes', finallyRoutes)
  133. return [...asyncRoutes]
  134. },
  135. /**
  136. * @author chuzhixin 1204505056@qq.com
  137. * @description 画廊布局、综合布局设置路由
  138. * @param {*} { commit }
  139. * @param accessedRoutes 画廊布局、综合布局设置路由
  140. */
  141. setPartialRoutes({ commit }, accessedRoutes) {
  142. commit('setPartialRoutes', accessedRoutes)
  143. },
  144. }
  145. export default { state, getters, mutations, actions }