index.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. import { createRouter, createWebHashHistory } from 'vue-router'
  2. import type { RouteRecordRaw } from 'vue-router'
  3. import type { App } from 'vue'
  4. import { Layout, getParentLayout } from '@/utils/routerHelper'
  5. import { useI18n } from '@/hooks/web/useI18n'
  6. const { t } = useI18n()
  7. export const constantRouterMap: AppRouteRecordRaw[] = [
  8. {
  9. path: '/',
  10. component: Layout,
  11. redirect: '/dashboard/analysis',
  12. name: 'Root',
  13. meta: {
  14. hidden: true
  15. }
  16. },
  17. {
  18. path: '/redirect',
  19. component: Layout,
  20. name: 'Redirect',
  21. children: [
  22. {
  23. path: '/redirect/:path(.*)',
  24. name: 'Redirect',
  25. component: () => import('@/views/Redirect/Redirect.vue'),
  26. meta: {}
  27. }
  28. ],
  29. meta: {
  30. hidden: true,
  31. noTagsView: true
  32. }
  33. },
  34. {
  35. path: '/login',
  36. component: () => import('@/views/Login/Login.vue'),
  37. name: 'Login',
  38. meta: {
  39. hidden: true,
  40. title: t('router.login'),
  41. noTagsView: true
  42. }
  43. },
  44. {
  45. path: '/404',
  46. component: () => import('@/views/Error/404.vue'),
  47. name: 'NoFind',
  48. meta: {
  49. hidden: true,
  50. title: '404',
  51. noTagsView: true
  52. }
  53. }
  54. ]
  55. export const asyncRouterMap: AppRouteRecordRaw[] = [
  56. {
  57. path: '/dashboard',
  58. component: Layout,
  59. redirect: '/dashboard/analysis',
  60. name: 'Dashboard',
  61. meta: {
  62. title: t('router.dashboard'),
  63. icon: 'ant-design:dashboard-filled',
  64. alwaysShow: true
  65. },
  66. children: [
  67. {
  68. path: 'analysis',
  69. component: () => import('@/views/Dashboard/Analysis.vue'),
  70. name: 'Analysis',
  71. meta: {
  72. title: t('router.analysis'),
  73. noCache: true,
  74. affix: true
  75. }
  76. },
  77. {
  78. path: 'workplace',
  79. component: () => import('@/views/Dashboard/Workplace.vue'),
  80. name: 'Workplace',
  81. meta: {
  82. title: t('router.workplace'),
  83. noCache: true
  84. }
  85. }
  86. ]
  87. },
  88. {
  89. path: '/external-link',
  90. component: Layout,
  91. meta: {},
  92. name: 'ExternalLink',
  93. children: [
  94. {
  95. path: 'https://element-plus-admin-doc.cn/',
  96. name: 'DocumentLink',
  97. meta: {
  98. title: t('router.document'),
  99. icon: 'clarity:document-solid'
  100. }
  101. }
  102. ]
  103. },
  104. {
  105. path: '/guide',
  106. component: Layout,
  107. name: 'Guide',
  108. meta: {},
  109. children: [
  110. {
  111. path: 'index',
  112. component: () => import('@/views/Guide/Guide.vue'),
  113. name: 'GuideDemo',
  114. meta: {
  115. title: t('router.guide'),
  116. icon: 'cib:telegram-plane'
  117. }
  118. }
  119. ]
  120. },
  121. {
  122. path: '/components',
  123. component: Layout,
  124. name: 'ComponentsDemo',
  125. meta: {
  126. title: t('router.component'),
  127. icon: 'bx:bxs-component',
  128. alwaysShow: true
  129. },
  130. children: [
  131. {
  132. path: 'form',
  133. component: getParentLayout(),
  134. redirect: '/components/form/default-form',
  135. name: 'Form',
  136. meta: {
  137. title: t('router.form'),
  138. alwaysShow: true
  139. },
  140. children: [
  141. {
  142. path: 'default-form',
  143. component: () => import('@/views/Components/Form/DefaultForm.vue'),
  144. name: 'DefaultForm',
  145. meta: {
  146. title: t('router.defaultForm')
  147. }
  148. },
  149. {
  150. path: 'use-form',
  151. component: () => import('@/views/Components/Form/UseFormDemo.vue'),
  152. name: 'UseForm',
  153. meta: {
  154. title: 'UseForm'
  155. }
  156. }
  157. ]
  158. },
  159. {
  160. path: 'table',
  161. component: getParentLayout(),
  162. redirect: '/components/table/default-table',
  163. name: 'TableDemo',
  164. meta: {
  165. title: t('router.table'),
  166. alwaysShow: true
  167. },
  168. children: [
  169. {
  170. path: 'default-table',
  171. component: () => import('@/views/Components/Table/DefaultTable.vue'),
  172. name: 'DefaultTable',
  173. meta: {
  174. title: t('router.defaultTable')
  175. }
  176. },
  177. {
  178. path: 'use-table',
  179. component: () => import('@/views/Components/Table/UseTableDemo.vue'),
  180. name: 'UseTable',
  181. meta: {
  182. title: 'UseTable'
  183. }
  184. },
  185. {
  186. path: 'tree-table',
  187. component: () => import('@/views/Components/Table/TreeTable.vue'),
  188. name: 'TreeTable',
  189. meta: {
  190. title: t('router.treeTable')
  191. }
  192. },
  193. {
  194. path: 'table-image-preview',
  195. component: () => import('@/views/Components/Table/TableImagePreview.vue'),
  196. name: 'TableImagePreview',
  197. meta: {
  198. title: t('router.PicturePreview')
  199. }
  200. }
  201. ]
  202. },
  203. {
  204. path: 'editor-demo',
  205. component: getParentLayout(),
  206. redirect: '/components/editor-demo/editor',
  207. name: 'EditorDemo',
  208. meta: {
  209. title: t('router.editor'),
  210. alwaysShow: true
  211. },
  212. children: [
  213. {
  214. path: 'editor',
  215. component: () => import('@/views/Components/Editor/Editor.vue'),
  216. name: 'Editor',
  217. meta: {
  218. title: t('router.richText')
  219. }
  220. }
  221. ]
  222. },
  223. {
  224. path: 'search',
  225. component: () => import('@/views/Components/Search.vue'),
  226. name: 'Search',
  227. meta: {
  228. title: t('router.search')
  229. }
  230. },
  231. {
  232. path: 'descriptions',
  233. component: () => import('@/views/Components/Descriptions.vue'),
  234. name: 'Descriptions',
  235. meta: {
  236. title: t('router.descriptions')
  237. }
  238. },
  239. {
  240. path: 'image-viewer',
  241. component: () => import('@/views/Components/ImageViewer.vue'),
  242. name: 'ImageViewer',
  243. meta: {
  244. title: t('router.imageViewer')
  245. }
  246. },
  247. {
  248. path: 'dialog',
  249. component: () => import('@/views/Components/Dialog.vue'),
  250. name: 'Dialog',
  251. meta: {
  252. title: t('router.dialog')
  253. }
  254. },
  255. {
  256. path: 'icon',
  257. component: () => import('@/views/Components/Icon.vue'),
  258. name: 'Icon',
  259. meta: {
  260. title: t('router.icon')
  261. }
  262. },
  263. {
  264. path: 'echart',
  265. component: () => import('@/views/Components/Echart.vue'),
  266. name: 'Echart',
  267. meta: {
  268. title: t('router.echart')
  269. }
  270. },
  271. {
  272. path: 'count-to',
  273. component: () => import('@/views/Components/CountTo.vue'),
  274. name: 'CountTo',
  275. meta: {
  276. title: t('router.countTo')
  277. }
  278. },
  279. {
  280. path: 'qrcode',
  281. component: () => import('@/views/Components/Qrcode.vue'),
  282. name: 'Qrcode',
  283. meta: {
  284. title: t('router.qrcode')
  285. }
  286. },
  287. {
  288. path: 'highlight',
  289. component: () => import('@/views/Components/Highlight.vue'),
  290. name: 'Highlight',
  291. meta: {
  292. title: t('router.highlight')
  293. }
  294. },
  295. {
  296. path: 'infotip',
  297. component: () => import('@/views/Components/Infotip.vue'),
  298. name: 'Infotip',
  299. meta: {
  300. title: t('router.infotip')
  301. }
  302. },
  303. {
  304. path: 'input-password',
  305. component: () => import('@/views/Components/InputPassword.vue'),
  306. name: 'InputPassword',
  307. meta: {
  308. title: t('router.inputPassword')
  309. }
  310. }
  311. ]
  312. },
  313. {
  314. path: '/function',
  315. component: Layout,
  316. redirect: '/function/multipleTabs',
  317. name: 'Function',
  318. meta: {
  319. title: t('router.function'),
  320. icon: 'ri:function-fill',
  321. alwaysShow: true
  322. },
  323. children: [
  324. {
  325. path: 'multiple-tabs',
  326. component: () => import('@/views/Function/MultipleTabs.vue'),
  327. name: 'MultipleTabs',
  328. meta: {
  329. title: t('router.multipleTabs')
  330. }
  331. },
  332. {
  333. path: 'multiple-tabs-demo/:id',
  334. component: () => import('@/views/Function/MultipleTabsDemo.vue'),
  335. name: 'MultipleTabsDemo',
  336. meta: {
  337. hidden: true,
  338. title: t('router.details'),
  339. canTo: true,
  340. activeMenu: '/function/multiple-tabs'
  341. }
  342. }
  343. ]
  344. },
  345. {
  346. path: '/hooks',
  347. component: Layout,
  348. redirect: '/hooks/useWatermark',
  349. name: 'Hooks',
  350. meta: {
  351. title: 'hooks',
  352. icon: 'ic:outline-webhook',
  353. alwaysShow: true
  354. },
  355. children: [
  356. {
  357. path: 'useWatermark',
  358. component: () => import('@/views/hooks/useWatermark.vue'),
  359. name: 'UseWatermark',
  360. meta: {
  361. title: 'useWatermark'
  362. }
  363. },
  364. {
  365. path: 'useTagsView',
  366. component: () => import('@/views/hooks/useTagsView.vue'),
  367. name: 'UseTagsView',
  368. meta: {
  369. title: 'useTagsView'
  370. }
  371. }
  372. // {
  373. // path: 'useCrudSchemas',
  374. // component: () => import('@/views/hooks/useCrudSchemas.vue'),
  375. // name: 'UseCrudSchemas',
  376. // meta: {
  377. // title: 'useCrudSchemas'
  378. // }
  379. // }
  380. ]
  381. },
  382. {
  383. path: '/level',
  384. component: Layout,
  385. redirect: '/level/menu1/menu1-1/menu1-1-1',
  386. name: 'Level',
  387. meta: {
  388. title: t('router.level'),
  389. icon: 'carbon:skill-level-advanced'
  390. },
  391. children: [
  392. {
  393. path: 'menu1',
  394. name: 'Menu1',
  395. component: getParentLayout(),
  396. redirect: '/level/menu1/menu1-1/menu1-1-1',
  397. meta: {
  398. title: t('router.menu1')
  399. },
  400. children: [
  401. {
  402. path: 'menu1-1',
  403. name: 'Menu11',
  404. component: getParentLayout(),
  405. redirect: '/level/menu1/menu1-1/menu1-1-1',
  406. meta: {
  407. title: t('router.menu11'),
  408. alwaysShow: true
  409. },
  410. children: [
  411. {
  412. path: 'menu1-1-1',
  413. name: 'Menu111',
  414. component: () => import('@/views/Level/Menu111.vue'),
  415. meta: {
  416. title: t('router.menu111')
  417. }
  418. }
  419. ]
  420. },
  421. {
  422. path: 'menu1-2',
  423. name: 'Menu12',
  424. component: () => import('@/views/Level/Menu12.vue'),
  425. meta: {
  426. title: t('router.menu12')
  427. }
  428. }
  429. ]
  430. },
  431. {
  432. path: 'menu2',
  433. name: 'Menu2',
  434. component: () => import('@/views/Level/Menu2.vue'),
  435. meta: {
  436. title: t('router.menu2')
  437. }
  438. }
  439. ]
  440. },
  441. {
  442. path: '/example',
  443. component: Layout,
  444. redirect: '/example/example-dialog',
  445. name: 'Example',
  446. meta: {
  447. title: t('router.example'),
  448. icon: 'ep:management',
  449. alwaysShow: true
  450. },
  451. children: [
  452. {
  453. path: 'example-dialog',
  454. component: () => import('@/views/Example/Dialog/ExampleDialog.vue'),
  455. name: 'ExampleDialog',
  456. meta: {
  457. title: t('router.exampleDialog')
  458. }
  459. },
  460. {
  461. path: 'example-page',
  462. component: () => import('@/views/Example/Page/ExamplePage.vue'),
  463. name: 'ExamplePage',
  464. meta: {
  465. title: t('router.examplePage')
  466. }
  467. },
  468. {
  469. path: 'example-add',
  470. component: () => import('@/views/Example/Page/ExampleAdd.vue'),
  471. name: 'ExampleAdd',
  472. meta: {
  473. title: t('router.exampleAdd'),
  474. noTagsView: true,
  475. noCache: true,
  476. hidden: true,
  477. canTo: true,
  478. activeMenu: '/example/example-page'
  479. }
  480. },
  481. {
  482. path: 'example-edit',
  483. component: () => import('@/views/Example/Page/ExampleEdit.vue'),
  484. name: 'ExampleEdit',
  485. meta: {
  486. title: t('router.exampleEdit'),
  487. noTagsView: true,
  488. noCache: true,
  489. hidden: true,
  490. canTo: true,
  491. activeMenu: '/example/example-page'
  492. }
  493. },
  494. {
  495. path: 'example-detail',
  496. component: () => import('@/views/Example/Page/ExampleDetail.vue'),
  497. name: 'ExampleDetail',
  498. meta: {
  499. title: t('router.exampleDetail'),
  500. noTagsView: true,
  501. noCache: true,
  502. hidden: true,
  503. canTo: true,
  504. activeMenu: '/example/example-page'
  505. }
  506. }
  507. ]
  508. },
  509. {
  510. path: '/error',
  511. component: Layout,
  512. redirect: '/error/404',
  513. name: 'Error',
  514. meta: {
  515. title: t('router.errorPage'),
  516. icon: 'ci:error',
  517. alwaysShow: true
  518. },
  519. children: [
  520. {
  521. path: '404-demo',
  522. component: () => import('@/views/Error/404.vue'),
  523. name: '404Demo',
  524. meta: {
  525. title: '404'
  526. }
  527. },
  528. {
  529. path: '403-demo',
  530. component: () => import('@/views/Error/403.vue'),
  531. name: '403Demo',
  532. meta: {
  533. title: '403'
  534. }
  535. },
  536. {
  537. path: '500-demo',
  538. component: () => import('@/views/Error/500.vue'),
  539. name: '500Demo',
  540. meta: {
  541. title: '500'
  542. }
  543. }
  544. ]
  545. },
  546. {
  547. path: '/authorization',
  548. component: Layout,
  549. redirect: '/authorization/user',
  550. name: 'Authorization',
  551. meta: {
  552. title: t('router.authorization'),
  553. icon: 'eos-icons:role-binding',
  554. alwaysShow: true
  555. },
  556. children: [
  557. {
  558. path: 'department',
  559. component: () => import('@/views/Authorization/Department/Department.vue'),
  560. name: 'Department',
  561. meta: {
  562. title: t('router.department')
  563. }
  564. },
  565. {
  566. path: 'user',
  567. component: () => import('@/views/Authorization/User/User.vue'),
  568. name: 'User',
  569. meta: {
  570. title: t('router.user')
  571. }
  572. },
  573. {
  574. path: 'menu',
  575. component: () => import('@/views/Authorization/Menu/Menu.vue'),
  576. name: 'Menu',
  577. meta: {
  578. title: t('router.menuManagement')
  579. }
  580. },
  581. {
  582. path: 'role',
  583. component: () => import('@/views/Authorization/Role/Role.vue'),
  584. name: 'Role',
  585. meta: {
  586. title: t('router.role')
  587. }
  588. },
  589. {
  590. path: 'test',
  591. component: () => import('@/views/Authorization/Test/Test.vue'),
  592. name: 'Test',
  593. meta: {
  594. title: t('router.permission'),
  595. permission: ['add', 'edit', 'delete']
  596. }
  597. }
  598. ]
  599. }
  600. ]
  601. const router = createRouter({
  602. history: createWebHashHistory(),
  603. strict: true,
  604. routes: constantRouterMap as RouteRecordRaw[],
  605. scrollBehavior: () => ({ left: 0, top: 0 })
  606. })
  607. export const resetRouter = (): void => {
  608. const resetWhiteNameList = ['Redirect', 'Login', 'NoFind', 'Root']
  609. router.getRoutes().forEach((route) => {
  610. const { name } = route
  611. if (name && !resetWhiteNameList.includes(name as string)) {
  612. router.hasRoute(name) && router.removeRoute(name)
  613. }
  614. })
  615. }
  616. export const setupRouter = (app: App<Element>) => {
  617. app.use(router)
  618. }
  619. export default router