index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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: "/InsertionPlanAdd",
  68. name: '计划新增',
  69. component: () => import("@/views/planView/InsertionPlan/InsertionPlanAdd"),
  70. meta: {
  71. title: "计划新增",
  72. keepAlive: false
  73. }
  74. },
  75. {
  76. path: "/statisticsView",
  77. component: () => import("@/views/statisticsView/statisticsView"),
  78. meta: {
  79. title: "数据统计",
  80. keepAlive: false
  81. }
  82. },
  83. {
  84. path: "/groupView",
  85. component: () => import("@/views/groupView/groupView"),
  86. meta: {
  87. title: "班组人员",
  88. keepAlive: false
  89. }
  90. },
  91. {
  92. path: "/workView",
  93. component: () => import("@/views/workView/workView"),
  94. meta: {
  95. title: "报工",
  96. keepAlive: false
  97. }
  98. },
  99. {
  100. path: "/test",
  101. meta: {
  102. title: "测试页面"
  103. },
  104. component: () => import("@/views/test/index")
  105. },
  106. {
  107. path: "/tests",
  108. meta: {
  109. title: "测试页面2"
  110. },
  111. component: () => import("@/views/test/list")
  112. },
  113. {
  114. path: "/clearStorage",
  115. meta: {
  116. title: "清空存储"
  117. },
  118. component: () => import("@/views/test/clearStorage")
  119. },
  120. {
  121. path: "/my",
  122. component: () => import("@/views/my/index"),
  123. redirect: "/my/center",
  124. children: [
  125. {
  126. path: "center",
  127. meta: {
  128. title: "个人中心"
  129. },
  130. component: () => import("@/views/my/children/center")
  131. },
  132. {
  133. path: "set",
  134. meta: {
  135. title: "修改密码"
  136. },
  137. component: () => import("@/views/my/children/set")
  138. }
  139. ]
  140. },
  141. {
  142. path: "/pdf",
  143. meta: {
  144. title: "PDF"
  145. },
  146. component: () => import("@/views/pdf/ppd")
  147. },
  148. {
  149. path: "*",
  150. component: () => import("@/components/NotFound")
  151. }
  152. ]
  153. });
  154. // 解决编程式路由往同一地址跳转时会报错的情况
  155. const originalPush = Router.prototype.push;
  156. const originalReplace = Router.prototype.replace;
  157. Router.prototype.push = function push(location, onResolve, onReject) {
  158. if (onResolve || onReject)
  159. return originalPush.call(this, location, onResolve, onReject);
  160. return originalPush.call(this, location).catch(err => err);
  161. };
  162. Router.prototype.replace = function push(location, onResolve, onReject) {
  163. if (onResolve || onReject)
  164. return originalReplace.call(this, location, onResolve, onReject);
  165. return originalReplace.call(this, location).catch(err => err);
  166. };
  167. router.beforeEach((to, from, next) => {
  168. let { title, needLogin } = to.meta;
  169. let { isLogin } = store.state;
  170. document.title = title;
  171. if (needLogin && !isLogin) {
  172. next({
  173. path: "/login"
  174. });
  175. } else {
  176. next();
  177. }
  178. });
  179. export default router;