routes.jsx 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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. * permission: 对应服务器端权限名称
  63. * }
  64. */
  65. export const authRoutes = [
  66. {
  67. path: "static",
  68. element: <StatisCharts />,
  69. meta: {
  70. title: "数据分析",
  71. noSiderBar: true,
  72. noFooter: true,
  73. permission: 'static',
  74. },
  75. },
  76. {
  77. path: "task",
  78. element: <Container />,
  79. meta: {
  80. title: "军供任务",
  81. permission: 'task',
  82. },
  83. children: [
  84. {
  85. index: true,
  86. element: <Navigate to="guaranteeTask" replace />,
  87. },
  88. {
  89. path: "guaranteeTask",
  90. element: <GuaranteeTaskList />,
  91. meta: {
  92. title: "军供通报",
  93. permission: 'guaranteeTask',
  94. },
  95. },
  96. {
  97. path: "guaranteeTask/edit",
  98. element: <GuaranteeTaskEdit />,
  99. meta: {
  100. title: "任务配置",
  101. permission: 'guaranteeTask.edit',
  102. },
  103. },
  104. {
  105. path: "guaranteeTask/print",
  106. element: <GuaranteeTaskPrint />,
  107. meta: {
  108. hideInMenu: true,
  109. noLayout: true,
  110. target: "_blank",
  111. title: "任务执行",
  112. permission: 'guaranteeTask.print',
  113. },
  114. },
  115. {
  116. path: "evaluate",
  117. element: <GuaranteeTaskEvaluate />,
  118. meta: {
  119. title: "任务评价",
  120. permission: 'guaranteeTask.evaluate',
  121. },
  122. },
  123. {
  124. path: "evaluate/list",
  125. element: <GuaranteeTaskEvaluateList />,
  126. meta: {
  127. title: "任务评价",
  128. hideInMenu: true,
  129. permission: 'guaranteeTask.evaluate.list',
  130. },
  131. },
  132. ],
  133. },
  134. {
  135. path: "stock",
  136. element: <Container />,
  137. meta: {
  138. title: "库存物资",
  139. permission: 'stock',
  140. },
  141. children: [
  142. {
  143. index: true,
  144. element: <Navigate to="dish/list" replace />,
  145. },
  146. {
  147. path: "dish/list",
  148. element: <DishList />,
  149. meta: {
  150. title: "菜肴管理",
  151. permission: 'dish',
  152. },
  153. },
  154. {
  155. path: "dish/edit",
  156. element: <DishEdit />,
  157. meta: {
  158. hideInMenu: true,
  159. title: "菜肴维护",
  160. permission: 'dish.edit',
  161. },
  162. },
  163. {
  164. path: "package/list",
  165. element: <PackageList />,
  166. meta: {
  167. title: "套餐管理",
  168. permission: 'package',
  169. },
  170. },
  171. {
  172. path: "list",
  173. element: <StockList />,
  174. meta: {
  175. title: "库存列表",
  176. permission: 'stock.list',
  177. },
  178. },
  179. {
  180. path: "add",
  181. element: <StockEdit />,
  182. meta: {
  183. title: "库存维护",
  184. permission: 'stock.edit',
  185. },
  186. },
  187. ],
  188. },
  189. {
  190. path: "purchase",
  191. element: <Container />,
  192. meta: {
  193. title: "采购管理",
  194. permission: 'purchase',
  195. },
  196. children: [
  197. {
  198. index: true,
  199. element: <Navigate to="plan/list" replace />,
  200. },
  201. {
  202. path: "plan/list",
  203. element: <PurchasePlanList type="plan" />,
  204. meta: {
  205. title: "采购计划",
  206. permission: 'purchase.plan',
  207. },
  208. },
  209. {
  210. path: "plan/edit",
  211. element: <PurchasePlanEdit />,
  212. meta: {
  213. title: "采购计划维护",
  214. hideInMenu: true,
  215. permission: 'purchase.plan.edit',
  216. },
  217. },
  218. {
  219. path: "bill/list",
  220. element: <PurchasePlanList type="bill" />,
  221. meta: {
  222. title: "采购账单",
  223. permission: 'purchase.bill',
  224. },
  225. },
  226. {
  227. path: "bill/edit",
  228. element: <PurchaseBillEdit />,
  229. meta: {
  230. title: "采购账单维护",
  231. hideInMenu: true,
  232. permission: 'purchase.bill.edit',
  233. },
  234. },
  235. {
  236. path: "inStore/list",
  237. element: <PurchasePlanList type="inStore" />,
  238. meta: {
  239. title: "采购入库",
  240. permission: 'purchase.instore',
  241. },
  242. },
  243. {
  244. path: "inStore/edit",
  245. element: <PurchaseInStoreEdit />,
  246. meta: {
  247. title: "采购详情",
  248. permission: 'purchase.detail',
  249. hideInMenu: true,
  250. },
  251. },
  252. ],
  253. },
  254. {
  255. path: "cms",
  256. element: <Container />,
  257. meta: {
  258. title: "公告文件",
  259. permission: 'cms',
  260. },
  261. children: [
  262. {
  263. index: true,
  264. element: <Navigate to="rotationChart/list" replace />,
  265. },
  266. {
  267. path: "rotationChart/introduction",
  268. element: <RotationChartIntroductionEdit />,
  269. meta: {
  270. title: "本站信息",
  271. permission: 'station',
  272. },
  273. },
  274. {
  275. path: "rotationChart/list",
  276. element: <RotationChartList />,
  277. meta: {
  278. title: "公告管理",
  279. permission: 'rotationChart',
  280. },
  281. },
  282. {
  283. path: "rotationChart/add",
  284. element: <RotationChartEdit />,
  285. meta: {
  286. title: "公告维护",
  287. hideInMenu: true,
  288. permission: 'rotationChart.edit',
  289. },
  290. },
  291. {
  292. path: "rotationChart/detail",
  293. element: <RotationChartDetail />,
  294. meta: {
  295. title: "公告详情",
  296. hideInMenu: true,
  297. permission: 'rotationChart.detail',
  298. },
  299. },
  300. {
  301. path: "regulation",
  302. element: <RegulationList />,
  303. meta: {
  304. title: "规章制度",
  305. permission: 'regulation',
  306. },
  307. },
  308. {
  309. path: "regulation/add",
  310. element: <RegulationEdit />,
  311. meta: {
  312. hideInMenu: true,
  313. title: "规章制度维护",
  314. permission: 'regulation.edit',
  315. },
  316. },
  317. {
  318. path: "emergency-plan",
  319. element: <EmergencyPlanList />,
  320. meta: {
  321. title: "应急预案",
  322. permission: 'emergency-plan',
  323. },
  324. },
  325. {
  326. path: "emergency-plan/edit",
  327. element: <EmergencyPlanEdit />,
  328. meta: {
  329. title: "应急预案维护",
  330. hideInMenu: true,
  331. permission: 'emergency-plan.edit',
  332. },
  333. },
  334. {
  335. path: "emergency-plan/detail",
  336. element: <EmergencyPlanDetail />,
  337. meta: {
  338. title: "应急预案详情",
  339. hideInMenu: true,
  340. permission: 'emergency-plan.detail',
  341. },
  342. },
  343. {
  344. path: "files",
  345. element: <FilesList />,
  346. meta: {
  347. title: "文件管理",
  348. permission: 'files',
  349. },
  350. },
  351. ],
  352. },
  353. {
  354. path: "system",
  355. element: <Container />,
  356. meta: {
  357. title: "系统管理",
  358. permission: 'system',
  359. },
  360. children: [
  361. {
  362. index: true,
  363. element: <Navigate to="stockClassification/list" replace />,
  364. },
  365. {
  366. path: DH_MONITOR,
  367. element: null,
  368. meta: {
  369. title: "大华监控",
  370. },
  371. },
  372. {
  373. path: DH_MONITOR,
  374. element: null,
  375. meta: {
  376. title: "海康监控",
  377. },
  378. },
  379. {
  380. path: "stockClassification/list",
  381. element: <StockClassificationList />,
  382. meta: {
  383. title: "库存分类",
  384. permission: 'stockClassification',
  385. },
  386. },
  387. {
  388. path: "stockClassification/edit",
  389. element: <StockClassificationEdit />,
  390. meta: {
  391. title: "库存分类维护",
  392. hideInMenu: true,
  393. permission: 'stockClassification.edit',
  394. },
  395. },
  396. {
  397. path: "log",
  398. element: <StockLog />,
  399. meta: {
  400. title: "库存日志",
  401. permission: 'stock.log',
  402. },
  403. },
  404. {
  405. path: "roles",
  406. element: <Roles />,
  407. meta: {
  408. title: "角色管理",
  409. permission: 'role',
  410. },
  411. },
  412. {
  413. path: "user",
  414. element: <UserList />,
  415. meta: {
  416. title: "用户管理",
  417. permission: 'user',
  418. },
  419. },
  420. {
  421. path: "user/edit",
  422. element: <UserEdit />,
  423. meta: {
  424. hideInMenu: true,
  425. title: "系统用户编辑",
  426. permission: 'user.edit',
  427. },
  428. },
  429. {
  430. path: "message",
  431. element: <MessageList />,
  432. meta: {
  433. title: "消息列表",
  434. permission: 'message',
  435. },
  436. },
  437. {
  438. path: "foo",
  439. element: null,
  440. meta: {
  441. title: "操作手册",
  442. },
  443. },
  444. ],
  445. },
  446. ];
  447. export const defaultRoutes = [
  448. {
  449. path: "/",
  450. element: <AuthLayout />,
  451. children: [
  452. {
  453. index: true,
  454. element: <Navigate to="home" replace />,
  455. },
  456. {
  457. path: "home",
  458. element: <Home />,
  459. meta: {
  460. title: "首页",
  461. icon: <DesktopOutlined />,
  462. noSiderBar: true,
  463. noFooter: true,
  464. },
  465. },
  466. {
  467. path: "*",
  468. element: <Page404 />,
  469. },
  470. ],
  471. },
  472. {
  473. path: "/login",
  474. element: <Login />,
  475. },
  476. {
  477. path: "*",
  478. element: <Page404 />,
  479. },
  480. ];
  481. export function mergeAuthRoutes (r1, r2) {
  482. const r = r1.slice();
  483. const children = r1[0].children.slice();
  484. r[0].children = children.concat(r2);
  485. return r;
  486. }
  487. // 全部路由
  488. export const routes = mergeAuthRoutes(defaultRoutes, authRoutes);
  489. function getPath (parent = "/", current = "") {
  490. if (current.indexOf("/") === 0 || current.indexOf("http") === 0)
  491. return current;
  492. return `${parent}/${current}`.replace(/\/\//g, "/");
  493. }
  494. // 路由数组, 一维数组
  495. export const routeArr = (() => {
  496. const flatten = (routes, parentPath = "/") => {
  497. return routes.reduce((acc, route) => {
  498. const path = getPath(parentPath, route.path);
  499. const children = route.children ? flatten(route.children, path) : [];
  500. return acc.concat([{ ...route, path }].concat(children));
  501. }, []);
  502. };
  503. return flatten(routes);
  504. })();