index.ts 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. import { createRouter, createWebHashHistory } from 'vue-router'
  2. import type { RouteRecordRaw } from 'vue-router'
  3. import { AppRouteRecordRaw } from './types'
  4. import type { App } from 'vue'
  5. import { getParentLayout } from './utils'
  6. /* Layout */
  7. const Layout = () => import('../layout/index.vue')
  8. /**
  9. * redirect: noredirect 当设置 noredirect 的时候该路由在面包屑导航中不可被点击
  10. * name:'router-name' 设定路由的名字,一定要填写不然使用<keep-alive>时会出现各种问题
  11. * meta : {
  12. hidden: true 当设置 true 的时候该路由不会再侧边栏出现 如404,login等页面(默认 false)
  13. alwaysShow: true 当你一个路由下面的 children 声明的路由大于1个时,自动会变成嵌套的模式,
  14. 只有一个时,会将那个子路由当做根路由显示在侧边栏,
  15. 若你想不管路由下面的 children 声明的个数都显示你的根路由,
  16. 你可以设置 alwaysShow: true,这样它就会忽略之前定义的规则,
  17. 一直显示根路由(默认 false)
  18. title: 'title' 设置该路由在侧边栏和面包屑中展示的名字
  19. icon: 'svg-name' 设置该路由的图标
  20. noCache: true 如果设置为true,则不会被 <keep-alive> 缓存(默认 false)
  21. breadcrumb: false 如果设置为false,则不会在breadcrumb面包屑中显示(默认 true)
  22. affix: true 如果设置为true,则会一直固定在tag项中(默认 false)
  23. noTagsView: true 如果设置为true,则不会出现在tag中(默认 false)
  24. activeMenu: '/dashboard' 显示高亮的路由路径
  25. followAuth: '/dashboard' 跟随哪个路由进行权限过滤
  26. showMainRoute: true 设置为true即使hidden为true,也依然可以进行路由跳转(默认 false)
  27. followRoute: '/dashboard' 为路由设置跟随其他路由的权限
  28. }
  29. **/
  30. export const constantRouterMap: AppRouteRecordRaw[] = [
  31. {
  32. path: '/redirect',
  33. component: Layout,
  34. children: [
  35. {
  36. path: '/redirect/:path*',
  37. component: () => import('_c/Redirect/index.vue'),
  38. meta: {}
  39. }
  40. ],
  41. meta: {
  42. hidden: true
  43. }
  44. },
  45. {
  46. path: '/404',
  47. component: () => import('_c/Error/404.vue'),
  48. name: 'NoFind',
  49. meta: {
  50. hidden: true,
  51. title: '404',
  52. noTagsView: true
  53. }
  54. },
  55. {
  56. path: '/login',
  57. component: () => import('_v/login/index.vue'),
  58. name: 'Login',
  59. meta: {
  60. hidden: true,
  61. title: '登录',
  62. noTagsView: true
  63. }
  64. },
  65. {
  66. path: '/',
  67. component: Layout,
  68. redirect: '/dashboard',
  69. name: 'Root',
  70. meta: {},
  71. children: [
  72. {
  73. path: 'dashboard',
  74. component: () => import('_v/dashboard/index.vue'),
  75. name: 'Dashboard',
  76. meta: {
  77. title: '首页',
  78. icon: 'dashboard',
  79. noCache: true,
  80. affix: true
  81. }
  82. }
  83. ]
  84. },
  85. {
  86. path: '/external-link',
  87. component: Layout,
  88. meta: {},
  89. children: [
  90. {
  91. path: 'http://8.133.179.48:4000/dist-doc/',
  92. meta: { title: '文档', icon: 'documentation' }
  93. }
  94. ]
  95. },
  96. {
  97. path: '/guide',
  98. component: Layout,
  99. name: 'Guide',
  100. meta: {},
  101. children: [
  102. {
  103. path: 'index',
  104. component: () => import('_v/guide/index.vue'),
  105. name: 'GuideDemo',
  106. meta: {
  107. title: '引导页',
  108. icon: 'guide'
  109. }
  110. }
  111. ]
  112. }
  113. ]
  114. export const asyncRouterMap: AppRouteRecordRaw[] = [
  115. {
  116. path: '/components-demo',
  117. component: Layout,
  118. redirect: '/components-demo/echarts',
  119. name: 'ComponentsDemo',
  120. meta: {
  121. title: '功能组件',
  122. icon: 'component',
  123. alwaysShow: true
  124. },
  125. children: [
  126. {
  127. path: 'echarts',
  128. component: () => import('_v/components-demo/echarts/index.vue'),
  129. name: 'EchartsDemo',
  130. meta: {
  131. title: '图表'
  132. }
  133. },
  134. {
  135. path: 'preview',
  136. component: () => import('_v/components-demo/preview/index.vue'),
  137. name: 'PreviewDemo',
  138. meta: {
  139. title: '图片预览'
  140. }
  141. },
  142. {
  143. path: 'button',
  144. component: () => import('_v/components-demo/button/index.vue'),
  145. name: 'ButtonDemo',
  146. meta: {
  147. title: '按钮'
  148. }
  149. },
  150. {
  151. path: 'message',
  152. component: () => import('_v/components-demo/message/index.vue'),
  153. name: 'MessageDemo',
  154. meta: {
  155. title: '消息提示'
  156. }
  157. },
  158. {
  159. path: 'count-to',
  160. component: () => import('_v/components-demo/count-to/index.vue'),
  161. name: 'CountToDemo',
  162. meta: {
  163. title: '数字动画'
  164. }
  165. },
  166. {
  167. path: 'search',
  168. component: () => import('_v/components-demo/search/index.vue'),
  169. name: 'SearchDemo',
  170. meta: {
  171. title: '查询'
  172. }
  173. },
  174. {
  175. path: 'editor',
  176. component: () => import('_v/components-demo/editor/index.vue'),
  177. name: 'EditorDemo',
  178. meta: {
  179. title: '富文本编辑器'
  180. }
  181. },
  182. {
  183. path: 'markdown',
  184. component: () => import('_v/components-demo/markdown/index.vue'),
  185. name: 'MarkdownDemo',
  186. meta: {
  187. title: 'markdown编辑器'
  188. }
  189. },
  190. {
  191. path: 'dialog',
  192. component: () => import('_v/components-demo/dialog/index.vue'),
  193. name: 'DialogDemo',
  194. meta: {
  195. title: '弹窗'
  196. }
  197. },
  198. {
  199. path: 'more',
  200. component: () => import('_v/components-demo/more/index.vue'),
  201. name: 'MoreDemo',
  202. meta: {
  203. title: '显示更多'
  204. }
  205. },
  206. {
  207. path: 'detail',
  208. component: () => import('_v/components-demo/detail/index.vue'),
  209. name: 'DetailDemo',
  210. meta: {
  211. title: '详情组件'
  212. }
  213. },
  214. {
  215. path: 'qrcode',
  216. component: () => import('_v/components-demo/qrcode/index.vue'),
  217. name: 'QrcodeDemo',
  218. meta: {
  219. title: '二维码组件'
  220. }
  221. },
  222. {
  223. path: 'avatars',
  224. component: () => import('_v/components-demo/avatars/index.vue'),
  225. name: 'AvatarsDemo',
  226. meta: {
  227. title: '头像组'
  228. }
  229. },
  230. {
  231. path: 'highlight',
  232. component: () => import('_v/components-demo/highlight/index.vue'),
  233. name: 'HighlightDemo',
  234. meta: {
  235. title: '文字高亮'
  236. }
  237. }
  238. ]
  239. },
  240. {
  241. path: '/table-demo',
  242. component: Layout,
  243. redirect: '/table-demo/basic-table',
  244. name: 'TableDemo',
  245. meta: {
  246. title: '表格',
  247. icon: 'table',
  248. alwaysShow: true
  249. },
  250. children: [
  251. {
  252. path: 'basic-table',
  253. component: () => import('_v/table-demo/basic-table/index.vue'),
  254. name: 'BasicTable',
  255. meta: {
  256. title: '基础表格'
  257. }
  258. },
  259. {
  260. path: 'page-table',
  261. component: () => import('_v/table-demo/page-table/index.vue'),
  262. name: 'PageTable',
  263. meta: {
  264. title: '分页表格'
  265. }
  266. },
  267. {
  268. path: 'stripe-table',
  269. component: () => import('_v/table-demo/stripe-table/index.vue'),
  270. name: 'StripeTable',
  271. meta: {
  272. title: '带斑马纹表格'
  273. }
  274. },
  275. {
  276. path: 'border-table',
  277. component: () => import('_v/table-demo/border-table/index.vue'),
  278. name: 'BorderTable',
  279. meta: {
  280. title: '带边框表格'
  281. }
  282. },
  283. {
  284. path: 'state-table',
  285. component: () => import('_v/table-demo/state-table/index.vue'),
  286. name: 'StateTable',
  287. meta: {
  288. title: '带状态表格'
  289. }
  290. },
  291. {
  292. path: 'fixed-header',
  293. component: () => import('_v/table-demo/fixed-header/index.vue'),
  294. name: 'FixedHeader',
  295. meta: {
  296. title: '固定表头'
  297. }
  298. },
  299. {
  300. path: 'fixed-column',
  301. component: () => import('_v/table-demo/fixed-column/index.vue'),
  302. name: 'FixedColumn',
  303. meta: {
  304. title: '固定列'
  305. }
  306. },
  307. {
  308. path: 'fixed-column-header',
  309. component: () => import('_v/table-demo/fixed-column-header/index.vue'),
  310. name: 'FixedColumnHeader',
  311. meta: {
  312. title: '固定列和表头'
  313. }
  314. },
  315. {
  316. path: 'fluid-height',
  317. component: () => import('_v/table-demo/fluid-height/index.vue'),
  318. name: 'FluidHeight',
  319. meta: {
  320. title: '流体高度'
  321. }
  322. },
  323. {
  324. path: 'multi-header',
  325. component: () => import('_v/table-demo/multi-header/index.vue'),
  326. name: 'MultiHeader',
  327. meta: {
  328. title: '多级表头'
  329. }
  330. },
  331. {
  332. path: 'single-choice',
  333. component: () => import('_v/table-demo/single-choice/index.vue'),
  334. name: 'SingleChoice',
  335. meta: {
  336. title: '单选'
  337. }
  338. },
  339. {
  340. path: 'multiple-choice',
  341. component: () => import('_v/table-demo/multiple-choice/index.vue'),
  342. name: 'MultipleChoice',
  343. meta: {
  344. title: '多选'
  345. }
  346. },
  347. {
  348. path: 'sort-table',
  349. component: () => import('_v/table-demo/sort-table/index.vue'),
  350. name: 'SortTable',
  351. meta: {
  352. title: '排序'
  353. }
  354. },
  355. {
  356. path: 'screen-table',
  357. component: () => import('_v/table-demo/screen-table/index.vue'),
  358. name: 'ScreenTable',
  359. meta: {
  360. title: '筛选'
  361. }
  362. },
  363. {
  364. path: 'expand-row',
  365. component: () => import('_v/table-demo/expand-row/index.vue'),
  366. name: 'ExpandRow',
  367. meta: {
  368. title: '展开行'
  369. }
  370. },
  371. {
  372. path: 'tree-and-load',
  373. component: () => import('_v/table-demo/tree-and-load/index.vue'),
  374. name: 'TreeAndLoad',
  375. meta: {
  376. title: '树形数据与懒加载'
  377. }
  378. },
  379. {
  380. path: 'custom-header',
  381. component: () => import('_v/table-demo/custom-header/index.vue'),
  382. name: 'CustomHeader',
  383. meta: {
  384. title: '自定义表头'
  385. }
  386. },
  387. {
  388. path: 'total-table',
  389. component: () => import('_v/table-demo/total-table/index.vue'),
  390. name: 'TotalTable',
  391. meta: {
  392. title: '表尾合计行'
  393. }
  394. },
  395. {
  396. path: 'merge-table',
  397. component: () => import('_v/table-demo/merge-table/index.vue'),
  398. name: 'MergeTable',
  399. meta: {
  400. title: '合并行或列'
  401. }
  402. },
  403. {
  404. path: 'custom-index',
  405. component: () => import('_v/table-demo/custom-index/index.vue'),
  406. name: 'CustomIndex',
  407. meta: {
  408. title: '自定义索引'
  409. }
  410. }
  411. ]
  412. },
  413. {
  414. path: '/directives-demo',
  415. component: Layout,
  416. redirect: '/directives-demo/clipboard',
  417. name: 'DirectivesDemo',
  418. meta: {
  419. title: '自定义指令',
  420. icon: 'clipboard',
  421. alwaysShow: true
  422. },
  423. children: [
  424. {
  425. path: 'clipboard',
  426. component: () => import('_v/directives-demo/clipboard/index.vue'),
  427. name: 'ClipboardDemo',
  428. meta: {
  429. title: 'Clipboard'
  430. }
  431. }
  432. ]
  433. },
  434. {
  435. path: '/hooks-demo',
  436. component: Layout,
  437. redirect: '/hooks-demo/watermark',
  438. name: 'HooksDemo',
  439. meta: {
  440. title: 'Hooks',
  441. icon: 'international',
  442. alwaysShow: true
  443. },
  444. children: [
  445. {
  446. path: 'watermark',
  447. component: () => import('_v/hooks-demo/useWatermark/index.vue'),
  448. name: 'UseWatermarkDemo',
  449. meta: {
  450. title: 'UseWaterMark'
  451. }
  452. },
  453. {
  454. path: 'useScrollTo',
  455. component: () => import('_v/hooks-demo/useScrollTo/index.vue'),
  456. name: 'UseScrollToDemo',
  457. meta: {
  458. title: 'UseScrollTo'
  459. }
  460. }
  461. ]
  462. },
  463. {
  464. path: '/icon',
  465. component: Layout,
  466. name: 'IconsDemo',
  467. meta: {},
  468. children: [
  469. {
  470. path: 'index',
  471. component: () => import('_v/icons/index.vue'),
  472. name: 'Icons',
  473. meta: {
  474. title: '图标',
  475. icon: 'icon'
  476. }
  477. }
  478. ]
  479. },
  480. {
  481. path: '/level',
  482. component: Layout,
  483. redirect: '/level/menu1/menu1-1/menu1-1-1',
  484. name: 'Level',
  485. meta: {
  486. title: '多级菜单缓存',
  487. icon: 'nested'
  488. },
  489. children: [
  490. {
  491. path: 'menu1',
  492. name: 'Menu1Demo',
  493. component: getParentLayout('Menu1Demo'),
  494. redirect: '/level/menu1/menu1-1/menu1-1-1',
  495. meta: {
  496. title: 'Menu1'
  497. },
  498. children: [
  499. {
  500. path: 'menu1-1',
  501. name: 'Menu11Demo',
  502. component: getParentLayout('Menu11Demo'),
  503. redirect: '/level/menu1/menu1-1/menu1-1-1',
  504. meta: {
  505. title: 'Menu1-1',
  506. alwaysShow: true
  507. },
  508. children: [
  509. {
  510. path: 'menu1-1-1',
  511. name: 'Menu111Demo',
  512. component: () => import('_v/level/Menu111.vue'),
  513. meta: {
  514. title: 'Menu1-1-1'
  515. }
  516. }
  517. ]
  518. },
  519. {
  520. path: 'menu1-2',
  521. name: 'Menu12Demo',
  522. component: () => import('_v/level/Menu12.vue'),
  523. meta: {
  524. title: 'Menu1-2'
  525. }
  526. }
  527. ]
  528. },
  529. {
  530. path: 'menu2',
  531. name: 'Menu2Demo',
  532. component: () => import('_v/level/Menu2.vue'),
  533. meta: {
  534. title: 'Menu2'
  535. }
  536. }
  537. ]
  538. },
  539. {
  540. path: '/example-demo',
  541. component: Layout,
  542. name: 'ExampleDemo',
  543. redirect: '/example-demo/example-dialog',
  544. meta: {
  545. alwaysShow: true,
  546. icon: 'example',
  547. title: '综合实例'
  548. },
  549. children: [
  550. {
  551. path: 'example-dialog',
  552. component: () => import('_v/example-demo/example-dialog/index.vue'),
  553. name: 'ExampleDialog',
  554. meta: {
  555. title: '列表综合实例-弹窗'
  556. }
  557. },
  558. {
  559. path: 'example-page',
  560. component: () => import('_v/example-demo/example-page/index.vue'),
  561. name: 'ExamplePage',
  562. meta: {
  563. title: '列表综合实例-页面'
  564. }
  565. },
  566. {
  567. path: 'example-add',
  568. component: () => import('_v/example-demo/example-page/example-add.vue'),
  569. name: 'ExampleAdd',
  570. meta: {
  571. title: '列表综合实例-新增',
  572. noTagsView: true,
  573. noCache: true,
  574. hidden: true,
  575. showMainRoute: true,
  576. activeMenu: '/example-demo/example-page'
  577. }
  578. },
  579. {
  580. path: 'example-edit',
  581. component: () => import('_v/example-demo/example-page/example-edit.vue'),
  582. name: 'ExampleEdit',
  583. meta: {
  584. title: '列表综合实例-编辑',
  585. noTagsView: true,
  586. noCache: true,
  587. hidden: true,
  588. showMainRoute: true,
  589. activeMenu: '/example-demo/example-page'
  590. }
  591. },
  592. {
  593. path: 'example-detail',
  594. component: () => import('_v/example-demo/example-page/example-detail.vue'),
  595. name: 'ExampleDetail',
  596. meta: {
  597. title: '列表综合实例-详情',
  598. noTagsView: true,
  599. noCache: true,
  600. hidden: true,
  601. showMainRoute: true,
  602. activeMenu: '/example-demo/example-page'
  603. }
  604. }
  605. ]
  606. },
  607. {
  608. path: '/role-demo',
  609. component: Layout,
  610. redirect: '/role-demo/user',
  611. name: 'RoleDemo',
  612. meta: {
  613. title: '权限管理',
  614. icon: 'user',
  615. alwaysShow: true
  616. },
  617. children: [
  618. {
  619. path: 'user',
  620. component: () => import('_v/role-demo/user/index.vue'),
  621. name: 'User',
  622. meta: {
  623. title: '用户管理'
  624. }
  625. },
  626. {
  627. path: 'role',
  628. component: () => import('_v/role-demo/role/index.vue'),
  629. name: 'Role',
  630. meta: {
  631. title: '角色管理'
  632. }
  633. }
  634. ]
  635. }
  636. ]
  637. const router = createRouter({
  638. history: createWebHashHistory(),
  639. strict: true,
  640. routes: constantRouterMap as RouteRecordRaw[]
  641. })
  642. export function resetRouter(): void {
  643. const resetWhiteNameList = [
  644. 'RedirectRoot',
  645. 'Redirect',
  646. 'Login',
  647. 'Root',
  648. 'Dashboard',
  649. 'Page404'
  650. ]
  651. router.getRoutes().forEach((route) => {
  652. const { name } = route
  653. if (name && !resetWhiteNameList.includes(name as string)) {
  654. router.hasRoute(name) && router.removeRoute(name)
  655. }
  656. })
  657. }
  658. export function setupRouter(app: App<Element>) {
  659. app.use(router)
  660. }
  661. export default router