routes.jsx 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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";
  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 RotationChartDetail from "@/pages/rotationChart/detail";
  37. import Roles from "@/pages/roles/index";
  38. import RegulationList from "@/regulation";
  39. import RegulationEdit from "@/regulation/edit";
  40. import UserList from "@/pages/user";
  41. import UserEdit from "@/pages/user/Edit";
  42. import PurchasePlanList from "@/pages/purchase/plan/list";
  43. import PurchasePlanEdit from "@/pages/purchase/plan/edit";
  44. import PurchaseBillEdit from "@/pages/purchase/bill/edit";
  45. import PurchaseInStoreEdit from "@/pages/purchase/inStore/edit";
  46. import EmergencyPlanList from "@/pages/cms/emergencyPlan/list";
  47. import EmergencyPlanEdit from "@/pages/cms/emergencyPlan/edit";
  48. import EmergencyPlanDetail from "@/pages/cms/emergencyPlan/detail";
  49. import FilesList from "@/pages/cms/files/list";
  50. import MessageList from "@/pages/message";
  51. import MessageDetail from "@/pages/message/detail";
  52. import StatisCharts from "@/pages/statis/charts";
  53. /**
  54. * meta 用来扩展自定义数据数据
  55. * {
  56. * title: 用于页面或者菜单的标题, 没有此字段, 菜单不会显示
  57. * hideInMenu: 布尔值, 如果为 false, 菜单不会显示
  58. * noLayout: 布尔值, 如果为 true, 将不会使用默认布局
  59. * noSiderBar: 布尔值, 如果为 true, 将没有左侧菜单栏
  60. * noFooter: 布尔值, 如果为 true, 将没有底部 footer
  61. * target: 字符串, 如果为 _blank, 将在新窗口打开
  62. * }
  63. */
  64. export const authRoutes = [
  65. {
  66. path: "task",
  67. element: <Container />,
  68. meta: {
  69. title: "军供任务",
  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: "stock",
  119. element: <Container />,
  120. meta: {
  121. title: "库存物资",
  122. },
  123. children: [
  124. {
  125. index: true,
  126. element: <Navigate to="dish/list" replace />,
  127. },
  128. {
  129. path: "dish/list",
  130. element: <DishList />,
  131. meta: {
  132. title: "菜肴管理",
  133. },
  134. },
  135. {
  136. path: "dish/edit",
  137. element: <DishEdit />,
  138. meta: {
  139. hideInMenu: true,
  140. title: "菜肴维护",
  141. },
  142. },
  143. {
  144. path: "package/list",
  145. element: <PackageList />,
  146. meta: {
  147. title: "套餐管理",
  148. },
  149. },
  150. {
  151. path: "list",
  152. element: <StockList />,
  153. meta: {
  154. title: "库存列表",
  155. },
  156. },
  157. {
  158. path: "add",
  159. element: <StockEdit />,
  160. meta: {
  161. title: "库存维护",
  162. },
  163. },
  164. ],
  165. },
  166. {
  167. path: "cms",
  168. element: <Container />,
  169. meta: {
  170. title: "公告文件",
  171. },
  172. children: [
  173. {
  174. index: true,
  175. element: <Navigate to="rotationChart/list" replace />,
  176. },
  177. {
  178. path: "station",
  179. element: null,
  180. meta: {
  181. title: "本站信息",
  182. },
  183. },
  184. {
  185. path: "rotationChart/list",
  186. element: <RotationChartList />,
  187. meta: {
  188. title: "公告管理",
  189. },
  190. },
  191. {
  192. path: "rotationChart/add",
  193. element: <RotationChartEdit />,
  194. meta: {
  195. title: "公告维护",
  196. hideInMenu: true,
  197. },
  198. },
  199. {
  200. path: "rotationChart/detail",
  201. element: <RotationChartDetail />,
  202. meta: {
  203. title: "公告详情",
  204. hideInMenu: true,
  205. },
  206. },
  207. {
  208. path: "rotationChart/introduction",
  209. element: <RotationChartIntroduction />,
  210. meta: {
  211. title: "本站信息简介",
  212. },
  213. },
  214. {
  215. path: "rotationChart/introduction/edit",
  216. element: <RotationChartIntroductionEdit />,
  217. meta: {
  218. hideInMenu: true,
  219. title: "本站信息简介维护",
  220. },
  221. },
  222. {
  223. path: "regulation",
  224. element: <RegulationList />,
  225. meta: {
  226. title: "规章制度",
  227. },
  228. },
  229. {
  230. path: "regulation/add",
  231. element: <RegulationEdit />,
  232. meta: {
  233. hideInMenu: true,
  234. title: "规章制度维护",
  235. },
  236. },
  237. {
  238. path: "emergency-plan",
  239. element: <EmergencyPlanList />,
  240. meta: {
  241. title: "应急预案",
  242. },
  243. },
  244. {
  245. path: "emergency-plan/edit",
  246. element: <EmergencyPlanEdit />,
  247. meta: {
  248. title: "应急预案维护",
  249. hideInMenu: true,
  250. },
  251. },
  252. {
  253. path: "emergency-plan/detail",
  254. element: <EmergencyPlanDetail />,
  255. meta: {
  256. title: "应急预案详情",
  257. hideInMenu: true,
  258. },
  259. },
  260. {
  261. path: "files",
  262. element: <FilesList />,
  263. meta: {
  264. title: "文件管理",
  265. },
  266. },
  267. ],
  268. },
  269. {
  270. path: "static",
  271. element: <StatisCharts />,
  272. meta: {
  273. title: "数据分析",
  274. noSiderBar: true,
  275. noFooter: true,
  276. },
  277. },
  278. {
  279. path: "purchase",
  280. element: <Container />,
  281. meta: {
  282. title: "采购管理",
  283. },
  284. children: [
  285. {
  286. index: true,
  287. element: <Navigate to="plan/list" replace />,
  288. },
  289. {
  290. path: "plan/list",
  291. element: <PurchasePlanList type="plan" />,
  292. meta: {
  293. title: "采购计划",
  294. },
  295. },
  296. {
  297. path: "plan/edit",
  298. element: <PurchasePlanEdit />,
  299. meta: {
  300. title: "采购计划维护",
  301. hideInMenu: true,
  302. },
  303. },
  304. {
  305. path: "bill/list",
  306. element: <PurchasePlanList type="bill" />,
  307. meta: {
  308. title: "采购账单",
  309. },
  310. },
  311. {
  312. path: "bill/edit",
  313. element: <PurchaseBillEdit />,
  314. meta: {
  315. title: "采购账单维护",
  316. hideInMenu: true,
  317. },
  318. },
  319. {
  320. path: "inStore/list",
  321. element: <PurchasePlanList type="inStore" />,
  322. meta: {
  323. title: "采购入库",
  324. },
  325. },
  326. {
  327. path: "inStore/edit",
  328. element: <PurchaseInStoreEdit />,
  329. meta: {
  330. title: "采购入库维护",
  331. hideInMenu: true,
  332. },
  333. },
  334. ],
  335. },
  336. {
  337. path: "system",
  338. element: <Container />,
  339. meta: {
  340. title: "系统管理",
  341. },
  342. children: [
  343. {
  344. index: true,
  345. element: <Navigate to="stockClassification/list" replace />,
  346. },
  347. {
  348. path: DH_MONITOR,
  349. element: null,
  350. meta: {
  351. title: "大华监控",
  352. },
  353. },
  354. {
  355. path: DH_MONITOR,
  356. element: null,
  357. meta: {
  358. title: "海康监控",
  359. },
  360. },
  361. {
  362. path: "stockClassification/list",
  363. element: <StockClassificationList />,
  364. meta: {
  365. title: "库存分类",
  366. },
  367. },
  368. {
  369. path: "stockClassification/edit",
  370. element: <StockClassificationEdit />,
  371. meta: {
  372. title: "库存分类维护",
  373. hideInMenu: true,
  374. },
  375. },
  376. {
  377. path: "log",
  378. element: <StockLog />,
  379. meta: {
  380. title: "库存日志",
  381. },
  382. },
  383. {
  384. path: "roles",
  385. element: <Roles />,
  386. meta: {
  387. title: "角色管理",
  388. },
  389. },
  390. {
  391. path: "user",
  392. element: <UserList />,
  393. meta: {
  394. title: "用户管理",
  395. },
  396. },
  397. {
  398. path: "user/edit",
  399. element: <UserEdit />,
  400. meta: {
  401. hideInMenu: true,
  402. title: "系统用户编辑",
  403. },
  404. },
  405. {
  406. path: "message",
  407. element: <MessageList />,
  408. meta: {
  409. title: "消息列表",
  410. },
  411. },
  412. {
  413. path: "message/detail",
  414. element: <MessageDetail />,
  415. meta: {
  416. title: "消息详情",
  417. hideInMenu: true,
  418. },
  419. },
  420. {
  421. path: "foo",
  422. element: null,
  423. meta: {
  424. title: "操作手册",
  425. },
  426. },
  427. ],
  428. },
  429. ];
  430. export const defaultRoutes = [
  431. {
  432. path: "/",
  433. element: <AuthLayout />,
  434. children: [
  435. {
  436. index: true,
  437. element: <Navigate to="home" replace />,
  438. },
  439. {
  440. path: "home",
  441. element: <Home />,
  442. meta: {
  443. title: "首页",
  444. icon: <DesktopOutlined />,
  445. noSiderBar: true,
  446. noFooter: true,
  447. },
  448. },
  449. {
  450. path: "*",
  451. element: <Page404 />,
  452. },
  453. ],
  454. },
  455. {
  456. path: "/login",
  457. element: <Login />,
  458. },
  459. {
  460. path: "*",
  461. element: <Page404 />,
  462. },
  463. ];
  464. export function mergeAuthRoutes(r1, r2) {
  465. const r = r1.slice();
  466. const children = r1[0].children.slice();
  467. r[0].children = children.concat(r2);
  468. return r;
  469. }
  470. // 全部路由
  471. export const routes = mergeAuthRoutes(defaultRoutes, authRoutes);
  472. function getPath(parent = "/", current = "") {
  473. if (current.indexOf("/") === 0 || current.indexOf("http") === 0)
  474. return current;
  475. return `${parent}/${current}`.replace(/\/\//g, "/");
  476. }
  477. // 路由数组, 一维数组
  478. export const routeArr = (() => {
  479. const flatten = (routes, parentPath = "/") => {
  480. return routes.reduce((acc, route) => {
  481. const path = getPath(parentPath, route.path);
  482. const children = route.children ? flatten(route.children, path) : [];
  483. return acc.concat([{ ...route, path }].concat(children));
  484. }, []);
  485. };
  486. return flatten(routes);
  487. })();