dynamicMuen.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/error/403.vue'),
  11. meta: { title: '403' }
  12. },
  13. {
  14. path: '/404',
  15. component: () => import(/* webpackChunkName: "404" */ '@views/error/404.vue'),
  16. meta: { title: '404' }
  17. },
  18. {
  19. path: '/instrumentViewDetail',
  20. component: () => import(/* webpackChunkName: "404" */ '@views/instrumentManagement/setPage/viewDetail.vue'),
  21. meta: { title: '设备详情' }
  22. },
  23. {
  24. path: '*',
  25. redirect: '/404'
  26. }
  27. ];
  28. //路由格式
  29. // 自定义路由文件
  30. const setListMunt = (arrList, item) => {
  31. let newOb = {};
  32. newOb = {
  33. path: `/${item.linkPath}`,
  34. component: () => import(`@/views/${item.linkPath}.vue`),
  35. meta: { title: item.name }
  36. };
  37. arrList.push(newOb);
  38. };
  39. const dimension = (arrList, arr) => {
  40. arr.forEach((item, index) => {
  41. if (!!item.children) {
  42. dimension(arrList, item.children);
  43. } else {
  44. setListMunt(arrList, item);
  45. }
  46. });
  47. };
  48. //添加路由
  49. const AddRt = (router, dynamicMuenList) => {
  50. let NEWdynamicMuenList = [...dynamicMuenList, ...staticMuen];
  51. if (NEWdynamicMuenList.length !== 0) {
  52. NEWdynamicMuenList.forEach((item) => {
  53. router.options.routes[0].children.push(item);
  54. });
  55. router.addRoutes(router.options.routes);
  56. }
  57. };
  58. export const funcRouter = (arr, data, router) => {
  59. dimension(arr, data);
  60. store.commit('setMenuList', data);
  61. AddRt(router, arr);
  62. };