index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. import { Message } from 'element-ui'
  4. Vue.use(VueRouter)
  5. const routes = [
  6. {
  7. path: '/message',
  8. name: 'message',
  9. component: () => import('../views/message/index.vue')
  10. },
  11. {
  12. path: '/forum',
  13. name: 'forum',
  14. component: () => import('../views/forum/index.vue')
  15. },
  16. {
  17. path: '/',
  18. name: 'login',
  19. component: () => import('../views/login.vue')
  20. },
  21. {
  22. path: '/layout',
  23. name: 'layout',
  24. component: () => import('../views/layout/index.vue'),
  25. children: [
  26. {
  27. path: 'tab1',
  28. name: 'tab1',
  29. meta: { myInd: 1 },
  30. component: () => import('../views/tab1/index.vue')
  31. },
  32. {
  33. path: 'tab1Add',
  34. name: 'tab1Add',
  35. meta: { myInd: 1 },
  36. component: () => import('../views/tab1/tab1Add.vue')
  37. },
  38. {
  39. path: 'tab1Add2',
  40. name: 'tab1Add2',
  41. meta: { myInd: 1 },
  42. component: () => import('../views/tab1/tab1Add2.vue')
  43. },
  44. {
  45. path: 'tab1Look',
  46. name: 'tab1Look',
  47. meta: { myInd: 1 },
  48. component: () => import('../views/tab1/tab1Look.vue')
  49. },
  50. {
  51. path: 'tab2',
  52. name: 'tab2',
  53. meta: { myInd: 2 },
  54. component: () => import('../views/tab2/index.vue')
  55. },
  56. {
  57. path: 'tab2Add',
  58. name: 'tab2Add',
  59. meta: { myInd: 2 },
  60. component: () => import('../views/tab2/tab2Add.vue')
  61. },
  62. {
  63. path: 'tab2Look',
  64. name: 'tab2Look',
  65. meta: { myInd: 2 },
  66. component: () => import('../views/tab2/tab2Look.vue')
  67. },
  68. {
  69. path: 'tab3',
  70. name: 'tab3',
  71. meta: { myInd: 3 },
  72. component: () => import('../views/tab3/index.vue')
  73. },
  74. {
  75. path: 'tab3Add',
  76. name: 'tab3Add',
  77. meta: { myInd: 3 },
  78. component: () => import('../views/tab3/tab3Add.vue')
  79. },
  80. {
  81. path: 'tab3Look',
  82. name: 'tab3Look',
  83. meta: { myInd: 3 },
  84. component: () => import('../views/tab3/tab3Look.vue')
  85. },
  86. {
  87. path: 'tab4',
  88. name: 'tab4',
  89. meta: { myInd: 4 },
  90. component: () => import('../views/tab4/index.vue')
  91. },
  92. {
  93. path: 'tab4Add',
  94. name: 'tab4Add',
  95. meta: { myInd: 4 },
  96. component: () => import('../views/tab4/tab4Add.vue')
  97. },
  98. {
  99. path: 'tab4Look',
  100. name: 'tab4Look',
  101. meta: { myInd: 4 },
  102. component: () => import('../views/tab4/tab4Look.vue')
  103. },
  104. {
  105. path: 'tab5',
  106. name: 'tab5',
  107. meta: { myInd: 5 },
  108. component: () => import('../views/tab5/index.vue')
  109. },
  110. {
  111. path: 'tab5Add',
  112. name: 'tab5Add',
  113. meta: { myInd: 5 },
  114. component: () => import('../views/tab5/tab5Add.vue')
  115. },
  116. {
  117. path: 'tab5Look',
  118. name: 'tab5Look',
  119. meta: { myInd: 5 },
  120. component: () => import('../views/tab5/tab5Look.vue')
  121. },
  122. {
  123. path: 'tab6',
  124. name: 'tab6',
  125. meta: { myInd: 6 },
  126. component: () => import('../views/tab6/index.vue')
  127. },
  128. {
  129. path: 'tab6Add',
  130. name: 'tab6Add',
  131. meta: { myInd: 6 },
  132. component: () => import('../views/tab6/tab6Add.vue')
  133. },
  134. {
  135. path: 'tab6Look',
  136. name: 'tab6Look',
  137. meta: { myInd: 6 },
  138. component: () => import('../views/tab6/tab6Look.vue')
  139. },
  140. {
  141. path: 'tab7',
  142. name: 'tab7',
  143. meta: { myInd: 7 },
  144. component: () => import('../views/tab7/index.vue')
  145. },
  146. {
  147. path: 'tab8',
  148. name: 'tab8',
  149. meta: { myInd: 8 },
  150. component: () => import('../views/tab8/index.vue')
  151. },
  152. {
  153. path: 'tab8Look',
  154. name: 'tab8Look',
  155. meta: { myInd: 8 },
  156. component: () => import('../views/tab8/tab8Look.vue')
  157. },
  158. {
  159. path: 'tab9',
  160. name: 'tab9',
  161. meta: { myInd: 9 },
  162. component: () => import('../views/tab9/index.vue')
  163. }
  164. ]
  165. }
  166. ]
  167. const router = new VueRouter({
  168. // mode: 'history',
  169. base: process.env.BASE_URL,
  170. routes
  171. })
  172. router.beforeEach((to, from, next) => {
  173. // 如果是去登录页,不需要验证,直接下一步
  174. if (to.name === 'login' || to.name === 'message' || to.name === 'forum') next()
  175. // 否则要有token值才能下一步,不然就返回登录页
  176. else {
  177. const token = localStorage.getItem('CQLJXU_token')
  178. if (token) next()
  179. else {
  180. Message.warning('登录失效,请重新登录')
  181. next({ name: 'login' })
  182. }
  183. }
  184. })
  185. export default router