index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. /**
  2. * @copyright chuzhixin 1204505056@qq.com
  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: "/personalCenter",
  55. component: Layout,
  56. hidden: true,
  57. redirect: "personalCenter",
  58. children: [
  59. {
  60. path: "personalCenter",
  61. name: "PersonalCenter",
  62. component: () => import("@/views/personalCenter/index"),
  63. meta: {
  64. title: "个人中心",
  65. },
  66. },
  67. ],
  68. },
  69. /* {
  70. path: "/test",
  71. component: Layout,
  72. redirect: "noRedirect",
  73. children: [
  74. {
  75. path: "test",
  76. name: "Test",
  77. component: () => import("@/views/test/index"),
  78. meta: {
  79. title: "test",
  80. icon: "marker",
  81. permissions: ["admin"],
  82. },
  83. },
  84. ],
  85. }, */
  86. {
  87. path: "/vab",
  88. component: Layout,
  89. redirect: "noRedirect",
  90. name: "Vab",
  91. alwaysShow: true,
  92. meta: { title: "组件", icon: "box-open" },
  93. children: [
  94. {
  95. path: "permissions",
  96. name: "Permission",
  97. component: () => import("@/views/vab/permissions/index"),
  98. meta: {
  99. title: "角色权限",
  100. permissions: ["admin", "editor"],
  101. },
  102. },
  103. {
  104. path:
  105. "https://github.com/chuzhixin/vue-admin-beautiful?utm_source=gold_browser_extension",
  106. name: "ExternalLink",
  107. meta: {
  108. title: "外链",
  109. target: "_blank",
  110. permissions: ["admin", "editor"],
  111. badge: "New",
  112. },
  113. },
  114. {
  115. path: "icon",
  116. component: EmptyLayout,
  117. redirect: "noRedirect",
  118. name: "Icon",
  119. meta: {
  120. title: "图标",
  121. permissions: ["admin"],
  122. },
  123. children: [
  124. {
  125. path: "awesomeIcon",
  126. name: "AwesomeIcon",
  127. component: () => import("@/views/vab/icon/index"),
  128. meta: { title: "常规图标" },
  129. },
  130. {
  131. path: "remixIcon",
  132. name: "RemixIcon",
  133. component: () => import("@/views/vab/icon/remixIcon"),
  134. meta: { title: "小清新图标" },
  135. },
  136. {
  137. path: "colorfulIcon",
  138. name: "ColorfulIcon",
  139. component: () => import("@/views/vab/icon/colorfulIcon"),
  140. meta: { title: "多彩图标" },
  141. },
  142. ],
  143. },
  144. {
  145. path: "table",
  146. component: EmptyLayout,
  147. redirect: "noRedirect",
  148. name: "Table",
  149. meta: {
  150. title: "表格",
  151. permissions: ["admin"],
  152. },
  153. children: [
  154. {
  155. path: "comprehensiveTable",
  156. name: "ComprehensiveTable",
  157. component: () => import("@/views/vab/table/index"),
  158. meta: { title: "综合表格" },
  159. },
  160. {
  161. path: "inlineEditTable",
  162. name: "InlineEditTable",
  163. component: () => import("@/views/vab/table/inlineEditTable"),
  164. meta: { title: "行内编辑" },
  165. },
  166. ],
  167. },
  168. {
  169. path: "map",
  170. component: () => import("@/views/vab/map/index"),
  171. name: "Map",
  172. meta: {
  173. title: "地图",
  174. permissions: ["admin"],
  175. },
  176. },
  177. {
  178. path: "webSocket",
  179. name: "WebSocket",
  180. component: () => import("@/views/vab/webSocket/index"),
  181. meta: { title: "webSocket", permissions: ["admin"] },
  182. },
  183. {
  184. path: "form",
  185. name: "Form",
  186. component: () => import("@/views/vab/form/index"),
  187. meta: { title: "表单", permissions: ["admin"] },
  188. },
  189. {
  190. path: "element",
  191. name: "Element",
  192. component: () => import("@/views/vab/element/index"),
  193. meta: { title: "常用组件", permissions: ["admin"] },
  194. },
  195. {
  196. path: "tree",
  197. name: "Tree",
  198. component: () => import("@/views/vab/tree/index"),
  199. meta: { title: "树", permissions: ["admin"] },
  200. },
  201. {
  202. path: "card",
  203. name: "Card",
  204. component: () => import("@/views/vab/card/index"),
  205. meta: { title: "卡片", permissions: ["admin"] },
  206. },
  207. {
  208. path: "verify",
  209. name: "Verify",
  210. component: () => import("@/views/vab/verify/index"),
  211. meta: { title: "验证码", permissions: ["admin"] },
  212. },
  213. {
  214. path: "menu1",
  215. component: () => import("@/views/vab/nested/menu1/index"),
  216. name: "Menu1",
  217. alwaysShow: true,
  218. meta: {
  219. title: "嵌套路由 1",
  220. permissions: ["admin"],
  221. },
  222. children: [
  223. {
  224. path: "menu1-1",
  225. name: "Menu1-1",
  226. alwaysShow: true,
  227. meta: { title: "嵌套路由 1-1" },
  228. component: () => import("@/views/vab/nested/menu1/menu1-1/index"),
  229. children: [
  230. {
  231. path: "menu1-1-1",
  232. name: "Menu1-1-1",
  233. meta: { title: "嵌套路由 1-1-1" },
  234. component: () =>
  235. import("@/views/vab/nested/menu1/menu1-1/menu1-1-1/index"),
  236. },
  237. ],
  238. },
  239. ],
  240. },
  241. {
  242. path: "magnifier",
  243. name: "Magnifier",
  244. component: () => import("@/views/vab/magnifier/index"),
  245. meta: { title: "放大镜", permissions: ["admin"] },
  246. },
  247. {
  248. path: "echarts",
  249. name: "Echarts",
  250. component: () => import("@/views/vab/echarts/index"),
  251. meta: { title: "图表", permissions: ["admin"] },
  252. },
  253. {
  254. path: "loading",
  255. name: "Loading",
  256. component: () => import("@/views/vab/loading/index"),
  257. meta: { title: "loading", permissions: ["admin"] },
  258. },
  259. {
  260. path: "player",
  261. name: "Player",
  262. component: () => import("@/views/vab/player/index"),
  263. meta: { title: "视频播放器", permissions: ["admin"] },
  264. },
  265. {
  266. path: "markdownEditor",
  267. name: "MarkdownEditor",
  268. component: () => import("@/views/vab/markdownEditor/index"),
  269. meta: { title: "markdown编辑器", permissions: ["admin"] },
  270. },
  271. {
  272. path: "editor",
  273. name: "Editor",
  274. component: () => import("@/views/vab/editor/index"),
  275. meta: {
  276. title: "富文本编辑器",
  277. permissions: ["admin"],
  278. badge: "New",
  279. },
  280. },
  281. {
  282. path: "backToTop",
  283. name: "BackToTop",
  284. component: () => import("@/views/vab/backToTop/index"),
  285. meta: { title: "返回顶部", permissions: ["admin"] },
  286. },
  287. {
  288. path: "lodash",
  289. name: "Lodash",
  290. component: () => import("@/views/vab/lodash/index"),
  291. meta: { title: "lodash", permissions: ["admin"] },
  292. },
  293. {
  294. path: "imgComparison",
  295. name: "ImgComparison",
  296. component: () => import("@/views/vab/imgComparison/index"),
  297. meta: { title: "图像拖拽比对", permissions: ["admin"] },
  298. },
  299. {
  300. path: "markdown",
  301. name: "Markdown",
  302. component: () => import("@/views/vab/markdown/index"),
  303. meta: { title: "markdown阅读器", permissions: ["admin"] },
  304. },
  305. {
  306. path: "smallComponents",
  307. name: "SmallComponents",
  308. component: () => import("@/views/vab/smallComponents/index"),
  309. meta: { title: "小组件", permissions: ["admin"] },
  310. },
  311. {
  312. path: "upload",
  313. name: "Upload",
  314. component: () => import("@/views/vab/upload/index"),
  315. meta: { title: "上传", permissions: ["admin"] },
  316. },
  317. {
  318. path: "log",
  319. name: "Log",
  320. component: () => import("@/views/vab/errorLog/index"),
  321. meta: { title: "错误日志模拟", permissions: ["admin"] },
  322. },
  323. {
  324. path: "more",
  325. name: "More",
  326. component: () => import("@/views/vab/more/index"),
  327. meta: { title: "更多组件", permissions: ["admin"] },
  328. },
  329. ],
  330. },
  331. {
  332. path: "/personnelManagement",
  333. component: Layout,
  334. redirect: "noRedirect",
  335. name: "PersonnelManagement",
  336. meta: { title: "配置", icon: "users-cog", permissions: ["admin"] },
  337. children: [
  338. {
  339. path: "userManagement",
  340. name: "UserManagement",
  341. component: () =>
  342. import("@/views/personnelManagement/userManagement/index"),
  343. meta: { title: "用户管理" },
  344. },
  345. {
  346. path: "roleManagement",
  347. name: "RoleManagement",
  348. component: () =>
  349. import("@/views/personnelManagement/roleManagement/index"),
  350. meta: { title: "角色管理" },
  351. },
  352. {
  353. path: "menuManagement",
  354. name: "MenuManagement",
  355. component: () =>
  356. import("@/views/personnelManagement/menuManagement/index"),
  357. meta: { title: "菜单管理", badge: "New" },
  358. },
  359. ],
  360. },
  361. {
  362. path: "/mall",
  363. component: Layout,
  364. redirect: "noRedirect",
  365. name: "Mall",
  366. meta: {
  367. title: "商城",
  368. icon: "shopping-cart",
  369. permissions: ["admin"],
  370. },
  371. children: [
  372. {
  373. path: "pay",
  374. name: "Pay",
  375. component: () => import("@/views/mall/pay/index"),
  376. meta: {
  377. title: "支付",
  378. noKeepAlive: true,
  379. },
  380. children: null,
  381. },
  382. {
  383. path: "goodsList",
  384. name: "GoodsList",
  385. component: () => import("@/views/mall/goodsList/index"),
  386. meta: {
  387. title: "商品列表",
  388. },
  389. },
  390. ],
  391. },
  392. {
  393. path: "/error",
  394. component: EmptyLayout,
  395. redirect: "noRedirect",
  396. name: "Error",
  397. meta: { title: "错误页", icon: "bug" },
  398. children: [
  399. {
  400. path: "401",
  401. name: "Error401",
  402. component: () => import("@/views/401"),
  403. meta: { title: "401" },
  404. },
  405. {
  406. path: "404",
  407. name: "Error404",
  408. component: () => import("@/views/404"),
  409. meta: { title: "404" },
  410. },
  411. ],
  412. },
  413. {
  414. path: "*",
  415. redirect: "/404",
  416. hidden: true,
  417. },
  418. ];
  419. const router = new VueRouter({
  420. base: publicPath,
  421. mode: routerMode,
  422. scrollBehavior: () => ({
  423. y: 0,
  424. }),
  425. routes: constantRoutes,
  426. });
  427. //注释的地方是允许路由重复点击,如果你觉得框架路由跳转规范太过严格可选择放开
  428. /* const originalPush = VueRouter.prototype.push;
  429. VueRouter.prototype.push = function push(location, onResolve, onReject) {
  430. if (onResolve || onReject)
  431. return originalPush.call(this, location, onResolve, onReject);
  432. return originalPush.call(this, location).catch((err) => err);
  433. }; */
  434. export function resetRouter() {
  435. router.matcher = new VueRouter({
  436. base: publicPath,
  437. mode: routerMode,
  438. scrollBehavior: () => ({
  439. y: 0,
  440. }),
  441. routes: constantRoutes,
  442. }).matcher;
  443. }
  444. export default router;