routes.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. // data[4].redirect = "/dataManage/sameAnalysis"
  46. console.log('data')
  47. console.log(data)
  48. data.unshift({
  49. path: 'external-link',
  50. component: 'Layout',
  51. children: [{
  52. path: '/home',
  53. meta: { title: '首页', icon: 'home', }
  54. }]
  55. }, )
  56. // if (data[data.length - 1].path !== '*')
  57. // data.push({ path: '/*', redirect: '/404', hidden: true })
  58. const asyncRoutes = convertRouter(data)
  59. const finallyRoutes = filterRoutes([...constantRoutes, ...asyncRoutes])
  60. commit('setRoutes', finallyRoutes)
  61. return [...asyncRoutes]
  62. },
  63. /**
  64. * @author chuzhixin 1204505056@qq.com
  65. * @description 画廊布局、综合布局设置路由
  66. * @param {*} { commit }
  67. * @param accessedRoutes 画廊布局、综合布局设置路由
  68. */
  69. setPartialRoutes({ commit }, accessedRoutes) {
  70. commit('setPartialRoutes', accessedRoutes)
  71. },
  72. }
  73. export default { state, getters, mutations, actions }