index.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. import Index from '@/layout/index.vue'
  4. import Home from '@/views/home/index.vue'
  5. // import checkPower from '@/utils/check-power.vue'
  6. Vue.use(VueRouter)
  7. const routes = [
  8. {
  9. path: '/',
  10. name: 'Index',
  11. component: Index,
  12. meta: { title: 'HerTube' },
  13. children: [
  14. {
  15. path: '/',
  16. name: 'Index',
  17. component: Home,
  18. meta: { title: 'HerTube' }
  19. },
  20. {
  21. path: '/hot',
  22. name: 'Hot',
  23. component: () => import('@/views/home/status.vue'),
  24. meta: { title: 'HerTube 状态' }
  25. },
  26. {
  27. path: '/subscribe',
  28. name: 'Subscribe',
  29. component: () => import('@/views/home/subscribe.vue'),
  30. meta: { title: 'HerTube 订阅' }
  31. },
  32. {
  33. path: '/history',
  34. name: 'History',
  35. component: () => import('@/views/home/history.vue'),
  36. meta: { title: 'HerTube 播放历史' }
  37. },
  38. {
  39. path: '/playlist',
  40. name: 'Playlist',
  41. component: () => import('@/views/home/playlist.vue'),
  42. meta: { title: 'HerTube 稍后再看' }
  43. },
  44. {
  45. path: '/video/:id',
  46. name: 'Vide',
  47. component: () => import('@/views/video/video.vue'),
  48. meta: { title: '播放' }
  49. },
  50. {
  51. path: '/user/setting',
  52. name: 'UserSetting',
  53. component: () => import('@/views/user/setting.vue'),
  54. meta: {
  55. title: '个人设置',
  56. requireAuth: true
  57. }
  58. },
  59. {
  60. path: '/vip',
  61. name: 'VIP',
  62. component: () => import('@/views/vip/index.vue'),
  63. meta: {
  64. title: 'VIP'
  65. }
  66. },
  67. {
  68. path: '/vip/pay',
  69. name: 'VipPay',
  70. component: () => import('@/views/vip/pay.vue'),
  71. meta: {
  72. title: 'VIP'
  73. }
  74. },
  75. {
  76. path: '/user/:id',
  77. name: 'User',
  78. component: () => import('@/views/user/index.vue'),
  79. meta: { title: '个人主页' }
  80. },
  81. {
  82. path: '/live',
  83. name: 'live',
  84. component: () => import('@/views/live/index.vue'),
  85. meta: { title: '直播' }
  86. }
  87. ]
  88. },
  89. {
  90. path: '/studio',
  91. name: 'Studio',
  92. component: () => import('@/layout/studio.vue'),
  93. meta: { title: '创作中心' },
  94. children: [
  95. {
  96. path: '/studio',
  97. name: 'StudioIndex',
  98. component: () => import('@/views/studio/index.vue'),
  99. meta: {
  100. title: '个人主页',
  101. requireAuth: true
  102. }
  103. },
  104. {
  105. path: '/studio/upload',
  106. name: 'Upload',
  107. component: () => import('@/views/studio/upload.vue'),
  108. meta: {
  109. title: '投稿',
  110. requireAuth: true
  111. }
  112. },
  113. {
  114. path: '/studio/post',
  115. name: 'Post',
  116. component: () => import('@/views/studio/post.vue'),
  117. meta: {
  118. title: '稿件列表',
  119. requireAuth: true
  120. }
  121. },
  122. {
  123. path: '/studio/comment',
  124. name: 'Comment',
  125. component: () => import('@/views/studio/comment.vue'),
  126. meta: {
  127. title: '评论',
  128. requireAuth: true
  129. }
  130. },
  131. {
  132. path: '/studio/admin/invitation',
  133. name: 'invitation',
  134. component: () => import('@/views/admin/invitation.vue'),
  135. meta: {
  136. title: '邀请码',
  137. requireAuth: true
  138. }
  139. },
  140. {
  141. path: '/studio/admin/examine',
  142. name: 'Examine',
  143. component: () => import('@/views/admin/examine.vue'),
  144. meta: {
  145. title: '审核视频',
  146. requireAuth: true
  147. }
  148. },
  149. {
  150. path: '/studio/admin/userlist',
  151. name: 'Examine',
  152. component: () => import('@/views/admin/user-list.vue'),
  153. meta: {
  154. title: '用户列表',
  155. requireAuth: true
  156. }
  157. },
  158. {
  159. path: '/studio/admin/websetting',
  160. name: 'Examine',
  161. component: () => import('@/views/admin/web-setting.vue'),
  162. meta: {
  163. title: '网页设置',
  164. requireAuth: true
  165. }
  166. },
  167. {
  168. path: '/studio/admin/category',
  169. name: 'Examine',
  170. component: () => import('@/views/admin/category.vue'),
  171. meta: {
  172. title: '分区设置',
  173. requireAuth: true
  174. }
  175. }
  176. ]
  177. },
  178. {
  179. path: '/login',
  180. name: 'Login',
  181. component: () => import('@/views/login.vue'),
  182. meta: {
  183. title: '登录'
  184. }
  185. },
  186. {
  187. path: '*',
  188. name: '404',
  189. component: () => import('@/views/404.vue'),
  190. meta: {
  191. title: '404'
  192. }
  193. }
  194. ]
  195. const router = new VueRouter({
  196. mode: 'history',
  197. routes
  198. })
  199. // 路由导航守卫
  200. router.beforeEach((to, from, next) => {
  201. // const token = window.localStorage.getItem('user')
  202. // console.log(this.$store.state.webInfo.name)
  203. // router.app.$options.store
  204. // 获取网页信息
  205. /*
  206. // TODO 网站信息暂时不从后端获取
  207. if (router.app.$options.store.state.webInfo.name == null) {
  208. fetch(`/api/media/web/info`, {
  209. headers: {
  210. 'Content-Type': 'application/json; charset=UTF-8'
  211. },
  212. method: 'GET',
  213. credentials: 'include'
  214. }).then(response => response.json())
  215. .then(json => {
  216. router.app.$options.store.state.webInfo = json.data
  217. })
  218. .catch(e => {
  219. return null
  220. })
  221. }*/
  222. // 路由发生变化修改页面 title
  223. if (to.meta.title) {
  224. document.title = to.meta.title
  225. }
  226. const vuexStore = router.app.$options.store
  227. // router.app.$options.store 就是 this.$store
  228. /* if (checkPower.updateUserRole(vuexStore.state.user.userInfo)) {
  229. vuexStore.state.user.userInfo.role = 'ROLE_USER'
  230. vuexStore.commit('SET_USER_INFO', vuexStore.state.user.userInfo)
  231. }*/
  232. // const date = new Date().getTime()
  233. if (vuexStore.state.user.userInfo != null) {
  234. if (to.path === '/login') {
  235. return next({ path: '/' })
  236. }
  237. return next()
  238. // TODO 不判断用户是否过期
  239. /* if (vuexStore.state.user.userInfo.expireTime > date) {
  240. if (to.path === '/login') {
  241. return next({ path: '/' })
  242. }
  243. return next()
  244. } else {
  245. vuexStore.commit('user/SET_USER_INFO', null)
  246. return next({
  247. path: '/login',
  248. query: { redirect: to.fullPath }
  249. })
  250. }*/
  251. } else {
  252. if (to.meta.requireAuth) {
  253. return next({
  254. path: '/login',
  255. query: { redirect: to.fullPath }
  256. })
  257. } else {
  258. return next()
  259. }
  260. }
  261. })
  262. export default router