index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import Vue from 'vue';
  2. import VueRouter from 'vue-router';
  3. import store from '@/store/index';
  4. const jwt = require('jsonwebtoken');
  5. Vue.use(VueRouter);
  6. const admin = [
  7. {
  8. path: '/admin/index',
  9. meta: { title: '统计报表', isleftarrow: false },
  10. component: () => import('../views/adminCenter/index.vue'),
  11. },
  12. {
  13. path: '/adminRefute',
  14. meta: { title: '文章辟谣', isleftarrow: false },
  15. component: () => import('../views/adminCenter/adminRefute.vue'),
  16. },
  17. {
  18. path: '/adminRefute/edit',
  19. meta: { title: '文章辟谣', isleftarrow: false },
  20. component: () => import('../views/adminCenter/refute/edit.vue'),
  21. },
  22. {
  23. path: '/adminCommunity',
  24. meta: { title: '社区话题', isleftarrow: false },
  25. component: () => import('../views/adminCenter/adminCommunity.vue'),
  26. },
  27. {
  28. path: '/adminCommunity/edit',
  29. meta: { title: '社区话题', isleftarrow: false },
  30. component: () => import('../views/adminCenter/topic/edit.vue'),
  31. },
  32. {
  33. path: '/adminServe',
  34. meta: { title: '咨询服务', isleftarrow: false },
  35. component: () => import('../views/adminCenter/adminServe.vue'),
  36. },
  37. {
  38. path: '/adminServe/edit',
  39. meta: { title: '咨询服务', isleftarrow: false },
  40. component: () => import('../views/adminCenter/serve/edit.vue'),
  41. },
  42. ];
  43. const routes = [
  44. {
  45. path: '/',
  46. meta: { title: '系统首页', isleftarrow: false },
  47. component: () => import('../views/index.vue'),
  48. },
  49. {
  50. path: '/login',
  51. meta: { title: '管理登陆', isleftarrow: false },
  52. component: () => import('../views/login.vue'),
  53. },
  54. // 文章辟谣
  55. {
  56. path: '/refute/index',
  57. meta: { title: '文章辟谣', isleftarrow: false },
  58. component: () => import('../views/refute/index.vue'),
  59. },
  60. {
  61. path: '/refute/detail',
  62. meta: { title: '文章正文', isleftarrow: false },
  63. component: () => import('../views/refute/detail.vue'),
  64. },
  65. // 社区话题
  66. {
  67. path: '/community/index',
  68. meta: { title: '社区话题', isleftarrow: false },
  69. component: () => import('../views/community/index.vue'),
  70. },
  71. {
  72. path: '/community/detail',
  73. meta: { title: '话题正文', isleftarrow: false },
  74. component: () => import('../views/community/detail.vue'),
  75. },
  76. // 咨询服务
  77. {
  78. path: '/service/index',
  79. meta: { title: '咨询服务', isleftarrow: false },
  80. component: () => import('../views/service/index.vue'),
  81. },
  82. {
  83. path: '/service/detail',
  84. meta: { title: '文章正文', isleftarrow: false },
  85. component: () => import('../views/service/detail.vue'),
  86. },
  87. // 引用管理员
  88. ...admin,
  89. ];
  90. const router = new VueRouter({
  91. mode: 'history',
  92. base: process.env.NODE_ENV === 'development' ? '' : process.env.VUE_APP_ROUTER,
  93. routes,
  94. });
  95. router.beforeEach(async (to, form, next) => {
  96. next();
  97. // if (to.name == 'account_user') {
  98. // let res = await store.dispatch('login/toGetUser');
  99. // if (res && res.uid) {
  100. // next();
  101. // } else {
  102. // let key = sessionStorage.getItem('token');
  103. // let user = jwt.decode(key);
  104. // if (user && user.uid) {
  105. // store.commit('setUser', user, { root: true });
  106. // next();
  107. // } else {
  108. // next({ name: 'login' });
  109. // }
  110. // }
  111. // } else {
  112. // let res = await store.dispatch('login/toGetUser');
  113. // next();
  114. // }
  115. });
  116. const originalPush = VueRouter.prototype.push;
  117. VueRouter.prototype.push = function push(location, onResolve, onReject) {
  118. if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject);
  119. return originalPush.call(this, location).catch(err => err);
  120. };
  121. export default router;