index.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 routes = [
  7. // 公众号第一版开始
  8. // 直播大厅
  9. {
  10. path: '/live/index',
  11. name: 'live_index',
  12. meta: { title: '直播大厅', isleftarrow: false },
  13. component: () => import('../views/live/index.vue'),
  14. },
  15. // 直播大厅-在线展会详情
  16. {
  17. path: '/live/liveDetail',
  18. name: 'liveDetail',
  19. meta: { title: '展会详情', isleftarrow: true },
  20. component: () => import('../views/live/liveDetail.vue'),
  21. },
  22. // 直播大厅-科技频道详情
  23. {
  24. path: '/live/channelDetail',
  25. name: 'channelDetail',
  26. meta: { title: '科技频道', isleftarrow: true },
  27. component: () => import('../views/live/channelDetail.vue'),
  28. },
  29. // 直播大厅-嘉宾访谈详情
  30. {
  31. path: '/live/interviewDeatil',
  32. name: 'interviewDeatil',
  33. meta: { title: '嘉宾访谈详情', isleftarrow: true },
  34. component: () => import('../views/live/interviewDeatil.vue'),
  35. },
  36. // 直播大厅-项目路演详情
  37. {
  38. path: '/live/roadshowDetail',
  39. name: 'roadshowDetail',
  40. meta: { title: '项目路演详情', isleftarrow: true },
  41. component: () => import('../views/live/roadshowDetail.vue'),
  42. },
  43. // 科技超市
  44. {
  45. path: '/market/index',
  46. name: 'market_index',
  47. meta: { title: '科技超市', isleftarrow: false },
  48. component: () => import('../views/market/index.vue'),
  49. },
  50. // 科技超市详情
  51. {
  52. path: '/market/detail',
  53. name: 'detail',
  54. meta: { title: '科技超市详情', isleftarrow: true },
  55. component: () => import('../views/market/detail.vue'),
  56. },
  57. // 个人中心
  58. {
  59. path: '/user/index',
  60. name: 'user',
  61. meta: { title: '个人中心', isleftarrow: false },
  62. component: () => import('../views/user/index.vue'),
  63. },
  64. // 公众号第一版结束
  65. // 公众号第二版开始 viewTwo
  66. // 在线展会
  67. {
  68. path: '/viewTwo/live/index',
  69. name: 'live',
  70. meta: { title: '在线展会', isleftarrow: true },
  71. component: () => import('../viewTwo/live/index.vue'),
  72. },
  73. // 在线展会详情
  74. {
  75. path: '/viewTwo/live/detail',
  76. name: 'live',
  77. meta: { title: '在线展会详情', isleftarrow: true },
  78. component: () => import('../viewTwo/live/detail.vue'),
  79. },
  80. // 人才对接详情
  81. {
  82. path: '/viewTwo/live/personalDetail',
  83. name: 'live',
  84. meta: { title: '人才对接详情', isleftarrow: true },
  85. component: () => import('../viewTwo/live/personalDetail.vue'),
  86. },
  87. // 专家培训详情
  88. {
  89. path: '/viewTwo/live/exportsDetail',
  90. name: 'live',
  91. meta: { title: '专家培训详情', isleftarrow: true },
  92. component: () => import('../viewTwo/live/exportsDetail.vue'),
  93. },
  94. // 科技频道
  95. {
  96. path: '/viewTwo/channel/index',
  97. name: 'channel',
  98. meta: { title: '科技频道', isleftarrow: false },
  99. component: () => import('../viewTwo/channel/index.vue'),
  100. },
  101. {
  102. path: '/viewTwo/channel/detail',
  103. name: 'detail',
  104. meta: { title: '科技频道详情', isleftarrow: true },
  105. component: () => import('../viewTwo/channel/detail.vue'),
  106. },
  107. // 培训访谈
  108. {
  109. path: '/viewTwo/interview/index',
  110. name: 'interview',
  111. meta: { title: '培训访谈', isleftarrow: false },
  112. component: () => import('../viewTwo/interview/index.vue'),
  113. },
  114. {
  115. path: '/viewTwo/interview/detail',
  116. name: 'detail',
  117. meta: { title: '培训访谈详情', isleftarrow: true },
  118. component: () => import('../viewTwo/interview/detail.vue'),
  119. },
  120. // 项目路演
  121. {
  122. path: '/viewTwo/roadshow/index',
  123. name: 'roadshow',
  124. meta: { title: '项目路演', isleftarrow: false },
  125. component: () => import('../viewTwo/roadshow/index.vue'),
  126. },
  127. {
  128. path: '/viewTwo/roadshow/detail',
  129. name: 'roadshow',
  130. meta: { title: '项目路演详情', isleftarrow: true },
  131. component: () => import('../viewTwo/roadshow/detail.vue'),
  132. },
  133. // 技术成果
  134. {
  135. path: '/viewTwo/achieve/index',
  136. name: 'achieve',
  137. meta: { title: '技术成果', isleftarrow: false },
  138. component: () => import('../viewTwo/achieve/index.vue'),
  139. },
  140. {
  141. path: '/viewTwo/achieve/detail',
  142. name: 'achieve',
  143. meta: { title: '技术成果详情', isleftarrow: true },
  144. component: () => import('../viewTwo/achieve/detail.vue'),
  145. },
  146. // e专利
  147. {
  148. path: '/viewTwo/patent/index',
  149. name: 'patent',
  150. meta: { title: 'e专利', isleftarrow: false },
  151. component: () => import('../viewTwo/patent/index.vue'),
  152. },
  153. // 科技需求
  154. {
  155. path: '/viewTwo/techol/index',
  156. name: 'techol',
  157. meta: { title: '科技需求', isleftarrow: false },
  158. component: () => import('../viewTwo/techol/index.vue'),
  159. },
  160. // 专家智库
  161. {
  162. path: '/viewTwo/expert/index',
  163. name: 'expert',
  164. meta: { title: '专家智库', isleftarrow: false },
  165. component: () => import('../viewTwo/expert/index.vue'),
  166. },
  167. // 在线服务
  168. {
  169. path: '/viewTwo/service/index',
  170. name: 'service',
  171. meta: { title: '在线服务', isleftarrow: false },
  172. component: () => import('../viewTwo/service/index.vue'),
  173. },
  174. // 调查问卷
  175. {
  176. path: '/viewTwo/question/index',
  177. name: 'question',
  178. meta: { title: '调查问卷', isleftarrow: false },
  179. component: () => import('../viewTwo/question/index.vue'),
  180. },
  181. // 通知通告
  182. {
  183. path: '/viewTwo/notice/index',
  184. name: 'notice',
  185. meta: { title: '通知通告', isleftarrow: false },
  186. component: () => import('../viewTwo/notice/index.vue'),
  187. },
  188. // 新闻资讯
  189. {
  190. path: '/viewTwo/news/index',
  191. name: 'news',
  192. meta: { title: '新闻资讯', isleftarrow: false },
  193. component: () => import('../viewTwo/news/index.vue'),
  194. },
  195. // 账号管理
  196. {
  197. path: '/viewTwo/account/index',
  198. name: 'account',
  199. meta: { title: '账号管理', isleftarrow: false },
  200. component: () => import('../viewTwo/account/index.vue'),
  201. },
  202. // 公众号第二版结束
  203. ];
  204. const router = new VueRouter({
  205. mode: 'history',
  206. base: process.env.NODE_ENV === 'development' ? '' : process.env.VUE_APP_ROUTER,
  207. routes,
  208. });
  209. router.beforeEach(async (to, form, next) => {
  210. if (to.name == 'user_index') {
  211. let res = await store.dispatch('login/toGetUser');
  212. if (res && res.uid) {
  213. next();
  214. } else {
  215. let key = sessionStorage.getItem('token');
  216. let user = jwt.decode(key);
  217. if (user && user.uid) {
  218. store.commit('setUser', user, { root: true });
  219. next();
  220. } else {
  221. next({ name: 'login' });
  222. }
  223. }
  224. } else {
  225. let res = await store.dispatch('login/toGetUser');
  226. next();
  227. }
  228. });
  229. const originalPush = VueRouter.prototype.push;
  230. VueRouter.prototype.push = function push(location, onResolve, onReject) {
  231. if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject);
  232. return originalPush.call(this, location).catch(err => err);
  233. };
  234. export default router;