full-routes.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /**
  2. * 1. 前端维护的完整路由表, 用于创建"菜单"
  3. * 2. component 是 string,并不是 组件对象。
  4. * 3. 生成菜单,关注的 path,name,component,icon。
  5. * 4. 部分路由组件是菜单不可见的,当访问该路由时,左侧菜单的menu item会失去active状态。需要设置 meta.activeMenu 保持选中状态。
  6. */
  7. import { AppRouteRecordRaw } from './types';
  8. import { getTreeItem } from '@/utils';
  9. import { cloneDeep } from 'lodash-es';
  10. const fullRoutes: AppRouteRecordRaw[] = [
  11. /**
  12. * Dashboard
  13. */
  14. {
  15. path: '/dashboard',
  16. name: 'Dashboard',
  17. component: 'LAYOUT',
  18. meta: {
  19. icon: 'DashboardOutlined',
  20. title: 'Dashboard',
  21. },
  22. children: [
  23. {
  24. // 首页(原主控台)
  25. path: 'console',
  26. name: 'DashboardConsole',
  27. component: '/dashboard/home/Home',
  28. meta: {
  29. icon: '',
  30. title: '首页',
  31. },
  32. }
  33. ]
  34. },
  35. /**
  36. * 场景管理
  37. */
  38. {
  39. path: '/scene',
  40. name: 'Scene',
  41. component: 'LAYOUT',
  42. meta: {
  43. icon: 'ApartmentOutlined',
  44. title: '场景管理',
  45. },
  46. children: [
  47. {
  48. // 模板管理
  49. path: 'template',
  50. name: 'SceneTemplate',
  51. component: '/templateManage/templateManage',
  52. meta: {
  53. icon: '',
  54. title: '模板管理',
  55. },
  56. },
  57. {
  58. // 车间管理
  59. path: 'workshop',
  60. name: 'SceneWorkshop',
  61. component: '/system-config/scene-manage/SceneManage',
  62. meta: {
  63. icon: '',
  64. title: '车间管理'
  65. },
  66. },
  67. {
  68. // 业务场景管理
  69. path: 'business',
  70. name: 'SceneBusiness',
  71. component: '/system-config/business-scene/PageBusinessScene',
  72. meta: {
  73. icon: '',
  74. title: '业务创建管理',
  75. },
  76. }
  77. ]
  78. },
  79. /**
  80. * 设备管理
  81. */
  82. {
  83. path: '/device',
  84. name: 'Device',
  85. component: 'LAYOUT',
  86. meta: {
  87. icon: 'CameraOutlined',
  88. title: '设备管理'
  89. },
  90. children: [
  91. {
  92. // 相机设备
  93. path: 'camera',
  94. name: 'DeviceCamera',
  95. component: '/cameras/overview/CamerasOverview',
  96. meta: {
  97. icon: '',
  98. title: '相机设备'
  99. },
  100. },
  101. {
  102. // NVR设备
  103. path: 'nvr',
  104. name: 'DeviceNVR',
  105. component: '/cameras/nvrlist/NvrList',
  106. meta: {
  107. icon: '',
  108. title: 'NVR设备'
  109. },
  110. }
  111. ]
  112. },
  113. /**
  114. * 布局管理
  115. */
  116. {
  117. path: '/layout',
  118. name: 'Layout',
  119. component: 'LAYOUT',
  120. meta: {
  121. icon: 'PictureOutlined',
  122. title: '布局管理',
  123. },
  124. children: [
  125. {
  126. // 公司场景布局入口页,选择PC端还是手机端
  127. path: 'scene',
  128. name: 'LayoutScene',
  129. component: '/page-config/PageScene',
  130. meta: {
  131. icon: '',
  132. title: '场景布局',
  133. },
  134. },
  135. {
  136. // 公司场景布局卡片列表。菜单不可见
  137. path: 'scene-list',
  138. name: 'LayoutSceneList',
  139. component: '/page-config/PageSceneList',
  140. meta: {
  141. icon: '',
  142. title: '场景布局列表',
  143. activeMenu: 'LayoutScene',
  144. }
  145. },
  146. {
  147. // 公司场景配置页面(菜单不可见)
  148. path: 'scene-config',
  149. name: 'LayoutSceneConfig',
  150. component: '/page-config/ConfigEdit',
  151. meta: {
  152. icon: '',
  153. title: '场景布局配置',
  154. activeMenu: 'LayoutScene',
  155. }
  156. },
  157. {
  158. // 相机布局入口页,选择PC端还是手机端
  159. path: 'camera',
  160. name: 'LayoutCamera',
  161. component: '/page-config/PageCamera',
  162. meta: {
  163. icon: '',
  164. title: '相机布局',
  165. }
  166. },
  167. {
  168. // 相机布局卡片列表。 菜单不可见
  169. path: 'camera-list',
  170. name: 'LayoutCameraList',
  171. component: '/page-config/PageCameraList',
  172. meta: {
  173. icon: '',
  174. title: '相机布局列表',
  175. activeMenu: 'LayoutCamera',
  176. }
  177. },
  178. {
  179. // 相机布局配置
  180. path: 'camera-config',
  181. name: 'LayoutCameraConfig',
  182. component: '/map-config/mini-map/MiniMapConfig',
  183. meta: {
  184. icon: '',
  185. title: '相机布局配置',
  186. activeMenu: 'LayoutCamera',
  187. }
  188. }
  189. ]
  190. },
  191. /**
  192. * 算法管理
  193. */
  194. {
  195. path: '/algorithm',
  196. name: 'Algorithm',
  197. component: 'LAYOUT',
  198. meta: {
  199. icon: 'FunctionOutlined',
  200. title: '算法管理',
  201. },
  202. children: [
  203. {
  204. // 算法预览
  205. path: 'preview',
  206. name: 'AlgorithmPreview',
  207. component: '/cameras/algo-management/algoManagement',
  208. meta: {
  209. icon: '',
  210. title: '算法预览',
  211. },
  212. },
  213. {
  214. // 算法配置
  215. path: 'config',
  216. name: 'AlgorithmConfig',
  217. component: '/cameras/preview/CameraPreview',
  218. meta: {
  219. ico: '',
  220. title: '算法配置',
  221. },
  222. }
  223. ]
  224. },
  225. /**
  226. * 用户管理
  227. */
  228. {
  229. path: '/user',
  230. name: 'User',
  231. component: 'LAYOUT',
  232. meta: {
  233. icon: 'UserOutlined',
  234. title: '用户管理',
  235. },
  236. children: [
  237. {
  238. // 账号管理
  239. path: 'account',
  240. name: 'UserAccount',
  241. component: '/system/user/user',
  242. meta: {
  243. icon: '',
  244. title: '账号管理',
  245. }
  246. },
  247. {
  248. // 角色管理
  249. path: 'role',
  250. name: 'UserRole',
  251. component: '/system/role/role',
  252. meta: {
  253. icon: '',
  254. title: '角色管理',
  255. }
  256. },
  257. {
  258. // 组织管理
  259. path: 'department',
  260. name: 'UserDepartment',
  261. component: '/auth/dept/dept',
  262. meta: {
  263. icon: '',
  264. title: '组织管理',
  265. }
  266. },
  267. {
  268. // 岗位管理 (目前不需要)
  269. path: 'post',
  270. name: 'UserPost',
  271. component: '/auth/post/post',
  272. meta: {
  273. icon: '',
  274. title: '岗位管理'
  275. }
  276. }
  277. ]
  278. },
  279. /**
  280. * 消息管理
  281. */
  282. {
  283. path: '/message',
  284. name: 'Message',
  285. component: 'LAYOUT',
  286. meta: {
  287. icon: 'SendOutlined',
  288. title: '消息管理',
  289. },
  290. children: [
  291. {
  292. // 报表推送
  293. path: 'report',
  294. name: 'MessageReport',
  295. component: '/message/reportmessage/ReportMessage',
  296. meta: {
  297. icon: '',
  298. title: '报表推送',
  299. },
  300. },
  301. {
  302. // 报表推送配置(菜单不可见)
  303. path: 'report-config',
  304. name: 'MessageReportConfig',
  305. component: '/message/reportmessage/ReportOperation',
  306. meta: {
  307. icon: '',
  308. title: '报表推送配置',
  309. activeMenu: 'MessageReport',
  310. },
  311. },
  312. {
  313. // 报警推送
  314. path: 'alarm',
  315. name: 'MessageAlarm',
  316. component: '/message/alarmMessages/alarmMessages',
  317. meta: {
  318. icon: '',
  319. title: '报警推送',
  320. },
  321. },
  322. {
  323. // 报警推送配置 (菜单不可见)
  324. path: 'alarm-config',
  325. name: 'MessageAlarmConfig',
  326. component: '/message/alarm-config/AlarmConfig',
  327. meta: {
  328. icon: '',
  329. title: '报警推送配置',
  330. activeMenu: 'MessageAlarm',
  331. },
  332. },
  333. {
  334. // 系统通知
  335. path: 'sys-notification',
  336. name: 'MessageSysNotification',
  337. component: '/message/systemNotifications/systemNotifications',
  338. meta: {
  339. icon: '',
  340. title: '系统通知',
  341. },
  342. },
  343. {
  344. // 系统通知配置(菜单不可见)
  345. path: 'sys-notification-config',
  346. name: 'MessageSysNotificationConfig',
  347. component: '/message/sysnotion-config/SysnotionConfig',
  348. meta: {
  349. icon: '',
  350. title: '系统通知配置',
  351. activeMenu: 'MessageSysNotification',
  352. },
  353. },
  354. {
  355. // 人员分组
  356. path: 'personnel-group',
  357. name: 'MessagePersonnelGroup',
  358. component: '/message/persongroup/UserGroup',
  359. meta: {
  360. icon: '',
  361. title: '人员分组',
  362. },
  363. }
  364. ]
  365. },
  366. /**
  367. * 数据管理
  368. */
  369. {
  370. path: '/data',
  371. name: 'Data',
  372. component: 'LAYOUT',
  373. meta: {
  374. icon: 'LineChartOutlined',
  375. title: '数据管理',
  376. },
  377. children: [
  378. {
  379. // 平台统计
  380. path: 'platform',
  381. name: 'DataPlatform',
  382. component: '/datamanager/platformdata/PlatformData',
  383. meta: {
  384. icon: '',
  385. title: '平台统计'
  386. }
  387. },
  388. {
  389. // 历史视频 (视频回看)
  390. path: 'playback',
  391. name: 'DataPlayback',
  392. component: '/datamanager/playback/Playback',
  393. meta: {
  394. icon: '',
  395. title: '历史视频'
  396. }
  397. },
  398. {
  399. // 违规问题
  400. path: 'violation',
  401. name: 'DataViolation',
  402. component: '/datamanager/alertformdata/AlertformData',
  403. meta: {
  404. icon: '',
  405. title: '违规问题'
  406. }
  407. },
  408. ]
  409. },
  410. /**
  411. * 系统管理 (只有超管可见)
  412. */
  413. {
  414. path: '/system',
  415. name: 'System',
  416. component: 'LAYOUT',
  417. meta: {
  418. icon: 'OptionsSharp',
  419. title: '系统管理',
  420. },
  421. children: [
  422. {
  423. // 租户管理
  424. path: 'tenant',
  425. name: 'SystemTenant',
  426. component: '/system/tenant/tenant',
  427. meta: {
  428. icon: '',
  429. title: '租户管理',
  430. }
  431. },
  432. {
  433. // 菜单管理
  434. path: 'menu',
  435. name: 'SystemMenu',
  436. component: '/system/menu/menu',
  437. meta: {
  438. icon: '',
  439. title: '菜单管理',
  440. }
  441. },
  442. {
  443. // 权限管理
  444. path: 'permission',
  445. name: 'SystemPermission',
  446. component: '/system/permssion/PagePermission',
  447. meta: {
  448. icon: '',
  449. title: '权限管理',
  450. }
  451. },
  452. {
  453. // 意见反馈
  454. path: 'feedback',
  455. name: 'SystemFeedback',
  456. component: '/feedback/feedback',
  457. meta: {
  458. icon: '',
  459. title: '意见反馈',
  460. }
  461. },
  462. {
  463. // 反馈处理
  464. path: 'feedback-handle',
  465. name: 'SystemFeedbackHandle',
  466. component: '/feedback/handleFeedback',
  467. meta: {
  468. icon: '',
  469. title: '反馈处理'
  470. }
  471. },
  472. {
  473. // 字典管理
  474. path: 'dictionary',
  475. name: 'SystemDictionary',
  476. component: '/system/dictionary/dictionary',
  477. meta: {
  478. icon: '',
  479. title: '字典管理',
  480. }
  481. },
  482. {
  483. // 系统管理
  484. path: 'log',
  485. name: 'SystemLog',
  486. component: '/system/log/log',
  487. meta: {
  488. icon: '',
  489. title: '日志管理',
  490. }
  491. },
  492. ]
  493. },
  494. /**
  495. * 异常页面
  496. */
  497. {
  498. path: '/exception',
  499. name: 'Exception',
  500. component: 'LAYOUT',
  501. redirect: '/exception/403',
  502. meta: {
  503. icon: 'ExclamationCircleOutlined',
  504. title: '异常页面',
  505. },
  506. children: [
  507. {
  508. // 403,
  509. path: '403',
  510. name: 'Exception403',
  511. component: '/exception/403',
  512. meta: {
  513. icon: '',
  514. title: '403',
  515. },
  516. },
  517. {
  518. path: '404',
  519. name: '/exception/404',
  520. component: '/exception/404',
  521. meta: {
  522. icon: '',
  523. title: '404',
  524. },
  525. },
  526. {
  527. path: '500',
  528. name: 'Exception500',
  529. component: '/exception/500',
  530. meta: {
  531. icon: '',
  532. title: '500',
  533. },
  534. },
  535. ]
  536. },
  537. ] as const;
  538. /**
  539. * 类型定义。避免与已有的定义冲突,避免与 vue-router的类型定义冲突,前面加 _ 前缀
  540. */
  541. export interface _RouteViewItem {
  542. label: string;
  543. value: string;
  544. }
  545. export type _RouteView = _RouteViewItem & { children?: _RouteViewItem[] | null };
  546. export type _RouteViewTree = _RouteView[];
  547. /**
  548. * 获取指定 父路由 下的子路由。
  549. * 若 父级路由 未指定,则返回一级路由
  550. */
  551. export function getChildRoutesView(parentRouteName?: string | null ): _RouteViewItem[] {
  552. // 未指定 parentRouteName, 则返回 level1 的路由
  553. if (parentRouteName == null) {
  554. return fullRoutes.map(route => ({
  555. label: route.meta.title as string,
  556. value: route.name,
  557. }));
  558. }
  559. // 获取指定父路由的子路由
  560. const parentRoute: AppRouteRecordRaw = cloneDeep(getTreeItem(fullRoutes, parentRouteName, 'name'));
  561. if (parentRoute.children && parentRoute.children.length > 0) {
  562. return parentRoute.children.map(route => ({
  563. label: route.meta.title as string,
  564. value: route.name,
  565. }));
  566. } else {
  567. return [];
  568. }
  569. }
  570. /**
  571. * 获取指定的 路由信息
  572. */
  573. export function getRouteByName(routeName: string) {
  574. return cloneDeep(getTreeItem(fullRoutes, routeName, 'name')) as AppRouteRecordRaw;
  575. }
  576. /**
  577. * 转换成 el-tree-select 的数据结构形式
  578. */
  579. export function transformToRouteViewTree(routes?: AppRouteRecordRaw[] | null) {
  580. const tree: _RouteViewTree = [];
  581. if (routes == null) return tree;
  582. for(const route of routes) {
  583. const treeItem: _RouteView = {
  584. value: route.name,
  585. label: route.meta.title as string,
  586. children: null
  587. }
  588. if (route.children && route.children.length > 0) {
  589. treeItem.children = transformToRouteViewTree(route.children);
  590. tree.push(treeItem);
  591. } else {
  592. tree.push(treeItem);
  593. }
  594. }
  595. return tree;
  596. }
  597. export const routeViewTree = transformToRouteViewTree(fullRoutes);