index.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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: "/expire",
  34. component: () => import("@/views/expire/index"),
  35. meta: {
  36. title: "到期"
  37. }
  38. },
  39. {
  40. path: "/index",
  41. component: () => import("@/views/index/index"),
  42. meta: {
  43. title: "工时管家",
  44. keepAlive: true
  45. }
  46. },
  47. {
  48. path: "/view",
  49. meta: {
  50. title: "查看日报"
  51. },
  52. component: () => import("@/views/view/index")
  53. },
  54. {
  55. path: "/calendar",
  56. meta: {
  57. title: "查看日报"
  58. },
  59. component: () => import("@/views/view/calendar")
  60. },
  61. {
  62. path: "/edit",
  63. meta: {
  64. title: "填写日报"
  65. },
  66. component: () => import("@/views/edit/index")
  67. },
  68. {
  69. path: "/weekedit",
  70. meta: {
  71. title: "按周填报"
  72. },
  73. component: () => import("@/views/edit/weekEdit")
  74. },
  75. {
  76. path: "/task",
  77. meta: {
  78. title: "待办任务"
  79. },
  80. component: () => import("@/views/task/index")
  81. },
  82. {
  83. path: "/expense",
  84. meta: {
  85. title: "费用报销"
  86. },
  87. component: () => import("@/views/expense/index")
  88. },
  89. {
  90. path: "/expenseDetails",
  91. name: "expenseDetails",
  92. meta: {
  93. title: "单据编辑"
  94. },
  95. component: () => import("@/views/expense/details")
  96. },
  97. {
  98. path: "/projectInside",
  99. name: "projectInside",
  100. meta: {
  101. title: "项目详情"
  102. },
  103. component: () => import("@/views/project/projectInside")
  104. },
  105. {
  106. path: "/editProject",
  107. meta: {
  108. title: "编辑项目"
  109. },
  110. component: () => import("@/views/project/edit")
  111. },
  112. {
  113. path: "/editask",
  114. name: "editask",
  115. meta: {
  116. title: "编辑任务"
  117. },
  118. component: () => import("@/views/task/editask")
  119. },
  120. {
  121. path: "/search",
  122. meta: {
  123. title: "选择项目"
  124. },
  125. component: () => import("@/views/edit/search")
  126. },
  127. {
  128. path: "/review",
  129. meta: {
  130. title: "审核日报"
  131. },
  132. component: () => import("@/views/review/index")
  133. },
  134. {
  135. path: "/profession_review",
  136. meta: {
  137. title: "专业审核"
  138. },
  139. component: () => import("@/views/review/profession_list")
  140. },
  141. {
  142. path: "/department_review",
  143. meta: {
  144. title: "部门审核"
  145. },
  146. component: () => import("@/views/review/department_list")
  147. },
  148. {
  149. path: "/msg",
  150. meta: {
  151. title: "消息记录"
  152. },
  153. component: () => import("@/views/msg/index")
  154. },
  155. {
  156. path: "/project",
  157. meta: {
  158. title: "项目管理"
  159. },
  160. component: () => import("@/views/project/index")
  161. },
  162. {
  163. path: "/error",
  164. meta: {
  165. title: "错误提示"
  166. },
  167. component: () => import("@/views/error/index")
  168. },
  169. {
  170. path: "/test",
  171. meta: {
  172. title: "测试页面"
  173. },
  174. component: () => import("@/views/test/index")
  175. },
  176. {
  177. path: "/tests",
  178. meta: {
  179. title: "测试页面2"
  180. },
  181. component: () => import("@/views/test/list")
  182. },
  183. // {
  184. // path: "/timetool",
  185. // meta: {
  186. // title: "自动计时"
  187. // },
  188. // component: () => import("@/views/timetool/timetool")
  189. // },
  190. {
  191. path: "/exaLeave",
  192. meta: {
  193. title: "请假审批"
  194. },
  195. component: () => import("@/views/exaLeave/exaLeave")
  196. },
  197. {
  198. path: "/applyLeave",
  199. meta: {
  200. title: "请假申请"
  201. },
  202. component: () => import("@/views/exaLeave/applyLeave")
  203. },
  204. {
  205. path: "/awayOffice",
  206. meta: {
  207. title: "出差申请"
  208. },
  209. component: () => import("@/views/exaLeave/awayOffice")
  210. },
  211. {
  212. path: "/editPerfect",
  213. meta: {
  214. title: "完善工号"
  215. },
  216. component: () => import("@/views/editPerfect/editPerfect")
  217. },
  218. {
  219. path: "/clearStorage",
  220. meta: {
  221. title: "清空存储"
  222. },
  223. component: () => import("@/views/test/clearStorage")
  224. },
  225. {
  226. path: "/my",
  227. component: () => import("@/views/my/index"),
  228. redirect: "/my/center",
  229. children: [
  230. {
  231. path: "center",
  232. meta: {
  233. title: "个人中心"
  234. },
  235. component: () => import("@/views/my/children/center")
  236. },
  237. {
  238. path: "set",
  239. meta: {
  240. title: "修改密码"
  241. },
  242. component: () => import("@/views/my/children/set")
  243. }
  244. ]
  245. },
  246. {
  247. path: "/count",
  248. component: () => import("@/views/count/count"),
  249. meta: {
  250. title: "填报统计"
  251. }
  252. },
  253. {
  254. path: "/cost",
  255. component: () => import("@/views/cost/cost"),
  256. meta: {
  257. title: "成本"
  258. }
  259. },
  260. {
  261. path: "/pdf",
  262. meta: {
  263. title: "PDF"
  264. },
  265. component: () => import("@/views/pdf/ppd")
  266. },
  267. {
  268. path: "*",
  269. component: () => import("@/components/NotFound")
  270. }
  271. ]
  272. });
  273. // 解决编程式路由往同一地址跳转时会报错的情况
  274. const originalPush = Router.prototype.push;
  275. const originalReplace = Router.prototype.replace;
  276. Router.prototype.push = function push(location, onResolve, onReject) {
  277. if (onResolve || onReject)
  278. return originalPush.call(this, location, onResolve, onReject);
  279. return originalPush.call(this, location).catch(err => err);
  280. };
  281. Router.prototype.replace = function push(location, onResolve, onReject) {
  282. if (onResolve || onReject)
  283. return originalReplace.call(this, location, onResolve, onReject);
  284. return originalReplace.call(this, location).catch(err => err);
  285. };
  286. router.beforeEach((to, from, next) => {
  287. let { title, needLogin } = to.meta;
  288. let { isLogin } = store.state;
  289. document.title = title;
  290. if (needLogin && !isLogin) {
  291. next({
  292. path: "/login"
  293. });
  294. } else {
  295. next();
  296. }
  297. });
  298. export default router;