index.ts 14 KB

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