index.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. path: '/viewTwo/patent/detail',
  155. name: 'patent',
  156. meta: { title: 'e专利详情', isleftarrow: true },
  157. component: () => import('../viewTwo/patent/detail.vue'),
  158. },
  159. // 科技需求
  160. {
  161. path: '/viewTwo/techol/index',
  162. name: 'techol',
  163. meta: { title: '科技需求', isleftarrow: false },
  164. component: () => import('../viewTwo/techol/index.vue'),
  165. },
  166. {
  167. path: '/viewTwo/techol/detail',
  168. name: 'techol',
  169. meta: { title: '科技需求详情', isleftarrow: true },
  170. component: () => import('../viewTwo/techol/detail.vue'),
  171. },
  172. // 专家智库
  173. {
  174. path: '/viewTwo/expert/index',
  175. name: 'expert',
  176. meta: { title: '专家智库', isleftarrow: false },
  177. component: () => import('../viewTwo/expert/index.vue'),
  178. },
  179. {
  180. path: '/viewTwo/expert/detail',
  181. name: 'expert',
  182. meta: { title: '专家智库详情', isleftarrow: true },
  183. component: () => import('../viewTwo/expert/detail.vue'),
  184. },
  185. // 在线服务
  186. {
  187. path: '/viewTwo/service/index',
  188. name: 'service',
  189. meta: { title: '在线服务', isleftarrow: false },
  190. component: () => import('../viewTwo/service/index.vue'),
  191. },
  192. {
  193. path: '/viewTwo/service/detail',
  194. name: 'service',
  195. meta: { title: '在线服务', isleftarrow: true },
  196. component: () => import('../viewTwo/service/detail.vue'),
  197. },
  198. // 调查问卷
  199. {
  200. path: '/viewTwo/question/index',
  201. name: 'question',
  202. meta: { title: '调查问卷', isleftarrow: false },
  203. component: () => import('../viewTwo/question/index.vue'),
  204. },
  205. // 通知通告
  206. {
  207. path: '/viewTwo/notice/index',
  208. name: 'notice',
  209. meta: { title: '通知通告', isleftarrow: false },
  210. component: () => import('../viewTwo/notice/index.vue'),
  211. },
  212. {
  213. path: '/viewTwo/notice/detail',
  214. name: 'notice',
  215. meta: { title: '通知通告详情', isleftarrow: true },
  216. component: () => import('../viewTwo/notice/detail.vue'),
  217. },
  218. // 新闻资讯
  219. {
  220. path: '/viewTwo/news/index',
  221. name: 'news',
  222. meta: { title: '新闻资讯', isleftarrow: false },
  223. component: () => import('../viewTwo/news/index.vue'),
  224. },
  225. // 账号管理
  226. {
  227. path: '/viewTwo/account/index',
  228. name: 'account',
  229. meta: { title: '账号管理', isleftarrow: false },
  230. component: () => import('../viewTwo/account/index.vue'),
  231. },
  232. // 公众号第二版结束
  233. ];
  234. const router = new VueRouter({
  235. mode: 'history',
  236. base: process.env.NODE_ENV === 'development' ? '' : process.env.VUE_APP_ROUTER,
  237. routes,
  238. });
  239. router.beforeEach(async (to, form, next) => {
  240. if (to.name == 'user_index') {
  241. let res = await store.dispatch('login/toGetUser');
  242. if (res && res.uid) {
  243. next();
  244. } else {
  245. let key = sessionStorage.getItem('token');
  246. let user = jwt.decode(key);
  247. if (user && user.uid) {
  248. store.commit('setUser', user, { root: true });
  249. next();
  250. } else {
  251. next({ name: 'login' });
  252. }
  253. }
  254. } else {
  255. let res = await store.dispatch('login/toGetUser');
  256. next();
  257. }
  258. });
  259. const originalPush = VueRouter.prototype.push;
  260. VueRouter.prototype.push = function push(location, onResolve, onReject) {
  261. if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject);
  262. return originalPush.call(this, location).catch(err => err);
  263. };
  264. export default router;