routes.jsx 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. import {
  2. CommentOutlined,
  3. ProjectOutlined,
  4. SettingOutlined,
  5. TeamOutlined,
  6. UsergroupAddOutlined,
  7. BankOutlined,
  8. GoldOutlined,
  9. EnvironmentOutlined,
  10. BranchesOutlined,
  11. NodeIndexOutlined,
  12. } from '@ant-design/icons';
  13. import { Outlet } from 'react-router-dom';
  14. import AuthLayout from "@/layouts/AuthLayout";
  15. import Login from '@/pages/login';
  16. import Page404 from '@/pages/404';
  17. import Role from '@/pages/role/index';
  18. import User from '@/pages/user/index';
  19. import UserEdit from '@/pages/user/Edit';
  20. import CheckList from '@/pages/check';
  21. import CheckEdit from '@/pages/check/Edit';
  22. import OrgList from "@/pages/org/index";
  23. import Index from '@/pages/index';
  24. import Home from "@/pages/sample/home";
  25. import BasicForm from '@/pages/sample/form';
  26. import BasicTable from '@/pages/sample/table';
  27. import PositionList from "@/pages/position/list";
  28. import PositionEdit from "@/pages/position/edit";
  29. import LocTypeList from "@/pages/locType/list";
  30. import LocTypeEdit from "@/pages/locType/edit";
  31. import IssueTypeList from "@/pages/issueType/list";
  32. import IssueTypeEdit from "@/pages/issueType/edit";
  33. import QuestionList from "@/pages/question/list";
  34. import IssueList from '@/pages/issue';
  35. /**
  36. * meta 用来扩展自定义数据数据
  37. * {
  38. * title: 用于页面或者菜单的标题, 没有此字段, 菜单不会显示
  39. * hideInMenu: 布尔值, 如果为 false, 菜单不会显示
  40. * noLayout: 布尔值, 如果为 true, 将不会使用默认布局
  41. * noSiderBar: 布尔值, 如果为 true, 将没有左侧菜单栏
  42. * noFooter: 布尔值, 如果为 true, 将没有底部 footer
  43. * target: 字符串, 如果为 _blank, 将在新窗口打开
  44. * permission: 对应服务器端权限名称
  45. * menuType: ANTD 的 menuItem 的 type 属性,
  46. * }
  47. */
  48. export const authRoutes = [
  49. {
  50. path: "",
  51. element: <Outlet />,
  52. meta: {
  53. title: '业务管理',
  54. menuType: 'group',
  55. },
  56. children: [
  57. {
  58. path: "issue",
  59. element: <IssueList />,
  60. meta: {
  61. title: '问 题 单',
  62. icon: <CommentOutlined />,
  63. }
  64. },
  65. {
  66. path: "check",
  67. element: <CheckList />,
  68. meta: {
  69. title: '模拟测评',
  70. icon: <ProjectOutlined />,
  71. }
  72. },
  73. {
  74. path: "check/edit",
  75. element: <CheckEdit />,
  76. meta: {
  77. hideInMenu: true,
  78. title: '模拟测评',
  79. icon: <ProjectOutlined />,
  80. }
  81. },
  82. ],
  83. },
  84. {
  85. path: "system",
  86. element: <Outlet />,
  87. meta: {
  88. title: '基础字典',
  89. icon: <ProjectOutlined />,
  90. menuType: 'group',
  91. // permission: 'form',
  92. },
  93. children: [
  94. {
  95. path: "locType/list",
  96. element: <LocTypeList />,
  97. meta: {
  98. title: '点位分类',
  99. icon: <EnvironmentOutlined />,
  100. // permission: 'form',
  101. },
  102. },
  103. {
  104. path: "locType/edit",
  105. element: <LocTypeEdit />,
  106. meta: {
  107. hideInMenu: true,
  108. title: '点位分类编辑',
  109. // icon: <AppstoreOutlined />,
  110. // permission: 'form',
  111. },
  112. },
  113. {
  114. path: "issueType/list",
  115. element: <IssueTypeList />,
  116. meta: {
  117. title: '问题分类',
  118. icon: <BranchesOutlined />,
  119. // permission: 'form',
  120. },
  121. },
  122. {
  123. path: "issueType/edit",
  124. element: <IssueTypeEdit />,
  125. meta: {
  126. hideInMenu: true,
  127. title: '问题分类编辑',
  128. // icon: <AppstoreOutlined />,
  129. // permission: 'form',
  130. },
  131. },
  132. {
  133. path: "question/list",
  134. element: <QuestionList />,
  135. meta: {
  136. title: '点位问题',
  137. icon: <NodeIndexOutlined />,
  138. // permission: 'form',
  139. },
  140. },
  141. ]
  142. },
  143. {
  144. path: "system",
  145. element: <Outlet />,
  146. meta: {
  147. title: '系统管理',
  148. icon: <SettingOutlined />,
  149. menuType: 'group',
  150. // permission: 'form',
  151. },
  152. children: [
  153. {
  154. path: "user",
  155. element: <User />,
  156. meta: {
  157. title: '人员管理',
  158. icon: <TeamOutlined />,
  159. // permission: 'form',
  160. },
  161. },
  162. {
  163. path: "user/edit",
  164. element: <UserEdit />,
  165. meta: {
  166. title: '人员维护',
  167. hideInMenu: true,
  168. // icon: <AppstoreOutlined />,
  169. // permission: 'form',
  170. },
  171. },
  172. {
  173. path: "role",
  174. element: <Role />,
  175. meta: {
  176. title: '角色管理',
  177. icon: <UsergroupAddOutlined />,
  178. // permission: 'form',
  179. },
  180. },
  181. {
  182. path: "org",
  183. element: <OrgList />,
  184. meta: {
  185. title: '机构管理',
  186. icon: <BankOutlined />,
  187. // permission: 'form',
  188. },
  189. },
  190. {
  191. path: "position/list",
  192. element: <PositionList />,
  193. meta: {
  194. title: '岗位管理',
  195. icon: <GoldOutlined />,
  196. // permission: 'form',
  197. },
  198. },
  199. {
  200. path: "position/edit",
  201. element: <PositionEdit />,
  202. meta: {
  203. hideInMenu: true,
  204. title: '岗位管理编辑',
  205. // icon: <AppstoreOutlined />,
  206. // permission: 'form',
  207. },
  208. },
  209. ]
  210. },
  211. // {
  212. // path: "form",
  213. // element: <BasicForm />,
  214. // meta: {
  215. // title: '表单',
  216. // icon: <AppstoreOutlined />,
  217. // permission: 'form',
  218. // },
  219. // },
  220. // {
  221. // path: "table",
  222. // element: <BasicTable />,
  223. // meta: {
  224. // title: '表格',
  225. // icon: <ContainerOutlined />,
  226. // permission: 'table',
  227. // },
  228. // },
  229. ];
  230. export const defaultRoutes = [
  231. {
  232. path: "/",
  233. element: <AuthLayout />,
  234. children: [
  235. {
  236. index: true,
  237. element: <Home />,
  238. },
  239. {
  240. path: '*',
  241. element: <Page404 />
  242. }
  243. ],
  244. },
  245. {
  246. path: '/login',
  247. element: <Login />,
  248. },
  249. {
  250. path: '*',
  251. element: <Page404 />
  252. }
  253. ]
  254. export function mergeAuthRoutes (r1, r2) {
  255. const r = r1.slice();
  256. const children = r1[0].children.slice();
  257. r[0].children = children.concat(r2);
  258. return r;
  259. }
  260. // 全部路由
  261. export const routes = mergeAuthRoutes(defaultRoutes, authRoutes);
  262. function getPath (parent = "/", current = "") {
  263. if (current.indexOf("/") === 0 || current.indexOf("http") === 0)
  264. return current;
  265. return `${parent}/${current}`.replace(/\/\//g, "/");
  266. }
  267. // 路由数组, 一维数组
  268. export const routeArr = (() => {
  269. const flatten = (routes, parentPath = "/") => {
  270. return routes.reduce((acc, route) => {
  271. const path = getPath(parentPath, route.path);
  272. const children = route.children ? flatten(route.children, path) : [];
  273. return acc.concat([{ ...route, path }].concat(children));
  274. }, []);
  275. };
  276. return flatten(routes);
  277. })();