routes.jsx 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. import {
  2. AppstoreOutlined,
  3. ContainerOutlined,
  4. DesktopOutlined,
  5. MailOutlined,
  6. MenuFoldOutlined,
  7. MenuUnfoldOutlined,
  8. PieChartOutlined,
  9. } from '@ant-design/icons';
  10. import { Navigate } from 'react-router-dom';
  11. import AuthLayout from '@/layouts/AuthLayout';
  12. import Container from '@/layouts/Container';
  13. import Login from '@/pages/login';
  14. import Page404 from '@/pages/404';
  15. import Home from '@/pages/sample/home';
  16. import BasicForm from '@/pages/sample/form';
  17. import BasicTable from '@/pages/sample/table';
  18. import GuaranteeTaskList from '@/pages/guaranteeTask';
  19. import GuaranteeTaskEdit from '@/pages/guaranteeTask/Edit';
  20. import GuaranteeTaskPrint from '@/pages/guaranteeTask/print';
  21. import GuaranteeTaskEvaluate from "@/pages/evaluate";
  22. import GuaranteeTaskEvaluateList from "@/pages/evaluate/evaluateList";
  23. import DishList from '@/pages/dish/list';
  24. import DishEdit from '@/pages/dish/edit';
  25. import PackageList from '@/pages/package/List';
  26. import StockList from '@/pages/stock/list';
  27. import StockEdit from '@/pages/stock/edit';
  28. import StockInOut from '@/pages/stock/outAndIn';
  29. import StockLog from '@/pages/stock/stockLog';
  30. import StockClassificationList from '@/pages/stockClassification/list';
  31. import StockClassificationEdit from '@/pages/stockClassification/edit';
  32. import RotationChartList from '@/pages/rotationChart/list';
  33. import RotationChartEdit from '@/pages/rotationChart/edit';
  34. import RotationChartIntroduction from '@/pages/rotationChart/introduction';
  35. import RotationChartIntroductionEdit from '@/pages/rotationChart/introduction/edit';
  36. import Roles from '@/pages/roles/index';
  37. import RegulationList from '@/regulation';
  38. import RegulationEdit from '@/regulation/edit';
  39. import UserList from '@/pages/user';
  40. import UserEdit from '@/pages/user/Edit';
  41. import PurchasePlanList from "@/pages/purchase/plan/list";
  42. import PurchasePlanEdit from "@/pages/purchase/plan/edit";
  43. import PurchaseBillEdit from "@/pages/purchase/bill/edit";
  44. import PurchaseInStoreEdit from "@/pages/purchase/inStore/edit";
  45. import EmergencyPlanList from "@/pages/cms/emergencyPlan/list";
  46. import EmergencyPlanEdit from "@/pages/cms/emergencyPlan/edit";
  47. import EmergencyPlanDetail from "@/pages/cms/emergencyPlan/detail";
  48. import FilesList from "@/pages/cms/files/list";
  49. import MessageList from '@/pages/message';
  50. import MessageDetail from '@/pages/message/detail';
  51. import StatisCharts from '@/pages/statis/charts';
  52. /**
  53. * meta 用来扩展自定义数据数据
  54. * {
  55. * title: 用于页面或者菜单的标题, 没有此字段, 菜单不会显示
  56. * hideInMenu: 布尔值, 如果为 false, 菜单不会显示
  57. * noLayout: 布尔值, 如果为 true, 将不会使用默认布局
  58. * noSiderBar: 布尔值, 如果为 true, 将没有左侧菜单栏
  59. * noFooter: 布尔值, 如果为 true, 将没有底部 footer
  60. * target: 字符串, 如果为 _blank, 将在新窗口打开
  61. * }
  62. */
  63. export const authRoutes = [
  64. {
  65. path: "task",
  66. element: <Container />,
  67. meta: {
  68. title: "军供任务",
  69. icon: <AppstoreOutlined />,
  70. },
  71. children: [
  72. {
  73. index: true,
  74. element: <Navigate to="guaranteeTask" replace />,
  75. },
  76. {
  77. path: "guaranteeTask",
  78. element: <GuaranteeTaskList />,
  79. meta: {
  80. title: "任务通报",
  81. },
  82. },
  83. {
  84. path: "guaranteeTask/edit",
  85. element: <GuaranteeTaskEdit />,
  86. meta: {
  87. title: "任务配置",
  88. },
  89. },
  90. {
  91. path: "guaranteeTask/print",
  92. element: <GuaranteeTaskPrint />,
  93. meta: {
  94. hideInMenu: true,
  95. noLayout: true,
  96. target: "_blank",
  97. title: "任务执行",
  98. },
  99. },
  100. {
  101. path: "evaluate",
  102. element: <GuaranteeTaskEvaluate />,
  103. meta: {
  104. title: "任务评价",
  105. },
  106. },
  107. {
  108. path: "evaluate/list",
  109. element: <GuaranteeTaskEvaluateList />,
  110. meta: {
  111. title: "任务评价",
  112. hideInMenu: true,
  113. },
  114. },
  115. ],
  116. },
  117. {
  118. path: "material",
  119. element: <Container />,
  120. meta: {
  121. title: "物资管理",
  122. icon: <AppstoreOutlined />,
  123. },
  124. children: [
  125. {
  126. index: true,
  127. element: <Navigate to="dish/list" replace />,
  128. },
  129. {
  130. path: "dish/list",
  131. element: <DishList />,
  132. meta: {
  133. title: "菜肴管理",
  134. },
  135. },
  136. {
  137. path: "dish/edit",
  138. element: <DishEdit />,
  139. meta: {
  140. hideInMenu: true,
  141. title: "菜肴维护",
  142. },
  143. },
  144. {
  145. path: "package/list",
  146. element: <PackageList />,
  147. meta: {
  148. title: "套餐管理",
  149. },
  150. },
  151. ],
  152. },
  153. {
  154. path: "stock",
  155. element: <Container />,
  156. meta: {
  157. title: "库存管理",
  158. icon: <AppstoreOutlined />,
  159. },
  160. children: [
  161. {
  162. index: true,
  163. element: <Navigate to="list" replace />,
  164. },
  165. {
  166. path: "list",
  167. element: <StockList />,
  168. meta: {
  169. title: "库存列表",
  170. },
  171. },
  172. {
  173. path: "add",
  174. element: <StockEdit />,
  175. meta: {
  176. title: "库存维护",
  177. },
  178. },
  179. ],
  180. },
  181. {
  182. path: "cms",
  183. element: <Container />,
  184. meta: {
  185. title: "公告文件",
  186. },
  187. children: [
  188. {
  189. index: true,
  190. element: <Navigate to="rotationChart/list" replace />,
  191. },
  192. {
  193. path: "rotationChart/introduction",
  194. element: <RotationChartIntroductionEdit />,
  195. meta: {
  196. title: "本站信息",
  197. },
  198. },
  199. {
  200. path: "rotationChart/list",
  201. element: <RotationChartList />,
  202. meta: {
  203. title: "公告内容",
  204. },
  205. },
  206. {
  207. path: "rotationChart/add",
  208. element: <RotationChartEdit />,
  209. meta: {
  210. title: "公告维护",
  211. },
  212. },
  213. {
  214. path: 'regulation',
  215. element: <RegulationList />,
  216. meta: {
  217. title: "规章制度",
  218. },
  219. },
  220. {
  221. path: 'regulation/add',
  222. element: <RegulationEdit />,
  223. meta: {
  224. hideInMenu: true,
  225. title: '规章制度维护',
  226. },
  227. },
  228. {
  229. path: "emergency-plan",
  230. element: <EmergencyPlanList />,
  231. meta: {
  232. title: "应急预案",
  233. },
  234. },
  235. {
  236. path: "emergency-plan/edit",
  237. element: <EmergencyPlanEdit />,
  238. meta: {
  239. title: "应急预案维护",
  240. hideInMenu: true,
  241. },
  242. },
  243. {
  244. path: "emergency-plan/detail",
  245. element: <EmergencyPlanDetail />,
  246. meta: {
  247. title: "应急预案详情",
  248. hideInMenu: true,
  249. },
  250. },
  251. {
  252. path: "files",
  253. element: <FilesList />,
  254. meta: {
  255. title: "文件管理",
  256. },
  257. },
  258. ],
  259. },
  260. {
  261. path: 'static',
  262. element: <StatisCharts />,
  263. meta: {
  264. title: '数据分析',
  265. noSiderBar: true,
  266. noFooter: true,
  267. },
  268. },
  269. {
  270. path: "system",
  271. element: <Container />,
  272. meta: {
  273. title: "系统管理",
  274. },
  275. children: [
  276. {
  277. index: true,
  278. element: <Navigate to="stockClassification/list" replace />,
  279. },
  280. {
  281. path: "stockClassification/list",
  282. element: <StockClassificationList />,
  283. meta: {
  284. title: "库存分类",
  285. },
  286. },
  287. {
  288. path: "stockClassification/edit",
  289. element: <StockClassificationEdit />,
  290. meta: {
  291. title: "库存分类维护",
  292. hideInMenu: true,
  293. },
  294. },
  295. {
  296. path: "log",
  297. element: <StockLog />,
  298. meta: {
  299. title: "操作日志",
  300. },
  301. },
  302. {
  303. path: "roles",
  304. element: <Roles />,
  305. meta: {
  306. title: "角色管理",
  307. },
  308. },
  309. {
  310. path: "user",
  311. element: <UserList />,
  312. meta: {
  313. title: "用户管理",
  314. },
  315. },
  316. {
  317. path: "user/edit",
  318. element: <UserEdit />,
  319. meta: {
  320. hideInMenu: true,
  321. title: "系统用户编辑",
  322. },
  323. },
  324. {
  325. path: "message",
  326. element: <MessageList />,
  327. meta: {
  328. title: "消息列表",
  329. },
  330. },
  331. {
  332. path: "message/detail",
  333. element: <MessageDetail />,
  334. meta: {
  335. title: "消息详情",
  336. hideInMenu: true,
  337. },
  338. },
  339. ],
  340. },
  341. {
  342. path: "purchase",
  343. element: <Container />,
  344. meta: {
  345. title: "采购管理",
  346. },
  347. children: [
  348. {
  349. index: true,
  350. element: <Navigate to="plan/list" replace />,
  351. },
  352. {
  353. path: "plan/list",
  354. element: <PurchasePlanList type="plan" />,
  355. meta: {
  356. title: "采购计划",
  357. },
  358. },
  359. {
  360. path: "plan/edit",
  361. element: <PurchasePlanEdit />,
  362. meta: {
  363. title: "采购计划维护",
  364. hideInMenu: true,
  365. },
  366. },
  367. {
  368. path: "bill/list",
  369. element: <PurchasePlanList type="bill" />,
  370. meta: {
  371. title: "采购账单",
  372. },
  373. },
  374. {
  375. path: "bill/edit",
  376. element: <PurchaseBillEdit />,
  377. meta: {
  378. title: "采购账单维护",
  379. hideInMenu: true,
  380. },
  381. },
  382. {
  383. path: "inStore/list",
  384. element: <PurchasePlanList type="inStore" />,
  385. meta: {
  386. title: "采购入库",
  387. },
  388. },
  389. {
  390. path: "inStore/edit",
  391. element: <PurchaseInStoreEdit />,
  392. meta: {
  393. title: "采购入库维护",
  394. hideInMenu: true,
  395. },
  396. },
  397. ],
  398. },
  399. ];
  400. export const defaultRoutes = [
  401. {
  402. path: "/",
  403. element: <AuthLayout />,
  404. children: [
  405. {
  406. index: true,
  407. element: <Home />,
  408. },
  409. {
  410. path: "home",
  411. element: <Home />,
  412. meta: {
  413. title: "首页",
  414. icon: <DesktopOutlined />,
  415. },
  416. },
  417. {
  418. path: "*",
  419. element: <Page404 />,
  420. },
  421. ],
  422. },
  423. {
  424. path: "/login",
  425. element: <Login />,
  426. },
  427. {
  428. path: "*",
  429. element: <Page404 />,
  430. },
  431. ];
  432. export function mergeAuthRoutes (r1, r2) {
  433. const r = r1.slice();
  434. const children = r1[0].children.slice();
  435. r[0].children = children.concat(r2);
  436. return r;
  437. }
  438. // 全部路由
  439. export const routes = mergeAuthRoutes(defaultRoutes, authRoutes);
  440. function getPath (parent = "/", current = "") {
  441. if (current.indexOf("/") === 0 || current.indexOf("http") === 0)
  442. return current;
  443. return `${parent}/${current}`.replace(/\/\//g, "/");
  444. }
  445. // 路由数组, 一维数组
  446. export const routeArr = (() => {
  447. const flatten = (routes, parentPath = "/") => {
  448. return routes.reduce((acc, route) => {
  449. const path = getPath(parentPath, route.path);
  450. const children = route.children ? flatten(route.children, path) : [];
  451. return acc.concat([{ ...route, path }].concat(children));
  452. }, []);
  453. };
  454. return flatten(routes);
  455. })();