index.ts 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. // 参数说明: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
  6. // 静态路由
  7. type RouteMeta = {
  8. // 标题
  9. title?: string
  10. // 图标
  11. icon?: string
  12. // 是否固定
  13. affix?: true
  14. // 是否在菜单列表进行隐藏
  15. hidden?: boolean
  16. // // 类型
  17. // type: string;
  18. }
  19. export const constantRoutes: Array<AppRouteRecordRaw> = [
  20. {
  21. path: '/redirect',
  22. component: Layout,
  23. meta: { hidden: true },
  24. children: [
  25. {
  26. path: '/redirect/:path(.*)',
  27. component: () => import('@/views/redirect/index.vue')
  28. }
  29. ]
  30. },
  31. {
  32. path: '/login',
  33. component: () => import('@/views/login/index.vue'),
  34. meta: { hidden: true }
  35. },
  36. {
  37. path: '/404',
  38. component: () => import('@/views/error-page/404.vue'),
  39. meta: { hidden: true }
  40. },
  41. {
  42. path: '/401',
  43. component: () => import('@/views/error-page/401.vue'),
  44. meta: { hidden: true }
  45. },
  46. // 首页
  47. {
  48. path: '/',
  49. component: Layout,
  50. redirect: '/dashboard',
  51. children: [
  52. {
  53. path: 'dashboard',
  54. component: () => import('@/views/dashboard/index.vue'),
  55. name: 'dashboard',
  56. meta: { title: 'dashboard', icon: 'homepage', affix: true }
  57. }
  58. ]
  59. },
  60. // 组件示例
  61. {
  62. path: '/components',
  63. component: Layout,
  64. redirect: '/index',
  65. children: [
  66. {
  67. path: 'index',
  68. component: () => import('@/views/components/index.vue'),
  69. name: 'comps',
  70. meta: { title: 'comps', icon: 'excel' }
  71. }
  72. ]
  73. },
  74. // 表单示例
  75. {
  76. path: '/form',
  77. component: Layout,
  78. // meta: { title: 'Form', icon: 'guide' },
  79. redirect: '/default',
  80. children: [
  81. {
  82. path: 'default',
  83. component: () => import('@/views/form/default.vue'),
  84. name: 'FormDefault',
  85. meta: { title: 'form', icon: 'guide' }
  86. }
  87. ]
  88. },
  89. // 列表示例
  90. {
  91. path: '/table',
  92. component: Layout,
  93. redirect: '/default',
  94. meta: { title: 'table', icon: 'table' },
  95. children: [
  96. {
  97. path: 'default',
  98. component: () => import('@/views/table/default.vue'),
  99. name: 'TableDefault',
  100. meta: { title: 'table' /*, icon: 'table'*/ }
  101. },
  102. {
  103. path: 'multipleHeader',
  104. component: () => import('@/views/table/multipleHeader.vue'),
  105. name: 'multipleHeader',
  106. meta: { title: 'multipleHeader' }
  107. },
  108. {
  109. path: 'treeTable',
  110. component: () => import('@/views/table/treeTable.vue'),
  111. name: 'treeTable',
  112. meta: { title: 'treeTable' }
  113. },
  114. {
  115. path: 'mergeCells',
  116. component: () => import('@/views/table/mergeCells.vue'),
  117. name: 'mergeCells',
  118. meta: { title: 'mergeCells' }
  119. },
  120. {
  121. path: 'footerSummary',
  122. component: () => import('@/views/table/footerSummary.vue'),
  123. name: 'footerSummary',
  124. meta: { title: 'footerSummary' }
  125. },
  126. {
  127. path: 'expandTable',
  128. component: () => import('@/views/table/expandTable.vue'),
  129. name: 'expandTable',
  130. meta: { title: 'expandTable' }
  131. },
  132. {
  133. path: 'resizeParentHeightTable',
  134. component: () => import('@/views/table/resizeParentHeightTable.vue'),
  135. name: 'resizeParentHeightTable',
  136. meta: { title: 'resizeParentHeightTable' }
  137. }
  138. ]
  139. },
  140. // 仅用于研发测试 START
  141. /*{
  142. path: '/test',
  143. component: Layout,
  144. // meta: {hidden: true, title: 'test', icon: 'system'},
  145. meta: { title: 'test', icon: 'system' },
  146. redirect: '/test/testSetup',
  147. children: [
  148. {
  149. path: 'testSetup',
  150. component: () => import('@/views/test/testSetup.vue'),
  151. name: 'testSetup',
  152. meta: { title: 'testSetup' }
  153. },
  154. {
  155. path: 'componentCommunication',
  156. component: () => import('@/views/test/componentCommunication/index.vue'),
  157. name: 'componentCommunication',
  158. meta: { title: '组件通信方式' }
  159. }
  160. ]
  161. },*/
  162. {
  163. path: '/setting',
  164. component: Layout,
  165. meta: { title: '设置', icon: 'guide' },
  166. redirect: '/setting/user',
  167. children: [
  168. {
  169. path: 'user',
  170. component: () => import('@/views/setting/user/index.vue'),
  171. name: 'user',
  172. meta: { title: '用户管理', icon: '' }
  173. },
  174. {
  175. path: 'post',
  176. component: () => import('@/views/setting/post/index.vue'),
  177. name: 'post',
  178. meta: { title: '岗位管理', icon: '' }
  179. },
  180. {
  181. path: 'role',
  182. component: () => import('@/views/setting/role/index.vue'),
  183. name: 'role',
  184. meta: { title: '角色管理', icon: '' }
  185. },
  186. {
  187. path: 'app',
  188. component: () => import('@/views/setting/app/index.vue'),
  189. name: 'app',
  190. meta: { title: '应用管理', icon: '' }
  191. },
  192. {
  193. path: 'department',
  194. component: () => import('@/views/setting/department/index.vue'),
  195. name: 'department',
  196. meta: { title: '部门管理', icon: '' }
  197. },
  198. {
  199. path: 'region',
  200. component: () => import('@/views/setting/region/index.vue'),
  201. name: 'region',
  202. meta: { title: '行政区域', icon: '' }
  203. },
  204. {
  205. path: 'configure',
  206. component: () => import('@/views/setting/configure/index.vue'),
  207. name: 'configure',
  208. meta: { title: '扩展配置', icon: '' }
  209. },
  210. {
  211. path: 'dict',
  212. component: () => import('@/views/setting/dict/index.vue'),
  213. name: 'dict',
  214. meta: { title: '字典管理', icon: '' }
  215. },
  216. {
  217. path: 'menu',
  218. component: () => import('@/views/setting/menu/index.vue'),
  219. name: 'menu',
  220. meta: { title: '菜单管理', icon: '' }
  221. }
  222. ]
  223. }
  224. // 仅用于研发测试 END
  225. // 外部链接
  226. /*{
  227. path: '/external-link',
  228. component: Layout,
  229. children: [
  230. {
  231. path: 'https://github.com/LanceJiang/vue3_element_admin',
  232. meta: { title: '外部链接', icon: 'link' }
  233. }
  234. ]
  235. }*/
  236. ]
  237. export const noFoundRouters = [
  238. {
  239. // redirect: '/404',
  240. path: '/:pathMatch(.*)',
  241. component: () => import('@/views/error-page/404.vue'),
  242. meta: { hidden: true }
  243. }
  244. ]
  245. /**
  246. * local_permissionsRoutes: 本地存储带权限路由 每次有新的路由配置 请做好标注!!!
  247. * 本地 dev 调试 默认使用本地路由数据
  248. * (若想要调试 接口数据 请在 env.development.local 修改 VITE_APP_USE_LOCAL_ROUTES 不为 1即可)
  249. */
  250. export const local_permissionsRoutes: Array<AppRouteRecordRaw> = [
  251. {
  252. // demo演示
  253. path: '/demo',
  254. component: 'Layout',
  255. redirect: '/demo/adminManage',
  256. meta: { title: 'demo', icon: 'peoples' },
  257. children: [
  258. {
  259. path: 'pageConfig',
  260. // component: () => import('@/views/demo/pageConfig/index'),
  261. component: 'demo/pageConfig/index',
  262. name: 'pageConfig',
  263. meta: { title: 'demo_pageConfig' }
  264. },
  265. {
  266. // 管理员管理
  267. path: 'adminManage',
  268. name: 'adminManage',
  269. component: 'demo/adminManage/index',
  270. meta: { title: 'demo_adminManage' }
  271. }
  272. ]
  273. },
  274. // todo 请添加相关新路由描述
  275. // 流程管理 权限
  276. {
  277. path: '/flow',
  278. // component: Layout,
  279. component: '',
  280. meta: { title: '流程管理', icon: 'guide' },
  281. redirect: '/flow/group',
  282. children: [
  283. {
  284. path: 'group1',
  285. // component: () => import('@/views/flow/group/index1.vue'),
  286. component: 'flow/group/index1',
  287. name: 'flow_group1',
  288. meta: { title: '流程组', icon: '' }
  289. },
  290. {
  291. path: 'group',
  292. // component: () => import('@/views/flow/group/index.vue'),
  293. component: 'flow/group/index',
  294. name: 'flow_group',
  295. meta: { title: '流程组 - ui调整', icon: '' }
  296. },
  297. {
  298. path: 'form',
  299. // component: () => import('@/views/flow/form/index.vue'),
  300. component: 'flow/form/index',
  301. name: 'flow_form',
  302. meta: { title: '流程表单', icon: '' }
  303. },
  304. {
  305. path: 'create',
  306. // component: () => import('@/views/flow/create/index.vue'),
  307. component: 'flow/create/index',
  308. name: 'flow_create',
  309. meta: { title: '创建流程', icon: '' }
  310. },
  311. {
  312. path: 'task',
  313. // component: () => import('@/views/flow/task/index.vue'),
  314. component: 'flow/task/index',
  315. name: 'flow_task',
  316. meta: { title: '流程任务', icon: '' }
  317. },
  318. {
  319. path: 'instance',
  320. // component: () => import('@/views/flow/instance/index.vue'),
  321. component: 'flow/instance/index',
  322. name: 'flow_instance',
  323. meta: { title: '流程实例', icon: '' }
  324. },
  325. {
  326. path: 'modal',
  327. // component: () => import('@/views/flow/modal/index.vue'),
  328. component: 'flow/modal/index',
  329. name: 'flow_modal',
  330. meta: { title: '流程模型', icon: '' }
  331. }
  332. ]
  333. }
  334. ]
  335. // 创建路由
  336. const router = createRouter({
  337. history: createWebHashHistory(),
  338. routes: constantRoutes.concat(noFoundRouters) as RouteRecordRaw[],
  339. // 刷新时,滚动条位置还原
  340. scrollBehavior: () => ({ left: 0, top: 0 })
  341. })
  342. // 重置路由
  343. export function resetRouter() {
  344. const { permission } = useStore()
  345. permission.routes.forEach(route => {
  346. const name = route.name
  347. if (name && router.hasRoute(name)) {
  348. router.removeRoute(name)
  349. }
  350. })
  351. }
  352. export default router