routes.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 { Layout } from 'ant-design-vue'
  9. const state = () => ({
  10. routes: [],
  11. partialRoutes: [],
  12. })
  13. const getters = {
  14. routes: (state) => state.routes,
  15. partialRoutes: (state) => state.partialRoutes,
  16. }
  17. const mutations = {
  18. setRoutes(state, routes) {
  19. state.routes = routes
  20. },
  21. setPartialRoutes(state, routes) {
  22. state.partialRoutes = routes
  23. },
  24. }
  25. const actions = {
  26. /**
  27. * @author chuzhixin 1204505056@qq.com
  28. * @description intelligence模式设置路由
  29. * @param {*} { commit }
  30. * @returns
  31. */
  32. async setRoutes({ commit }) {
  33. const finallyRoutes = filterRoutes([...constantRoutes, ...asyncRoutes])
  34. commit('setRoutes', finallyRoutes)
  35. return [...asyncRoutes]
  36. },
  37. /**
  38. * @author chuzhixin 1204505056@qq.com
  39. * @description all模式设置路由
  40. * @param {*} { commit }
  41. * @returns
  42. */
  43. async setAllRoutes({ commit }) {
  44. let { data } = await getRouterList()
  45. // let data = [
  46. // {
  47. // path: 'external-link',
  48. // component: "Layout",
  49. // children: [{
  50. // path: '/home',
  51. // meta: { title: '首页', icon: 'home', }
  52. // }]
  53. // },
  54. // {
  55. // path: '/',
  56. // redirect: '/alarmManage/index',
  57. // meta: {
  58. // title: '告警管理',
  59. // icon: 'alarmManage',
  60. // affix: true,
  61. // },
  62. // component: "Layout",
  63. // children: [{
  64. // meta: {
  65. // title: '告警管理',
  66. // icon: 'alarmManage',
  67. // },
  68. // path: '/alarmManage/index',
  69. // component: '@/views/alarmManage/index',
  70. // },]
  71. // }
  72. // ]
  73. data.unshift({
  74. path: 'external-link',
  75. component: 'Layout',
  76. children: [{
  77. path: '/home',
  78. meta: { title: '首页', icon: 'home', }
  79. }]
  80. }, )
  81. console.log('data')
  82. console.log(data)
  83. if (data[data.length - 1].path !== '*')
  84. data.push({ path: '/*', redirect: '/404', hidden: true })
  85. const asyncRoutes = convertRouter(data)
  86. const finallyRoutes = filterRoutes([...constantRoutes, ...asyncRoutes])
  87. commit('setRoutes', finallyRoutes)
  88. return [...asyncRoutes]
  89. },
  90. /**
  91. * @author chuzhixin 1204505056@qq.com
  92. * @description 画廊布局、综合布局设置路由
  93. * @param {*} { commit }
  94. * @param accessedRoutes 画廊布局、综合布局设置路由
  95. */
  96. setPartialRoutes({ commit }, accessedRoutes) {
  97. commit('setPartialRoutes', accessedRoutes)
  98. },
  99. }
  100. export default { state, getters, mutations, actions }