index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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: "/audit",
  13. meta: {
  14. title: "导入日报审核"
  15. },
  16. component: () => import("@/views/audit/audit")
  17. },
  18. {
  19. path: "/login",
  20. component: () => import("@/views/login/index"),
  21. meta: {
  22. title: "登陆"
  23. }
  24. },
  25. {
  26. path: "/register",
  27. component: () => import("@/views/register/index"),
  28. meta: {
  29. title: "注册"
  30. }
  31. },
  32. {
  33. path: "/index",
  34. component: () => import("@/views/index/index"),
  35. meta: {
  36. title: "工时管家",
  37. keepAlive: true
  38. }
  39. },
  40. {
  41. path: "/view",
  42. meta: {
  43. title: "查看日报"
  44. },
  45. component: () => import("@/views/view/index")
  46. },
  47. {
  48. path: "/calendar",
  49. meta: {
  50. title: "查看日报"
  51. },
  52. component: () => import("@/views/view/calendar")
  53. },
  54. {
  55. path: "/edit",
  56. meta: {
  57. title: "填写日报"
  58. },
  59. component: () => import("@/views/edit/index")
  60. },
  61. {
  62. path: "/weekedit",
  63. meta: {
  64. title: "按周填报"
  65. },
  66. component: () => import("@/views/edit/weekEdit")
  67. },
  68. {
  69. path: "/search",
  70. meta: {
  71. title: "选择项目"
  72. },
  73. component: () => import("@/views/edit/search")
  74. },
  75. {
  76. path: "/review",
  77. meta: {
  78. title: "审核日报"
  79. },
  80. component: () => import("@/views/review/index")
  81. },
  82. {
  83. path: "/profession_review",
  84. meta: {
  85. title: "专业审核"
  86. },
  87. component: () => import("@/views/review/profession_list")
  88. },
  89. {
  90. path: "/department_review",
  91. meta: {
  92. title: "部门审核"
  93. },
  94. component: () => import("@/views/review/department_list")
  95. },
  96. {
  97. path: "/msg",
  98. meta: {
  99. title: "消息记录"
  100. },
  101. component: () => import("@/views/msg/index")
  102. },
  103. {
  104. path: "/project",
  105. meta: {
  106. title: "项目管理"
  107. },
  108. component: () => import("@/views/project/index")
  109. },
  110. {
  111. path: "/error",
  112. meta: {
  113. title: "错误提示"
  114. },
  115. component: () => import("@/views/error/index")
  116. },
  117. {
  118. path: "/test",
  119. meta: {
  120. title: "测试页面"
  121. },
  122. component: () => import("@/views/test/index")
  123. },
  124. {
  125. path: "/tests",
  126. meta: {
  127. title: "测试页面2"
  128. },
  129. component: () => import("@/views/test/list")
  130. },
  131. // {
  132. // path: "/timetool",
  133. // meta: {
  134. // title: "自动计时"
  135. // },
  136. // component: () => import("@/views/timetool/timetool")
  137. // },
  138. {
  139. path: "/exaLeave",
  140. meta: {
  141. title: "请假审批"
  142. },
  143. component: () => import("@/views/exaLeave/exaLeave")
  144. },
  145. {
  146. path: "/my",
  147. component: () => import("@/views/my/index"),
  148. redirect: "/my/center",
  149. children: [
  150. {
  151. path: "center",
  152. meta: {
  153. title: "个人中心"
  154. },
  155. component: () => import("@/views/my/children/center")
  156. },
  157. {
  158. path: "set",
  159. meta: {
  160. title: "修改密码"
  161. },
  162. component: () => import("@/views/my/children/set")
  163. }
  164. ]
  165. },
  166. {
  167. path: "*",
  168. component: () => import("@/components/NotFound")
  169. }
  170. ]
  171. });
  172. // 解决编程式路由往同一地址跳转时会报错的情况
  173. const originalPush = Router.prototype.push;
  174. const originalReplace = Router.prototype.replace;
  175. Router.prototype.push = function push(location, onResolve, onReject) {
  176. if (onResolve || onReject)
  177. return originalPush.call(this, location, onResolve, onReject);
  178. return originalPush.call(this, location).catch(err => err);
  179. };
  180. Router.prototype.replace = function push(location, onResolve, onReject) {
  181. if (onResolve || onReject)
  182. return originalReplace.call(this, location, onResolve, onReject);
  183. return originalReplace.call(this, location).catch(err => err);
  184. };
  185. router.beforeEach((to, from, next) => {
  186. let { title, needLogin } = to.meta;
  187. let { isLogin } = store.state;
  188. document.title = title;
  189. if (needLogin && !isLogin) {
  190. next({
  191. path: "/login"
  192. });
  193. } else {
  194. next();
  195. }
  196. });
  197. export default router;