index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import Vue from 'vue';
  2. import Router from 'vue-router';
  3. import { Message } from 'element-ui';
  4. const Login = () => import('@/views/Login');
  5. const Home = () => import('@/views/Home');
  6. // 首页
  7. const Main = () => import('@/views/main/main');
  8. // 个人中心
  9. const Customer = () => import('@/views/customer/Customer');
  10. const CustomerRecharge = () => import('@/views/customer/customerRecharge');
  11. const custRecTime = () => import('@/views/customer/custRecTime');
  12. // 系统管理部分
  13. const User = () => import('@/views/sys/user');
  14. // 无车部分
  15. const nocarRec = () => import('@/views/noCar/nocarRec.vue');
  16. const billway = () => import('@/views/noCar/billway.vue');
  17. const nocarInvoice = () => import('@/views/noCar/invoice.vue');
  18. const billwayException = () => import('@/views/noCar/billwayException.vue');
  19. const noCarCalculateInfo = () => import('@/views/noCar/calculateInfo.vue');
  20. const hcInvoice = () => import('@/views/noCar/hcInvoice.vue');
  21. // 自有车部分
  22. const selfcarRec = () => import('@/views/selfCar/selfcarRec.vue');
  23. const selfCarTrade = () => import('@/views/selfCar/selfCarTrade.vue');
  24. const selfInvoice = () => import('@/views/selfCar/invoice.vue');
  25. const selfCarTradeException = () => import('@/views/selfCar/selfCarTradeException.vue');
  26. const SelfCalculateInfo = () => import('@/views/selfCar/calculateInfo.vue');
  27. // 参数管理
  28. const paramMagager = () => import('@/views/manager/paramMagager.vue');
  29. Vue.use(Router);
  30. const router = new Router({
  31. base: '/jkcredit/',
  32. mode: 'history',
  33. routes: [
  34. { name: 'Login', path: '/login', component: Login },
  35. {
  36. name: 'Home',
  37. path: '/',
  38. component: Home,
  39. redirect: '/main',
  40. children: [
  41. // 首页
  42. { name: 'Main', path: '/main', component: Main },
  43. // 客户管理
  44. { name: 'Customer', path: '/customer', component: Customer },
  45. { name: 'customerRecharge', path: '/CustomerRecharge', component: CustomerRecharge },
  46. { name: 'custRecTime', path: '/custRecTime', component: custRecTime },
  47. // 系统管理部分
  48. { name: 'User', path: '/user', component: User },
  49. // 无车部分
  50. { name: 'nocarRec', path: '/nocarRec', component: nocarRec },
  51. { name: 'billway', path: '/billway', component: billway },
  52. { name: 'nocarInvoice', path: '/nocarInvoice', component: nocarInvoice },
  53. { name: 'billwayException', path: '/billwayException', component: billwayException },
  54. { name: 'noCarCalculateInfo', path: '/noCarCalculateInfo', component: noCarCalculateInfo },
  55. { name: 'hcInvoice', path: '/hcInvoice', component: hcInvoice },
  56. // 自有车部分
  57. { name: 'selfcarRec', path: '/selfcarRec', component: selfcarRec },
  58. { name: 'selfInvoice', path: '/selfInvoice', component: selfInvoice },
  59. { name: 'selfCarTrade', path: '/selfCarTrade', component: selfCarTrade },
  60. { name: 'selfCarTradeException', path: '/selfCarTradeException', component: selfCarTradeException },
  61. { name: 'SelfCalculateInfo', path: '/SelfCalculateInfo', component: SelfCalculateInfo },
  62. // 参数管理
  63. { name: 'paramMagager', path: '/paramMagager', component: paramMagager }
  64. ]
  65. }
  66. ]
  67. });
  68. router.beforeEach((to, from, next) => {
  69. // console.log(to);
  70. // console.log(from);
  71. // next();
  72. // 如果是登录的时候不判断token ,不是登录才判断token
  73. // console.log(to);
  74. if (to.name && to.name.toLocaleLowerCase() !== 'login') {
  75. // 判断token
  76. const token = sessionStorage.getItem('token');
  77. if (!token) {
  78. // 没有token,跳转到登录页面
  79. // this.$router.push('/login')
  80. router.push('/login');
  81. // 提示
  82. // this.$message.warning('请先登录');
  83. Message.warning('请先登录');
  84. return;
  85. }
  86. }
  87. next();
  88. });
  89. export default router;