index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. // import checkPower from '@/utils/check-power.vue'
  4. Vue.use(VueRouter)
  5. const routes = [
  6. {
  7. path: '/',
  8. name: 'Index',
  9. component: () => import('@/layout/index.vue'),
  10. meta: { title: 'HerTube' },
  11. children: [
  12. {
  13. path: '/',
  14. name: 'Home',
  15. component: () => import('@/views/home/index.vue'),
  16. meta: { title: 'HerTube' }
  17. },
  18. {
  19. path: '/studio',
  20. name: 'Studio',
  21. component: () => import('@/views/studio/index.vue'),
  22. meta: { title: 'Studio' },
  23. children: [
  24. {
  25. path: '/studio',
  26. name: 'Post',
  27. component: () => import('@/views/studio/post.vue'),
  28. meta: {
  29. title: '稿件列表',
  30. requireAuth: true
  31. }
  32. },
  33. {
  34. path: '/studio/upload',
  35. name: 'Upload',
  36. component: () => import('@/views/studio/upload.vue'),
  37. meta: {
  38. title: '投稿',
  39. requireAuth: true
  40. }
  41. },
  42. {
  43. path: '/studio/statistics',
  44. name: 'Statisticss',
  45. component: () => import('@/views/studio/statistics.vue'),
  46. meta: {
  47. title: '数据统计',
  48. requireAuth: true
  49. }
  50. },
  51. {
  52. path: '/studio/comment',
  53. name: 'Comment',
  54. component: () => import('@/views/studio/comment.vue'),
  55. meta: {
  56. title: '评论',
  57. requireAuth: true
  58. }
  59. },
  60. {
  61. path: '/studio/admin/invitation',
  62. name: 'invitation',
  63. component: () => import('@/views/admin/invitation.vue'),
  64. meta: {
  65. title: '邀请码',
  66. requireAuth: true
  67. }
  68. },
  69. {
  70. path: '/studio/admin/examine',
  71. name: 'Examine',
  72. component: () => import('@/views/admin/examine.vue'),
  73. meta: {
  74. title: '审核视频',
  75. requireAuth: true
  76. }
  77. },
  78. {
  79. path: '/studio/admin/userlist',
  80. name: 'Examine',
  81. component: () => import('@/views/admin/user-list.vue'),
  82. meta: {
  83. title: '用户列表',
  84. requireAuth: true
  85. }
  86. },
  87. {
  88. path: '/studio/admin/websetting',
  89. name: 'Examine',
  90. component: () => import('@/views/admin/web-setting.vue'),
  91. meta: {
  92. title: '网页设置',
  93. requireAuth: true
  94. }
  95. },
  96. {
  97. path: '/studio/admin/category',
  98. name: 'Examine',
  99. component: () => import('@/views/admin/category.vue'),
  100. meta: {
  101. title: '分区设置',
  102. requireAuth: true
  103. }
  104. }
  105. ]
  106. },
  107. {
  108. path: '/user',
  109. name: 'User',
  110. component: () => import('@/views/user/index.vue'),
  111. meta: { title: '用户中心' },
  112. children: [
  113. {
  114. path: '/u/:userId',
  115. name: 'UserHome',
  116. component: () => import('@/views/user/home.vue'),
  117. meta: { title: '用户主页' }
  118. },
  119. {
  120. path: '/user',
  121. name: 'UserSetting',
  122. component: () => import('@/views/user/setting.vue'),
  123. meta: {
  124. title: '账户设置',
  125. requireAuth: true
  126. }
  127. },
  128. {
  129. path: '/user/setting',
  130. name: 'UserSetting',
  131. component: () => import('@/views/user/setting.vue'),
  132. meta: {
  133. title: '账户设置',
  134. requireAuth: true
  135. }
  136. },
  137. {
  138. path: '/user/favlist',
  139. name: 'UserFavlist',
  140. component: () => import('@/views/user/favlist.vue'),
  141. meta: { title: '收藏列表' }
  142. },
  143. {
  144. path: '/user/playlist',
  145. name: 'UserPlaylist',
  146. component: () => import('@/views/user/playlist.vue'),
  147. meta: { title: '稍后再看' }
  148. },
  149. {
  150. path: '/user/hislist',
  151. name: 'UserHislist',
  152. component: () => import('@/views/user/hislist.vue'),
  153. meta: { title: '历史记录' }
  154. },
  155. {
  156. path: '/user/follow',
  157. name: 'UserFollow',
  158. component: () => import('@/views/user/follow.vue'),
  159. meta: { title: '关注管理' }
  160. },
  161. {
  162. path: '/user/vip',
  163. name: 'UserVip',
  164. component: () => import('@/views/user/vip.vue'),
  165. meta: { title: '小会员' }
  166. },
  167. {
  168. path: '/user/loginhistory',
  169. name: 'LoginHistory',
  170. component: () => import('@/views/user/LoginHistory.vue'),
  171. meta: { title: '登录历史' }
  172. }
  173. /* {
  174. path: '/user/studio',
  175. name: 'StudioIndex',
  176. component: () => import('@/views/studio/index.vue'),
  177. meta: {
  178. title: '个人中心',
  179. requireAuth: true
  180. }
  181. },
  182. {
  183. path: '/user/upload',
  184. name: 'Upload',
  185. component: () => import('@/views/studio/upload.vue'),
  186. meta: {
  187. title: '投稿',
  188. requireAuth: true
  189. }
  190. },
  191. {
  192. path: '/user/post',
  193. name: 'Post',
  194. component: () => import('@/views/studio/post.vue'),
  195. meta: {
  196. title: '稿件列表',
  197. requireAuth: true
  198. }
  199. },
  200. {
  201. path: '/user/comment',
  202. name: 'Comment',
  203. component: () => import('@/views/studio/comment.vue'),
  204. meta: {
  205. title: '评论',
  206. requireAuth: true
  207. }
  208. },
  209. {
  210. path: '/user/admin/invitation',
  211. name: 'invitation',
  212. component: () => import('@/views/admin/invitation.vue'),
  213. meta: {
  214. title: '邀请码',
  215. requireAuth: true
  216. }
  217. },
  218. {
  219. path: '/user/admin/examine',
  220. name: 'Examine',
  221. component: () => import('@/views/admin/examine.vue'),
  222. meta: {
  223. title: '审核视频',
  224. requireAuth: true
  225. }
  226. },
  227. {
  228. path: '/user/admin/userlist',
  229. name: 'Examine',
  230. component: () => import('@/views/admin/user-list.vue'),
  231. meta: {
  232. title: '用户列表',
  233. requireAuth: true
  234. }
  235. },
  236. {
  237. path: '/user/admin/websetting',
  238. name: 'Examine',
  239. component: () => import('@/views/admin/web-setting.vue'),
  240. meta: {
  241. title: '网页设置',
  242. requireAuth: true
  243. }
  244. },
  245. {
  246. path: '/user/admin/category',
  247. name: 'Examine',
  248. component: () => import('@/views/admin/category.vue'),
  249. meta: {
  250. title: '分区设置',
  251. requireAuth: true
  252. }
  253. }*/
  254. ]
  255. },
  256. {
  257. path: '/message',
  258. name: 'Message',
  259. component: () => import('@/views/message/index.vue'),
  260. meta: { title: 'Message' },
  261. children: [
  262. {
  263. path: '/message',
  264. name: 'Message',
  265. component: () => import('@/views/user/index.vue'),
  266. meta: { title: '消息主页' }
  267. }
  268. ]
  269. },
  270. {
  271. path: '/live',
  272. name: 'Live',
  273. component: () => import('@/views/home/live.vue'),
  274. meta: { title: 'HerTube 直播' }
  275. },
  276. {
  277. path: '/channel',
  278. name: 'Channel',
  279. component: () => import('@/views/home/channel.vue'),
  280. meta: { title: 'HerTube 分区' }
  281. },
  282. {
  283. path: '/mblog',
  284. name: 'Mblog',
  285. component: () => import('@/views/home/mblog.vue'),
  286. meta: { title: 'HerTube 微博' }
  287. },
  288. {
  289. path: '/zhihu',
  290. name: 'Zhihu',
  291. component: () => import('@/views/home/zhihu.vue'),
  292. meta: { title: 'HerTube 知乎' }
  293. },
  294. {
  295. path: '/playlist',
  296. name: 'Playlist',
  297. component: () => import('@/views/home/playlist.vue'),
  298. meta: { title: 'HerTube 稍后再看' }
  299. },
  300. {
  301. path: '/search/result',
  302. name: 'SearchResult',
  303. component: () => import('@/views/home/search-result.vue'),
  304. meta: { title: 'HerTube 搜索结果' }
  305. },
  306. {
  307. path: '/video/:id',
  308. name: 'Vide',
  309. component: () => import('@/views/video/video.vue'),
  310. meta: { title: '播放' }
  311. },
  312. {
  313. path: '/vip',
  314. name: 'VIP',
  315. component: () => import('@/views/vip/index.vue'),
  316. meta: {
  317. title: 'VIP'
  318. }
  319. },
  320. {
  321. path: '/vip/pay',
  322. name: 'VipPay',
  323. component: () => import('@/views/vip/pay.vue'),
  324. meta: {
  325. title: 'VIP'
  326. }
  327. },
  328. {
  329. path: '/live',
  330. name: 'live',
  331. component: () => import('@/views/live/index.vue'),
  332. meta: { title: '直播1' }
  333. }
  334. ]
  335. },
  336. {
  337. path: '/login',
  338. name: 'Login',
  339. component: () => import('@/views/login.vue'),
  340. meta: {
  341. title: '登录'
  342. }
  343. },
  344. {
  345. path: '*',
  346. name: '404',
  347. component: () => import('@/views/404.vue'),
  348. meta: {
  349. title: '404'
  350. }
  351. }
  352. ]
  353. const router = new VueRouter({
  354. mode: 'history',
  355. routes
  356. })
  357. // 路由导航守卫
  358. router.beforeEach((to, from, next) => {
  359. // const token = window.localStorage.getItem('user')
  360. // console.log(this.$store.state.webInfo.name)
  361. // router.app.$options.store
  362. // 获取网页信息
  363. /*
  364. // TODO 网站信息暂时不从后端获取
  365. if (router.app.$options.store.state.webInfo.name == null) {
  366. fetch(`/api/media/web/info`, {
  367. headers: {
  368. 'Content-Type': 'application/json; charset=UTF-8'
  369. },
  370. method: 'GET',
  371. credentials: 'include'
  372. }).then(response => response.json())
  373. .then(json => {
  374. router.app.$options.store.state.webInfo = json.data
  375. })
  376. .catch(e => {
  377. return null
  378. })
  379. }*/
  380. // 路由发生变化修改页面 title
  381. if (to.meta.title) {
  382. document.title = to.meta.title
  383. }
  384. const vuexStore = router.app.$options.store
  385. // router.app.$options.store 就是 this.$store
  386. /* if (checkPower.updateUserRole(vuexStore.state.user.userInfo)) {
  387. vuexStore.state.user.userInfo.role = 'ROLE_USER'
  388. vuexStore.commit('SET_USER_INFO', vuexStore.state.user.userInfo)
  389. }*/
  390. // const date = new Date().getTime()
  391. if (vuexStore.state.user.userInfo != null) {
  392. if (to.path === '/login') {
  393. return next({ path: '/' })
  394. }
  395. return next()
  396. // TODO 不判断用户是否过期
  397. /* if (vuexStore.state.user.userInfo.expireTime > date) {
  398. if (to.path === '/login') {
  399. return next({ path: '/' })
  400. }
  401. return next()
  402. } else {
  403. vuexStore.commit('user/SET_USER_INFO', null)
  404. return next({
  405. path: '/login',
  406. query: { redirect: to.fullPath }
  407. })
  408. }*/
  409. } else {
  410. if (to.meta.requireAuth) {
  411. return next({
  412. path: '/login',
  413. query: { redirect: to.fullPath }
  414. })
  415. } else {
  416. return next()
  417. }
  418. }
  419. })
  420. export default router