index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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'
  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: 'loading',
  207. name: 'Loading',
  208. component: () => import('@/views/vab/loading/index'),
  209. meta: { title: 'loading', permissions: ['admin'] },
  210. },
  211. {
  212. path: 'player',
  213. name: 'Player',
  214. component: () => import('@/views/vab/player/index'),
  215. meta: { title: '视频播放器', permissions: ['admin'] },
  216. },
  217. {
  218. path: 'markdownEditor',
  219. name: 'MarkdownEditor',
  220. component: () => import('@/views/vab/markdownEditor/index'),
  221. meta: { title: 'markdown编辑器', permissions: ['admin'] },
  222. },
  223. {
  224. path: 'editor',
  225. name: 'Editor',
  226. component: () => import('@/views/vab/editor/index'),
  227. meta: {
  228. title: '富文本编辑器',
  229. permissions: ['admin'],
  230. badge: 'New',
  231. },
  232. },
  233. {
  234. path: 'backToTop',
  235. name: 'BackToTop',
  236. component: () => import('@/views/vab/backToTop/index'),
  237. meta: { title: '返回顶部', permissions: ['admin'] },
  238. },
  239. {
  240. path: 'lodash',
  241. name: 'Lodash',
  242. component: () => import('@/views/vab/lodash/index'),
  243. meta: { title: 'lodash', permissions: ['admin'] },
  244. },
  245. {
  246. path: 'smallComponents',
  247. name: 'SmallComponents',
  248. component: () => import('@/views/vab/smallComponents/index'),
  249. meta: { title: '小组件', permissions: ['admin'] },
  250. },
  251. {
  252. path: 'upload',
  253. name: 'Upload',
  254. component: () => import('@/views/vab/upload/index'),
  255. meta: { title: '上传', permissions: ['admin'] },
  256. },
  257. {
  258. path: 'log',
  259. name: 'Log',
  260. component: () => import('@/views/vab/errorLog/index'),
  261. meta: { title: '错误日志模拟', permissions: ['admin'] },
  262. },
  263. {
  264. path:
  265. 'https://github.com/chuzhixin/vue-admin-beautiful?utm_source=gold_browser_extension',
  266. name: 'ExternalLink',
  267. meta: {
  268. title: '外链',
  269. target: '_blank',
  270. permissions: ['admin', 'editor'],
  271. badge: 'New',
  272. },
  273. },
  274. {
  275. path: 'more',
  276. name: 'More',
  277. component: () => import('@/views/vab/more/index'),
  278. meta: { title: '关于', permissions: ['admin'] },
  279. },
  280. ],
  281. },
  282. {
  283. path: '/personnelManagement',
  284. component: Layout,
  285. redirect: 'noRedirect',
  286. name: 'PersonnelManagement',
  287. meta: { title: '配置', icon: 'users-cog', permissions: ['admin'] },
  288. children: [
  289. {
  290. path: 'userManagement',
  291. name: 'UserManagement',
  292. component: () =>
  293. import('@/views/personnelManagement/userManagement/index'),
  294. meta: { title: '用户管理' },
  295. },
  296. {
  297. path: 'roleManagement',
  298. name: 'RoleManagement',
  299. component: () =>
  300. import('@/views/personnelManagement/roleManagement/index'),
  301. meta: { title: '角色管理' },
  302. },
  303. {
  304. path: 'menuManagement',
  305. name: 'MenuManagement',
  306. component: () =>
  307. import('@/views/personnelManagement/menuManagement/index'),
  308. meta: { title: '菜单管理', badge: 'New' },
  309. },
  310. ],
  311. },
  312. {
  313. path: '/mall',
  314. component: Layout,
  315. redirect: 'noRedirect',
  316. name: 'Mall',
  317. meta: {
  318. title: '商城',
  319. icon: 'shopping-cart',
  320. permissions: ['admin'],
  321. },
  322. children: [
  323. {
  324. path: 'pay',
  325. name: 'Pay',
  326. component: () => import('@/views/mall/pay/index'),
  327. meta: {
  328. title: '支付',
  329. noKeepAlive: true,
  330. },
  331. children: null,
  332. },
  333. {
  334. path: 'goodsList',
  335. name: 'GoodsList',
  336. component: () => import('@/views/mall/goodsList/index'),
  337. meta: {
  338. title: '商品列表',
  339. },
  340. },
  341. ],
  342. },
  343. {
  344. path: '/error',
  345. component: EmptyLayout,
  346. redirect: 'noRedirect',
  347. name: 'Error',
  348. meta: { title: '错误页', icon: 'bug' },
  349. children: [
  350. {
  351. path: '401',
  352. name: 'Error401',
  353. component: () => import('@/views/401'),
  354. meta: { title: '401' },
  355. },
  356. {
  357. path: '404',
  358. name: 'Error404',
  359. component: () => import('@/views/404'),
  360. meta: { title: '404' },
  361. },
  362. ],
  363. },
  364. {
  365. path: '*',
  366. redirect: '/404',
  367. hidden: true,
  368. },
  369. ]
  370. const router = new VueRouter({
  371. base: publicPath,
  372. mode: routerMode,
  373. scrollBehavior: () => ({
  374. y: 0,
  375. }),
  376. routes: constantRoutes,
  377. })
  378. //注释的地方是允许路由重复点击,如果你觉得框架路由跳转规范太过严格可选择放开
  379. const originalPush = VueRouter.prototype.push
  380. VueRouter.prototype.push = function push(location, onResolve, onReject) {
  381. if (onResolve || onReject)
  382. return originalPush.call(this, location, onResolve, onReject)
  383. return originalPush.call(this, location).catch((err) => err)
  384. }
  385. export function resetRouter() {
  386. router.matcher = new VueRouter({
  387. base: publicPath,
  388. mode: routerMode,
  389. scrollBehavior: () => ({
  390. y: 0,
  391. }),
  392. routes: constantRoutes,
  393. }).matcher
  394. }
  395. export default router