index.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
  2. import { AppRouteRecordRaw } from './types'
  3. import useStore from '@/store'
  4. export const Layout = () => import('@/layout/index.vue')
  5. const HOME_URL = '/dashboard'
  6. // 参数说明: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
  7. // 静态路由
  8. export const sysStaticRouter: Array<AppRouteRecordRaw> = [
  9. {
  10. path: '/login',
  11. component: () => import('@/views/login/index.vue'),
  12. meta: { hidden: true }
  13. },
  14. {
  15. path: '/user_register',
  16. component: () => import('@/views/login/userRegister.vue'),
  17. meta: { hidden: true }
  18. },
  19. {
  20. path: '/reset_password',
  21. component: () => import('@/views/login/resetPassword.vue'),
  22. meta: { hidden: true }
  23. },
  24. // 主入口
  25. {
  26. path: '/',
  27. name: 'mainLayout',
  28. component: Layout,
  29. redirect: HOME_URL,
  30. // redirect: '/dashboard',
  31. children: [
  32. // 重定向
  33. {
  34. path: '/redirect/:path(.*)',
  35. meta: { hidden: true },
  36. component: () => import('@/views/redirect/index.vue')
  37. },
  38. {
  39. path: 'dashboard',
  40. component: () => import('@/views/dashboard/index.vue'),
  41. name: 'dashboard',
  42. meta: { title: 'dashboard', icon: 'icon-homepage', affix: true }
  43. }
  44. ]
  45. },
  46. {
  47. path: '/profile',
  48. component: Layout,
  49. name: 'profile',
  50. meta: { hidden: true, title: '用户' },
  51. redirect: '/profile/index',
  52. children: [
  53. {
  54. path: 'index',
  55. component: () => import('@/views/profile/index.vue'),
  56. name: 'profileIndex',
  57. meta: {
  58. hidden: true,
  59. title: 'profile',
  60. icon: 'le-account'
  61. // parentName: 'mainLayout'
  62. }
  63. }
  64. ]
  65. },
  66. {
  67. path: '/flow_create',
  68. component: Layout,
  69. name: 'flow_create',
  70. meta: { hidden: true, title: '创建流程' },
  71. redirect: '/flow_create/index',
  72. children: [
  73. {
  74. path: 'index',
  75. component: () => import('@/views/flow/create/index.vue'),
  76. name: 'flow_create',
  77. meta: { hidden: true, title: '创建流程', icon: '' }
  78. }
  79. ]
  80. }
  81. ]
  82. export const sysErrorRoutes = [
  83. {
  84. path: '/404',
  85. component: () => import('@/views/error-page/404.vue'),
  86. meta: { hidden: true }
  87. },
  88. {
  89. path: '/401',
  90. component: () => import('@/views/error-page/401.vue'),
  91. meta: { hidden: true }
  92. },
  93. {
  94. // redirect: '/404',
  95. path: '/:pathMatch(.*)',
  96. component: () => import('@/views/error-page/404.vue'),
  97. meta: { hidden: true }
  98. }
  99. ]
  100. // 展示示例相关菜单
  101. export const localDemoRoutes = !!import.meta.env.DEV
  102. ? [
  103. // 外部链接
  104. {
  105. path: '/external-link',
  106. component: Layout,
  107. children: [
  108. {
  109. path: 'https://github.com/LanceJiang/Lance-Element-Admin',
  110. meta: { title: '外部链接', icon: 'icon-link' }
  111. }
  112. ]
  113. },
  114. // 组件示例
  115. {
  116. path: '/components',
  117. component: Layout,
  118. redirect: '/index',
  119. children: [
  120. {
  121. path: 'index',
  122. component: () => import('@/views/components/index.vue'),
  123. name: 'comps',
  124. meta: { title: 'comps', icon: 'icon-excel' }
  125. }
  126. ]
  127. },
  128. // 表单示例
  129. {
  130. /*path: '/form',
  131. component: Layout,
  132. // meta: { title: 'Form', icon: 'guide' },
  133. redirect: '/default',
  134. children: [
  135. {
  136. path: 'default',
  137. component: () => import('@/views/form/default.vue'),
  138. name: 'FormDefault',
  139. meta: { title: 'form', icon: 'icon-guide' }
  140. }
  141. ]*/
  142. path: 'default',
  143. component: () => import('@/views/form/default.vue'),
  144. name: 'FormDefault',
  145. meta: { title: 'form', icon: 'icon-guide', parentName: 'mainLayout' }
  146. },
  147. // 列表示例
  148. {
  149. path: '/table',
  150. component: Layout,
  151. redirect: 'default',
  152. meta: { title: 'table', icon: 'icon-table' },
  153. children: [
  154. {
  155. path: 'default',
  156. component: () => import('@/views/table/default.vue'),
  157. name: 'TableDefault',
  158. meta: { title: 'table' /*, icon: 'table'*/ }
  159. },
  160. {
  161. path: 'multipleHeader',
  162. component: () => import('@/views/table/multipleHeader.vue'),
  163. name: 'multipleHeader',
  164. meta: { title: 'multipleHeader' }
  165. },
  166. {
  167. path: 'treeTable',
  168. component: () => import('@/views/table/treeTable.vue'),
  169. name: 'treeTable',
  170. meta: { title: 'treeTable' }
  171. },
  172. {
  173. path: 'mergeCells',
  174. component: () => import('@/views/table/mergeCells.vue'),
  175. name: 'mergeCells',
  176. meta: { title: 'mergeCells' }
  177. },
  178. {
  179. path: 'footerSummary',
  180. component: () => import('@/views/table/footerSummary.vue'),
  181. name: 'footerSummary',
  182. meta: { title: 'footerSummary' }
  183. },
  184. {
  185. path: 'expandTable',
  186. component: () => import('@/views/table/expandTable.vue'),
  187. name: 'expandTable',
  188. meta: { title: 'expandTable' }
  189. },
  190. {
  191. path: 'resizeParentHeightTable',
  192. component: () => import('@/views/table/resizeParentHeightTable.vue'),
  193. name: 'resizeParentHeightTable',
  194. meta: { title: 'resizeParentHeightTable' }
  195. }
  196. ]
  197. },
  198. {
  199. // demo演示
  200. path: '/demo',
  201. component: 'Layout',
  202. redirect: '/demo/adminManage',
  203. meta: { title: 'demo', icon: 'icon-peoples' },
  204. children: [
  205. {
  206. // path: '/demo/pageConfig',
  207. path: 'pageConfig',
  208. // component: () => import('@/views/demo/pageConfig/index'),
  209. component: 'demo/pageConfig/index',
  210. name: 'pageConfig',
  211. meta: { title: 'demo_pageConfig', icon: 'le-fangda1' }
  212. },
  213. {
  214. // 管理员管理
  215. // path: '/demo/adminManage',
  216. path: 'adminManage',
  217. name: 'adminManage',
  218. component: 'demo/adminManage/index',
  219. meta: { title: 'demo_adminManage', icon: 'Setting' }
  220. }
  221. ]
  222. },
  223. {
  224. path: '/menuNested',
  225. name: 'menuNested',
  226. component: 'Layout',
  227. redirect: '/menuNested/menu1',
  228. meta: {
  229. icon: 'List',
  230. title: '菜单嵌套'
  231. },
  232. children: [
  233. {
  234. path: '/menuNested/menu1',
  235. name: 'menu1',
  236. component: 'menuNested/menu1/index',
  237. meta: {
  238. icon: 'Menu',
  239. title: '菜单1'
  240. }
  241. },
  242. {
  243. path: '/menuNested/menu2',
  244. name: 'menu2',
  245. redirect: '/menuNested/menu2/menu21',
  246. component: 'RouteView',
  247. meta: {
  248. icon: 'Menu',
  249. title: '菜单2'
  250. // parentName: 'mainLayout'
  251. },
  252. children: [
  253. {
  254. path: '/menuNested/menu2/menu21',
  255. // path: 'menu21',
  256. name: 'menu21',
  257. component: 'menuNested/menu2/menu21/index',
  258. meta: {
  259. icon: 'Menu',
  260. title: '菜单2-1'
  261. }
  262. },
  263. ...Array.from({ length: 50 }).map((_, i) => {
  264. return {
  265. path: '/menuNested/menu2/menu23' + i,
  266. name: 'menu23_' + i,
  267. component: 'menuNested/menu2/menu23/index',
  268. meta: {
  269. icon: 'Menu',
  270. title: '菜单2-3_' + i
  271. }
  272. }
  273. }),
  274. {
  275. path: '/menuNested/menu2/menu22',
  276. // path: 'menu22',
  277. name: 'menu22',
  278. component: 'RouteView',
  279. redirect: '/menuNested/menu2/menu22/menu221',
  280. meta: {
  281. icon: 'Menu',
  282. title: '菜单2-2'
  283. },
  284. children: [
  285. {
  286. path: '/menuNested/menu2/menu22/menu221',
  287. // path: 'menu221',
  288. name: 'menu221',
  289. component: 'menuNested/menu2/menu22/menu221/index',
  290. meta: {
  291. icon: 'Menu',
  292. title: '菜单2-2-1'
  293. }
  294. },
  295. {
  296. path: '/menuNested/menu2/menu22/menu222',
  297. // path: 'menu222',
  298. name: 'menu222',
  299. component: 'menuNested/menu2/menu22/menu222/index',
  300. meta: {
  301. icon: 'Menu',
  302. title: '菜单2-2-2'
  303. }
  304. },
  305. ...Array.from({ length: 50 }).map((_, i) => {
  306. return {
  307. path: '/menuNested/menu2/menu22/menu222' + i,
  308. // path: 'menu222',
  309. name: 'menu222_' + i,
  310. component: 'menuNested/menu2/menu22/menu222/index',
  311. meta: {
  312. icon: 'Menu',
  313. title: '菜单2-2-2' + i
  314. }
  315. }
  316. })
  317. ]
  318. },
  319. {
  320. path: '/menuNested/menu2/menu23',
  321. // path: 'menu23',
  322. name: 'menu23',
  323. component: 'menuNested/menu2/menu23/index',
  324. meta: {
  325. icon: 'Menu',
  326. title: '菜单2-3'
  327. }
  328. } /*,
  329. ...Array.from({length: 50}).map((_, i) => {
  330. return {
  331. path: '/menuNested/menu2/menu23' + i,
  332. name: 'menu23' + i,
  333. component: 'menuNested/menu2/menu23/index',
  334. meta: {
  335. icon: 'Menu',
  336. title: '菜单2-3' + i
  337. }
  338. }
  339. })*/
  340. ]
  341. },
  342. {
  343. path: '/menuNested/menu3',
  344. name: 'menu3',
  345. component: 'menuNested/menu3/index',
  346. meta: {
  347. icon: 'Menu',
  348. title: '菜单3'
  349. }
  350. }
  351. ]
  352. }
  353. ]
  354. : []
  355. export const constantRoutes: AppRouteRecordRaw[] = [
  356. // 首页
  357. {
  358. // path: '/dashboard',
  359. path: HOME_URL,
  360. component: () => import('@/views/dashboard/index.vue'),
  361. name: 'dashboard',
  362. meta: { title: 'dashboard', icon: 'icon-homepage', affix: true, parentName: 'mainLayout' }
  363. },
  364. // ...localDemoRoutes,
  365. // 用户
  366. {
  367. path: '/profile',
  368. component: Layout,
  369. name: 'profile',
  370. meta: { hidden: true, title: '用户' },
  371. redirect: '/profile/index',
  372. children: [
  373. {
  374. path: 'index',
  375. component: () => import('@/views/profile/index.vue'),
  376. name: 'profileIndex',
  377. meta: {
  378. hidden: true,
  379. title: 'profile',
  380. icon: 'le-account'
  381. // parentName: 'mainLayout'
  382. }
  383. }
  384. ]
  385. }
  386. /*// 仅用于研发测试 START
  387. {
  388. path: '/test',
  389. component: Layout,
  390. // meta: {hidden: true, title: 'test', icon: 'system'},
  391. meta: { title: 'test', icon: 'system' },
  392. redirect: '/test/testSetup',
  393. children: [
  394. {
  395. path: 'testSetup',
  396. component: () => import('@/views/test/testSetup.vue'),
  397. name: 'testSetup',
  398. meta: { title: 'testSetup' }
  399. },
  400. {
  401. path: 'componentCommunication',
  402. component: () => import('@/views/test/componentCommunication/index.vue'),
  403. name: 'componentCommunication',
  404. meta: { title: '组件通信方式' }
  405. }
  406. ]
  407. }
  408. // 仅用于研发测试 END*/
  409. ]
  410. /**
  411. * local_permissionsMenuList: 每次有新的路由配置 请做好标注!!!
  412. * 本地 dev 调试 默认使用本地路由数据
  413. * (若想要调试 接口数据 请在 env.development.local 修改 VITE_APP_USE_LOCAL_ROUTES 不为 1即可)
  414. */
  415. export const local_permissionsMenuList: Array<AppRouteRecordRaw> = [
  416. ...constantRoutes,
  417. // 设置 权限
  418. {
  419. path: '/setting',
  420. component: 'Layout',
  421. meta: { title: '设置', icon: 'icon-swagger' },
  422. redirect: '/setting/user',
  423. children: [
  424. {
  425. path: 'user',
  426. // component: () => import('@/views/setting/user/index1.vue'),
  427. component: 'setting/user/index',
  428. name: 'user',
  429. meta: { title: '用户管理', icon: 'icon-logo' } // 本地icon
  430. },
  431. {
  432. path: 'role',
  433. // component: () => import('@/views/setting/role/index1.vue'),
  434. component: 'setting/role/index',
  435. name: 'role',
  436. meta: { title: '角色管理', icon: 'le-amazon' } // le-iconfont
  437. },
  438. {
  439. path: 'post',
  440. // component: () => import('@/views/setting/post/index1.vue'),
  441. component: 'setting/post/index',
  442. name: 'post',
  443. meta: { title: '岗位管理', icon: '' }
  444. },
  445. {
  446. path: 'app',
  447. // component: () => import('@/views/setting/app/index1.vue'),
  448. component: 'setting/app/index',
  449. name: 'app',
  450. meta: { title: '应用管理', icon: '' }
  451. },
  452. {
  453. path: 'department',
  454. // component: () => import('@/views/setting/department/index1.vue'),
  455. component: 'setting/department/index',
  456. name: 'department',
  457. meta: { title: '部门管理', icon: '' }
  458. },
  459. {
  460. path: 'region',
  461. // component: () => import('@/views/setting/region/index1.vue'),
  462. component: 'setting/region/index',
  463. name: 'region',
  464. meta: { title: '行政区域', icon: '' }
  465. },
  466. {
  467. path: 'configure',
  468. // component: () => import('@/views/setting/configure/index1.vue'),
  469. component: 'setting/configure/index',
  470. name: 'configure',
  471. meta: { title: '扩展配置', icon: '' }
  472. },
  473. {
  474. path: 'dict',
  475. // component: () => import('@/views/setting/dict/index1.vue'),
  476. component: 'setting/dict/index',
  477. name: 'dict',
  478. meta: { title: '字典管理', icon: '' }
  479. },
  480. {
  481. path: 'menu',
  482. component: () => import('@/views/setting/menu/index.vue'),
  483. // component: 'setting/menu/index',
  484. name: 'menu',
  485. meta: { title: '菜单管理', icon: 'PriceTag' } // element icons
  486. }
  487. ]
  488. },
  489. // 流程管理 权限
  490. {
  491. path: '/flow',
  492. // component: Layout,
  493. component: '',
  494. meta: { title: '流程管理', icon: 'icon-guide' },
  495. redirect: '/flow/group',
  496. children: [
  497. {
  498. path: 'group1',
  499. // component: () => import('@/views/flow/group/index1.vue'),
  500. component: 'flow/group/index1',
  501. name: 'flow_group1',
  502. meta: { title: '流程组', icon: '' }
  503. },
  504. {
  505. path: 'group',
  506. // component: () => import('@/views/flow/group/index1.vue'),
  507. component: 'flow/group/index',
  508. name: 'flow_group',
  509. meta: { title: '流程组 - ui调整', icon: '' }
  510. },
  511. {
  512. path: 'form',
  513. // component: () => import('@/views/flow/form/index1.vue'),
  514. component: 'flow/form/index',
  515. name: 'flow_form',
  516. meta: { title: '流程表单', icon: '' }
  517. },
  518. {
  519. path: 'create',
  520. // component: () => import('@/views/flow/create/index1.vue'),
  521. component: 'flow/create/index',
  522. name: 'flow_create',
  523. meta: { title: '创建流程', icon: '' }
  524. },
  525. {
  526. path: 'task',
  527. // component: () => import('@/views/flow/task/index1.vue'),
  528. component: 'flow/task/index',
  529. name: 'flow_task',
  530. meta: { title: '流程任务', icon: '' }
  531. },
  532. {
  533. path: 'instance',
  534. // component: () => import('@/views/flow/instance/index1.vue'),
  535. component: 'flow/instance/index',
  536. name: 'flow_instance',
  537. meta: { title: '流程实例', icon: '' }
  538. },
  539. {
  540. path: 'modal',
  541. // component: () => import('@/views/flow/modal/index1.vue'),
  542. component: 'flow/modal/index',
  543. name: 'flow_modal',
  544. meta: { title: '流程模型', icon: '' }
  545. }
  546. ]
  547. }
  548. // todo 请添加相关新路由描述
  549. ]
  550. // 创建路由
  551. const router = createRouter({
  552. history: createWebHashHistory(),
  553. routes: sysStaticRouter.concat(sysErrorRoutes) as RouteRecordRaw[],
  554. // 刷新时,滚动条位置还原
  555. scrollBehavior: () => ({ left: 0, top: 0 })
  556. })
  557. // 重置路由
  558. export function resetRouter() {
  559. const { permission } = useStore()
  560. permission.showMenuListFlat.forEach(route => {
  561. const name = route.name
  562. if (name && router.hasRoute(name)) {
  563. router.removeRoute(name)
  564. }
  565. })
  566. }
  567. export default router