index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. /**
  2. * @author chuzhixin 1204505056@qq.com (不想保留author可删除)
  3. * @description router全局配置,如有必要可分文件抽离,其中asyncRoutes只有在intelligence模式下才会用到,vip文档中已提供路由的基础图标与小清新图标的配置方案,请仔细阅读
  4. */
  5. import Vue from 'vue'
  6. import VueRouter from 'vue-router'
  7. import Layout from '@/layouts'
  8. import EmptyLayout from '@/layouts/EmptyLayout'
  9. import { publicPath, routerMode } from '@/config/settings'
  10. Vue.use(VueRouter)
  11. export const constantRoutes = [
  12. {
  13. path: '/login',
  14. component: () => import('@/views/login/index'),
  15. hidden: true,
  16. },
  17. {
  18. path: '/register',
  19. component: () => import('@/views/register/index'),
  20. hidden: true,
  21. },
  22. {
  23. path: '/401',
  24. name: '401',
  25. component: () => import('@/views/401'),
  26. hidden: true,
  27. },
  28. {
  29. path: '/404',
  30. name: '404',
  31. component: () => import('@/views/404'),
  32. hidden: true,
  33. },
  34. ]
  35. export const asyncRoutes = [
  36. {
  37. path: '/',
  38. component: Layout,
  39. redirect: 'index',
  40. children: [
  41. {
  42. path: 'index',
  43. name: 'Index',
  44. component: () => import('@/views/index/index'),
  45. meta: {
  46. title: '首页',
  47. icon: 'home',
  48. affix: true,
  49. },
  50. },
  51. ],
  52. },
  53. /* {
  54. path: "/test",
  55. component: Layout,
  56. redirect: "noRedirect",
  57. children: [
  58. {
  59. path: "test",
  60. name: "Test",
  61. component: () => import("@/views/test/index"),
  62. meta: {
  63. title: "test",
  64. icon: "marker",
  65. permissions: ["admin"],
  66. },
  67. },
  68. ],
  69. }, */
  70. {
  71. path: '/vab',
  72. component: Layout,
  73. redirect: 'noRedirect',
  74. name: 'Vab',
  75. alwaysShow: true,
  76. meta: { title: '组件', icon: 'box-open' },
  77. children: [
  78. {
  79. path: 'permissions',
  80. name: 'Permission',
  81. component: () => import('@/views/vab/permissions/index'),
  82. meta: {
  83. title: '角色权限',
  84. permissions: ['admin', 'editor'],
  85. },
  86. },
  87. {
  88. path: 'icon',
  89. component: EmptyLayout,
  90. redirect: 'noRedirect',
  91. name: 'Icon',
  92. meta: {
  93. title: '图标',
  94. permissions: ['admin'],
  95. },
  96. children: [
  97. {
  98. path: 'awesomeIcon',
  99. name: 'AwesomeIcon',
  100. component: () => import('@/views/vab/icon/index'),
  101. meta: { title: '常规图标' },
  102. },
  103. {
  104. path: 'remixIcon',
  105. name: 'RemixIcon',
  106. component: () => import('@/views/vab/icon/remixIcon'),
  107. meta: { title: '小清新图标' },
  108. },
  109. {
  110. path: 'colorfulIcon',
  111. name: 'ColorfulIcon',
  112. component: () => import('@/views/vab/icon/colorfulIcon'),
  113. meta: { title: '多彩图标' },
  114. },
  115. ],
  116. },
  117. {
  118. path: 'table',
  119. component: () => import('@/views/vab/table/index'),
  120. name: 'Table',
  121. meta: {
  122. title: '表格',
  123. permissions: ['admin'],
  124. },
  125. },
  126. {
  127. path: 'map',
  128. component: () => import('@/views/vab/map/index'),
  129. name: 'Map',
  130. meta: {
  131. title: '地图',
  132. permissions: ['admin'],
  133. },
  134. },
  135. {
  136. path: 'webSocket',
  137. name: 'WebSocket',
  138. component: () => import('@/views/vab/webSocket/index'),
  139. meta: { title: 'webSocket', permissions: ['admin'] },
  140. },
  141. {
  142. path: 'form',
  143. name: 'Form',
  144. component: () => import('@/views/vab/form/index'),
  145. meta: { title: '表单', permissions: ['admin'] },
  146. },
  147. {
  148. path: 'element',
  149. name: 'Element',
  150. component: () => import('@/views/vab/element/index'),
  151. meta: { title: '常用组件', permissions: ['admin'] },
  152. },
  153. {
  154. path: 'tree',
  155. name: 'Tree',
  156. component: () => import('@/views/vab/tree/index'),
  157. meta: { title: '树', permissions: ['admin'] },
  158. },
  159. {
  160. path: 'card',
  161. name: 'Card',
  162. component: () => import('@/views/vab/card/index'),
  163. meta: { title: '卡片', permissions: ['admin'] },
  164. },
  165. {
  166. path: 'verify',
  167. name: 'Verify',
  168. component: () => import('@/views/vab/verify/index'),
  169. meta: { title: '验证码', permissions: ['admin'] },
  170. },
  171. {
  172. path: 'menu1',
  173. component: () => import('@/views/vab/nested/menu1/index'),
  174. name: 'Menu1',
  175. alwaysShow: true,
  176. meta: {
  177. title: '嵌套路由 1',
  178. permissions: ['admin'],
  179. },
  180. children: [
  181. {
  182. path: 'menu1-1',
  183. name: 'Menu1-1',
  184. alwaysShow: true,
  185. meta: { title: '嵌套路由 1-1' },
  186. component: () => import('@/views/vab/nested/menu1/menu1-1/index'),
  187. children: [
  188. {
  189. path: 'menu1-1-1',
  190. name: 'Menu1-1-1',
  191. meta: { title: '嵌套路由 1-1-1' },
  192. component: () =>
  193. import('@/views/vab/nested/menu1/menu1-1/menu1-1-1/index'),
  194. },
  195. ],
  196. },
  197. ],
  198. },
  199. {
  200. path: 'magnifier',
  201. name: 'Magnifier',
  202. component: () => import('@/views/vab/magnifier/index'),
  203. meta: { title: '放大镜', permissions: ['admin'] },
  204. },
  205. {
  206. path: 'echarts',
  207. name: 'Echarts',
  208. component: () => import('@/views/vab/echarts/index'),
  209. meta: { title: '图表', permissions: ['admin'] },
  210. },
  211. {
  212. path: 'loading',
  213. name: 'Loading',
  214. component: () => import('@/views/vab/loading/index'),
  215. meta: { title: 'loading', permissions: ['admin'] },
  216. },
  217. {
  218. path: 'player',
  219. name: 'Player',
  220. component: () => import('@/views/vab/player/index'),
  221. meta: { title: '视频播放器', permissions: ['admin'] },
  222. },
  223. {
  224. path: 'markdownEditor',
  225. name: 'MarkdownEditor',
  226. component: () => import('@/views/vab/markdownEditor/index'),
  227. meta: { title: 'markdown编辑器', permissions: ['admin'] },
  228. },
  229. {
  230. path: 'editor',
  231. name: 'Editor',
  232. component: () => import('@/views/vab/editor/index'),
  233. meta: {
  234. title: '富文本编辑器',
  235. permissions: ['admin'],
  236. badge: 'New',
  237. },
  238. },
  239. {
  240. path: 'backToTop',
  241. name: 'BackToTop',
  242. component: () => import('@/views/vab/backToTop/index'),
  243. meta: { title: '返回顶部', permissions: ['admin'] },
  244. },
  245. {
  246. path: 'lodash',
  247. name: 'Lodash',
  248. component: () => import('@/views/vab/lodash/index'),
  249. meta: { title: 'lodash', permissions: ['admin'] },
  250. },
  251. {
  252. path: 'imgComparison',
  253. name: 'ImgComparison',
  254. component: () => import('@/views/vab/imgComparison/index'),
  255. meta: { title: '图像拖拽比对', permissions: ['admin'] },
  256. },
  257. {
  258. path: 'smallComponents',
  259. name: 'SmallComponents',
  260. component: () => import('@/views/vab/smallComponents/index'),
  261. meta: { title: '小组件', permissions: ['admin'] },
  262. },
  263. {
  264. path: 'upload',
  265. name: 'Upload',
  266. component: () => import('@/views/vab/upload/index'),
  267. meta: { title: '上传', permissions: ['admin'] },
  268. },
  269. {
  270. path: 'log',
  271. name: 'Log',
  272. component: () => import('@/views/vab/errorLog/index'),
  273. meta: { title: '错误日志模拟', permissions: ['admin'] },
  274. },
  275. {
  276. path:
  277. 'https://github.com/chuzhixin/vue-admin-beautiful?utm_source=gold_browser_extension',
  278. name: 'ExternalLink',
  279. meta: {
  280. title: '外链',
  281. target: '_blank',
  282. permissions: ['admin', 'editor'],
  283. badge: 'New',
  284. },
  285. },
  286. {
  287. path: 'more',
  288. name: 'More',
  289. component: () => import('@/views/vab/more/index'),
  290. meta: { title: '关于', permissions: ['admin'] },
  291. },
  292. ],
  293. },
  294. {
  295. path: '/personnelManagement',
  296. component: Layout,
  297. redirect: 'noRedirect',
  298. name: 'PersonnelManagement',
  299. meta: { title: '配置', icon: 'users-cog', permissions: ['admin'] },
  300. children: [
  301. {
  302. path: 'userManagement',
  303. name: 'UserManagement',
  304. component: () =>
  305. import('@/views/personnelManagement/userManagement/index'),
  306. meta: { title: '用户管理' },
  307. },
  308. {
  309. path: 'roleManagement',
  310. name: 'RoleManagement',
  311. component: () =>
  312. import('@/views/personnelManagement/roleManagement/index'),
  313. meta: { title: '角色管理' },
  314. },
  315. {
  316. path: 'menuManagement',
  317. name: 'MenuManagement',
  318. component: () =>
  319. import('@/views/personnelManagement/menuManagement/index'),
  320. meta: { title: '菜单管理', badge: 'New' },
  321. },
  322. ],
  323. },
  324. {
  325. path: '/mall',
  326. component: Layout,
  327. redirect: 'noRedirect',
  328. name: 'Mall',
  329. meta: {
  330. title: '商城',
  331. icon: 'shopping-cart',
  332. permissions: ['admin'],
  333. },
  334. children: [
  335. {
  336. path: 'pay',
  337. name: 'Pay',
  338. component: () => import('@/views/mall/pay/index'),
  339. meta: {
  340. title: '支付',
  341. noKeepAlive: true,
  342. },
  343. children: null,
  344. },
  345. {
  346. path: 'goodsList',
  347. name: 'GoodsList',
  348. component: () => import('@/views/mall/goodsList/index'),
  349. meta: {
  350. title: '商品列表',
  351. },
  352. },
  353. ],
  354. },
  355. {
  356. path: '/error',
  357. component: EmptyLayout,
  358. redirect: 'noRedirect',
  359. name: 'Error',
  360. meta: { title: '错误页', icon: 'bug' },
  361. children: [
  362. {
  363. path: '401',
  364. name: 'Error401',
  365. component: () => import('@/views/401'),
  366. meta: { title: '401' },
  367. },
  368. {
  369. path: '404',
  370. name: 'Error404',
  371. component: () => import('@/views/404'),
  372. meta: { title: '404' },
  373. },
  374. ],
  375. },
  376. {
  377. path: '*',
  378. redirect: '/404',
  379. hidden: true,
  380. },
  381. ]
  382. const router = new VueRouter({
  383. base: publicPath,
  384. mode: routerMode,
  385. scrollBehavior: () => ({
  386. y: 0,
  387. }),
  388. routes: constantRoutes,
  389. })
  390. //注释的地方是允许路由重复点击,如果你觉得框架路由跳转规范太过严格可选择放开
  391. const originalPush = VueRouter.prototype.push
  392. VueRouter.prototype.push = function push(location, onResolve, onReject) {
  393. if (onResolve || onReject)
  394. return originalPush.call(this, location, onResolve, onReject)
  395. return originalPush.call(this, location).catch((err) => err)
  396. }
  397. export function resetRouter() {
  398. router.matcher = new VueRouter({
  399. base: publicPath,
  400. mode: routerMode,
  401. scrollBehavior: () => ({
  402. y: 0,
  403. }),
  404. routes: constantRoutes,
  405. }).matcher
  406. }
  407. export default router