routes.jsx 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import {
  2. AppstoreOutlined,
  3. ContainerOutlined,
  4. DesktopOutlined,
  5. MailOutlined,
  6. MenuFoldOutlined,
  7. MenuUnfoldOutlined,
  8. PieChartOutlined,
  9. } from '@ant-design/icons';
  10. import AuthLayout from "@/layouts/AuthLayout";
  11. import PageContainer from "@/layouts/PageContainer";
  12. import Login from '@/pages/login';
  13. import Page404 from '@/pages/404';
  14. import Index from '@/pages/index';
  15. import Home from "@/pages/sample/home";
  16. import BasicForm from '@/pages/sample/form';
  17. import BasicTable from '@/pages/sample/table';
  18. /**
  19. * meta 用来扩展自定义数据数据
  20. * {
  21. * title: 用于页面或者菜单的标题, 没有此字段, 菜单不会显示
  22. * hideInMenu: 布尔值, 如果为 false, 菜单不会显示
  23. * noLayout: 布尔值, 如果为 true, 将不会使用默认布局
  24. * noSiderBar: 布尔值, 如果为 true, 将没有左侧菜单栏
  25. * noFooter: 布尔值, 如果为 true, 将没有底部 footer
  26. * target: 字符串, 如果为 _blank, 将在新窗口打开
  27. * permission: 对应服务器端权限名称
  28. * }
  29. */
  30. export const authRoutes = [
  31. {
  32. path: 'index',
  33. element: <Index />,
  34. },
  35. {
  36. path: "system",
  37. element: <PageContainer />,
  38. meta: {
  39. title: '系统管理',
  40. // icon: <AppstoreOutlined />,
  41. // permission: 'form',
  42. },
  43. children: [
  44. {
  45. path: "user",
  46. element: <Index />,
  47. meta: {
  48. title: '人员管理',
  49. // icon: <AppstoreOutlined />,
  50. // permission: 'form',
  51. },
  52. },
  53. {
  54. path: "role",
  55. element: <Index />,
  56. meta: {
  57. title: '角色管理',
  58. // icon: <AppstoreOutlined />,
  59. // permission: 'form',
  60. },
  61. },
  62. ]
  63. },
  64. // {
  65. // path: "form",
  66. // element: <BasicForm />,
  67. // meta: {
  68. // title: '表单',
  69. // icon: <AppstoreOutlined />,
  70. // permission: 'form',
  71. // },
  72. // },
  73. // {
  74. // path: "table",
  75. // element: <BasicTable />,
  76. // meta: {
  77. // title: '表格',
  78. // icon: <ContainerOutlined />,
  79. // permission: 'table',
  80. // },
  81. // },
  82. ];
  83. export const defaultRoutes = [
  84. {
  85. path: "/",
  86. element: <AuthLayout />,
  87. children: [
  88. {
  89. index: true,
  90. element: <Home />,
  91. },
  92. {
  93. path: "home",
  94. element: <Home />,
  95. meta: {
  96. title: '首页',
  97. icon: <DesktopOutlined />,
  98. },
  99. },
  100. {
  101. path: '*',
  102. element: <Page404 />
  103. }
  104. ],
  105. },
  106. {
  107. path: '/login',
  108. element: <Login />,
  109. },
  110. {
  111. path: '*',
  112. element: <Page404 />
  113. }
  114. ]
  115. export function mergeAuthRoutes (r1, r2) {
  116. const r = r1.slice();
  117. const children = r1[0].children.slice();
  118. r[0].children = children.concat(r2);
  119. return r;
  120. }
  121. // 全部路由
  122. export const routes = mergeAuthRoutes(defaultRoutes, authRoutes);
  123. function getPath (parent = "/", current = "") {
  124. if (current.indexOf("/") === 0 || current.indexOf("http") === 0)
  125. return current;
  126. return `${parent}/${current}`.replace(/\/\//g, "/");
  127. }
  128. // 路由数组, 一维数组
  129. export const routeArr = (() => {
  130. const flatten = (routes, parentPath = "/") => {
  131. return routes.reduce((acc, route) => {
  132. const path = getPath(parentPath, route.path);
  133. const children = route.children ? flatten(route.children, path) : [];
  134. return acc.concat([{ ...route, path }].concat(children));
  135. }, []);
  136. };
  137. return flatten(routes);
  138. })();