dynamicMuen.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import store from '../store/store.js';
  2. const staticMuen = [
  3. {
  4. path: '/msg',
  5. component: () => import(/* webpackChunkName: "messages" */ '@views/messages'),
  6. meta: { title: '消息中心' }
  7. },
  8. {
  9. path: '/403',
  10. component: () => import(/* webpackChunkName: "404" */ '@views/403'),
  11. meta: { title: '403' }
  12. },
  13. {
  14. path: '/404',
  15. component: () => import(/* webpackChunkName: "404" */ '@views/404'),
  16. meta: { title: '404' }
  17. },
  18. {
  19. path: '/parkingLotAdministration/pageJump/partitionManagement',
  20. component: () => import(/* webpackChunkName: "404" */ '@views/parkingLotAdministration/pageJump/partitionManagement.vue'),
  21. meta: { title: '车库分区管理' }
  22. },
  23. {
  24. path: '/ownerManagement/details',
  25. component: () => import(/* webpackChunkName: "404" */ '@views/ownerManagement/details.vue'),
  26. meta: { title: '住户详情' }
  27. },
  28. {
  29. path: '/housingManagement/details',
  30. component: () => import(/* webpackChunkName: "404" */ '@views/assetManagement/housingManagement/details.vue'),
  31. meta: { title: '房屋详情' },
  32. name: 'housingManagementDetails'
  33. },
  34. {
  35. path: '/shopManagement/details',
  36. component: () => import(/* webpackChunkName: "404" */ '@views/assetManagement/shopManagement/details.vue'),
  37. meta: { title: '商铺详情' },
  38. name: 'shopManagementDetails'
  39. },
  40. {
  41. path: '/invoiceManagement/index',
  42. component: () => import(/* webpackChunkName: "404" */ '@views/payService/invoiceManagement/index.vue'),
  43. meta: { title: '发票管理' }
  44. },
  45. {
  46. path: '/expenseReport/index',
  47. component: () => import(/* webpackChunkName: "404" */ '@views/payService/expenseReport/index.vue'),
  48. meta: { title: '费用报表' },
  49. name: 'expenseReport'
  50. },
  51. {
  52. path: '/shannon-transfer',
  53. component: () => import(/* webpackChunkName: "404" */ '@views/patrolManagement/components/shannon-transfer.vue'),
  54. meta: { title: '测试' },
  55. name: 'shannon-transfer'
  56. },
  57. {
  58. path: '*',
  59. redirect: '/404'
  60. }
  61. ];
  62. //路由格式
  63. // 自定义路由文件
  64. const setListMunt = (arrList, item) => {
  65. let newOb = {};
  66. newOb = {
  67. path: `/${item.linkPath}`,
  68. component: () => import(`@/views/${item.linkPath}.vue`),
  69. meta: { title: item.name }
  70. };
  71. arrList.push(newOb);
  72. };
  73. const dimension = (arrList, arr) => {
  74. arr.forEach((item, index) => {
  75. //默认去掉第一个添加路由
  76. // if (item.linkPath !== 'workbench/index') {
  77. // if (!!item.children) {
  78. // dimension(arrList, item.children);
  79. // } else {
  80. // setListMunt(arrList, item);
  81. // }
  82. // }
  83. if (!!item.children) {
  84. dimension(arrList, item.children);
  85. } else {
  86. setListMunt(arrList, item);
  87. }
  88. });
  89. };
  90. //添加路由
  91. const AddRt = (router, dynamicMuenList) => {
  92. let NEWdynamicMuenList = [...dynamicMuenList, ...staticMuen];
  93. if (NEWdynamicMuenList.length !== 0) {
  94. NEWdynamicMuenList.forEach((item) => {
  95. router.options.routes[0].children.push(item);
  96. });
  97. router.addRoutes(router.options.routes);
  98. }
  99. };
  100. export const funcRouter = (arr, data, router) => {
  101. dimension(arr, data);
  102. store.commit('setMenuList', data);
  103. AddRt(router, arr);
  104. };