index.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* eslint-disable camelcase */
  2. /**
  3. * 全站路由配置
  4. *
  5. * 建议:
  6. * 1. 代码中路由统一使用name属性跳转(不使用path属性)
  7. */
  8. import Vue from 'vue'
  9. import Router from 'vue-router'
  10. import { clearLoginInfo } from '@/utils'
  11. // import MainFrame from "@/views/main.vue"
  12. // import MainHome from "@/views/common/home.vue"
  13. Vue.use(Router)
  14. // 解决路由重复跳转报错
  15. const originalPush = Router.prototype.push
  16. const originalReplace = Router.prototype.replace
  17. // 修改原型对象中的push函数
  18. Router.prototype.push = function push(location) {
  19. // @ts-ignore
  20. return originalPush.call(this, location).catch(err => err)
  21. }
  22. // 修改原型对象中的replace函数
  23. Router.prototype.replace = function replace(location) {
  24. // @ts-ignore
  25. return originalReplace.call(this, location).catch(err => err)
  26. }
  27. // 开发环境不使用懒加载, 因为懒加载页面太多的话会造成webpack热更新太慢, 所以只有生产环境使用懒加载
  28. const _import = require('./import-' + process.env.NODE_ENV)
  29. export const pages = [
  30. {
  31. path: "/home",
  32. component: _import("common/home"),
  33. name: "home",
  34. meta: { title: "首页", sidebar: false, icon: "index", isTab: false }
  35. }, {
  36. path: "/prod/product/list",
  37. component: _import("modules/prod/prodList"),
  38. name: "prodList",
  39. meta: { title: "产品管理", sidebar: true, icon: "product", isTab: true }
  40. }, {
  41. path: "/prod/product/edit/:id",
  42. component: _import("modules/prod/prodInfo"),
  43. name: "prodInfo",
  44. meta: { title: "产品信息", sidebar: false, icon: "", isTab: false }
  45. }, {
  46. path: "/prod/category/list",
  47. component: _import("modules/prod/category"),
  48. name: "categoryList",
  49. meta: { title: "分类管理", sidebar: true, icon: "inbox", isTab: true }
  50. }, {
  51. path: "/user/list",
  52. component: _import("modules/user/user"),
  53. name: "userList",
  54. meta: { title: "用户管理", sidebar: true, icon: "user", isTab: true }
  55. }, {
  56. path: "/order/list",
  57. component: _import("modules/order/order"),
  58. name: "orderList",
  59. meta: { title: "订单管理", sidebar: true, icon: "order", isTab: true }
  60. }, {
  61. path: "/liveroom/list",
  62. component: _import("modules/liveroom/liveroomList"),
  63. name: "liveroomList",
  64. meta: { title: "直播间管理", sidebar: true, icon: "broadcast", isTab: true }
  65. }, {
  66. path: "/liveroom/edit/:id",
  67. component: _import("modules/liveroom/liveroomEdit"),
  68. name: "liveroomEdit",
  69. meta: { title: "直播间信息", sidebar: false, icon: "", isTab: false }
  70. }, {
  71. path: "/liveroom/liveroom-product-jump-record/:id",
  72. component: _import("modules/liveroom/liveroomProductJumpRecord"),
  73. name: "liveroomProductJumpRecord",
  74. meta: { title: "直播间商品跳转记录", sidebar: false, icon: "", isTab: false }
  75. }, {
  76. path: "/liveroom/product/:id",
  77. component: _import("modules/liveroom/liveroomProd"),
  78. name: "liveroomProd",
  79. meta: { title: "直播间商品库", sidebar: false, icon: "", isTab: false }
  80. }, {
  81. path: "/liveroom/consults/:id",
  82. component: _import("modules/liveroom/liveroomConsults"),
  83. name: "liveroomConsults",
  84. meta: { title: "直播间客户咨询", sidebar: false, icon: "", isTab: false }
  85. },
  86. ]
  87. const routes = [
  88. { path: '/404', component: _import('common/404'), name: '404', meta: { title: '未找到该页面' } },
  89. { path: '/login', component: _import('common/login'), name: 'login', meta: { title: '登录' } },
  90. {
  91. path: "/",
  92. component: _import("main"),
  93. name: 'main',
  94. redirect: { name: 'home' },
  95. meta: { title: '主入口整体布局' },
  96. children: pages,
  97. beforeEnter(to: string, from: string, next: Function) {
  98. // @ts-ignore
  99. let authorization = Vue.cookie.get('Authorization')
  100. if (!authorization || !/\S/.test(authorization)) {
  101. clearLoginInfo()
  102. next({ name: 'login' })
  103. }
  104. next()
  105. }
  106. }
  107. ]
  108. const router = new Router({
  109. mode: 'hash',
  110. // @ts-ignore
  111. routes,
  112. // @ts-ignore
  113. scrollBehavior: () => ({ y: 0 }),
  114. })
  115. export default router