index.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import Vue from "vue";
  2. import Router from "vue-router";
  3. import store from "../store/index";
  4. Vue.use(Router);
  5. const router = new Router({
  6. routes: [
  7. {
  8. path: "/",
  9. redirect: "/login"
  10. },
  11. {
  12. path: "/login",
  13. component: () => import("@/views/login/index"),
  14. meta: {
  15. title: "登陆"
  16. }
  17. },
  18. {
  19. path: "/expire",
  20. component: () => import("@/views/expire/index"),
  21. meta: {
  22. title: "到期"
  23. }
  24. },
  25. {
  26. path: "/index",
  27. component: () => import("@/views/index/index"),
  28. meta: {
  29. title: "车间生产管家",
  30. keepAlive: true
  31. }
  32. },
  33. {
  34. path: "/todayPlan",
  35. component: () => import("@/views/planView/todayPlan/todayPlan"),
  36. meta: {
  37. title: "今日计划",
  38. keepAlive: false
  39. }
  40. },
  41. {
  42. path: "/distribution",
  43. name: "distribution",
  44. component: () => import("@/views/planView/todayPlan/distribution"),
  45. meta: {
  46. title: "计划详情",
  47. keepAlive: false
  48. }
  49. },
  50. {
  51. path: "/tomorrowPlan",
  52. component: () => import("@/views/planView/tomorrowPlan/tomorrowPlan"),
  53. meta: {
  54. title: "明日计划",
  55. keepAlive: false
  56. }
  57. },
  58. {
  59. path: "/InsertionPlan",
  60. component: () => import("@/views/planView/InsertionPlan/InsertionPlan"),
  61. meta: {
  62. title: "插单计划",
  63. keepAlive: false
  64. }
  65. },
  66. {
  67. path: "/statisticsView",
  68. component: () => import("@/views/statisticsView/statisticsView"),
  69. meta: {
  70. title: "数据统计",
  71. keepAlive: false
  72. }
  73. },
  74. {
  75. path: "/groupView",
  76. component: () => import("@/views/groupView/groupView"),
  77. meta: {
  78. title: "班组人员",
  79. keepAlive: false
  80. }
  81. },
  82. {
  83. path: "/workView",
  84. component: () => import("@/views/workView/workView"),
  85. meta: {
  86. title: "报工",
  87. keepAlive: false
  88. }
  89. },
  90. {
  91. path: "/test",
  92. meta: {
  93. title: "测试页面"
  94. },
  95. component: () => import("@/views/test/index")
  96. },
  97. {
  98. path: "/tests",
  99. meta: {
  100. title: "测试页面2"
  101. },
  102. component: () => import("@/views/test/list")
  103. },
  104. {
  105. path: "/clearStorage",
  106. meta: {
  107. title: "清空存储"
  108. },
  109. component: () => import("@/views/test/clearStorage")
  110. },
  111. {
  112. path: "/my",
  113. component: () => import("@/views/my/index"),
  114. redirect: "/my/center",
  115. children: [
  116. {
  117. path: "center",
  118. meta: {
  119. title: "个人中心"
  120. },
  121. component: () => import("@/views/my/children/center")
  122. },
  123. {
  124. path: "set",
  125. meta: {
  126. title: "修改密码"
  127. },
  128. component: () => import("@/views/my/children/set")
  129. }
  130. ]
  131. },
  132. {
  133. path: "/pdf",
  134. meta: {
  135. title: "PDF"
  136. },
  137. component: () => import("@/views/pdf/ppd")
  138. },
  139. {
  140. path: "*",
  141. component: () => import("@/components/NotFound")
  142. }
  143. ]
  144. });
  145. // 解决编程式路由往同一地址跳转时会报错的情况
  146. const originalPush = Router.prototype.push;
  147. const originalReplace = Router.prototype.replace;
  148. Router.prototype.push = function push(location, onResolve, onReject) {
  149. if (onResolve || onReject)
  150. return originalPush.call(this, location, onResolve, onReject);
  151. return originalPush.call(this, location).catch(err => err);
  152. };
  153. Router.prototype.replace = function push(location, onResolve, onReject) {
  154. if (onResolve || onReject)
  155. return originalReplace.call(this, location, onResolve, onReject);
  156. return originalReplace.call(this, location).catch(err => err);
  157. };
  158. router.beforeEach((to, from, next) => {
  159. let { title, needLogin } = to.meta;
  160. let { isLogin } = store.state;
  161. document.title = title;
  162. if (needLogin && !isLogin) {
  163. next({
  164. path: "/login"
  165. });
  166. } else {
  167. next();
  168. }
  169. });
  170. export default router;