dynamicMuen.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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: '/editWorkbench',
  59. component: () => import(/* webpackChunkName: "404" */ '@views/newWorkBench/editWorkbench.vue'),
  60. meta: { title: '编辑工作台' },
  61. name: 'editWorkbench'
  62. },
  63. {
  64. path: '*',
  65. redirect: '/404'
  66. }
  67. ];
  68. //路由格式
  69. // 自定义路由文件
  70. const setListMunt = (arrList, item) => {
  71. let newOb = {};
  72. newOb = {
  73. path: `/${item.linkPath}`,
  74. component: () => import(`@/views/${item.linkPath}.vue`),
  75. meta: { title: item.name },
  76. name: `${item.linkPath}`
  77. };
  78. arrList.push(newOb);
  79. };
  80. const dimension = (arrList, arr) => {
  81. arr.forEach((item, index) => {
  82. //默认去掉第一个添加路由
  83. // if (item.linkPath !== 'workbench/index') {
  84. // if (!!item.children) {
  85. // dimension(arrList, item.children);
  86. // } else {
  87. // setListMunt(arrList, item);
  88. // }
  89. // }
  90. if (!!item.children) {
  91. dimension(arrList, item.children);
  92. } else {
  93. setListMunt(arrList, item);
  94. }
  95. });
  96. };
  97. //添加路由
  98. const AddRt = (router, dynamicMuenList) => {
  99. let NEWdynamicMuenList = [...dynamicMuenList, ...staticMuen];
  100. if (NEWdynamicMuenList.length !== 0) {
  101. NEWdynamicMuenList.forEach((item) => {
  102. router.options.routes[0].children.push(item);
  103. });
  104. router.addRoutes(router.options.routes);
  105. }
  106. };
  107. export const funcRouter = (arr, data, router) => {
  108. dimension(arr, data);
  109. store.commit('setMenuList', data);
  110. AddRt(router, arr);
  111. };