index.ts 14 KB

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