index.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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: 'bili' },
  11. children: [
  12. {
  13. path: '/',
  14. name: 'Home',
  15. component: () => import('@/views/home/index.vue'),
  16. meta: { title: 'bili' }
  17. },
  18. /* 用户稿件模块 */
  19. {
  20. path: '/studio',
  21. name: 'Studio',
  22. component: () => import('@/views/studio/index.vue'),
  23. meta: { title: 'Studio' },
  24. children: [
  25. {
  26. path: '/studio',
  27. name: 'Post',
  28. component: () => import('@/views/studio/post.vue'),
  29. meta: {
  30. title: '稿件列表',
  31. requireAuth: true
  32. }
  33. },
  34. {
  35. path: '/studio/upload',
  36. name: 'Upload',
  37. component: () => import('@/views/studio/upload.vue'),
  38. meta: {
  39. title: '投稿',
  40. requireAuth: true
  41. }
  42. },
  43. {
  44. path: '/studio/statistics',
  45. name: 'Statisticss',
  46. component: () => import('@/views/studio/statistics.vue'),
  47. meta: {
  48. title: '数据统计',
  49. requireAuth: true
  50. }
  51. },
  52. {
  53. path: '/studio/comment',
  54. name: 'Comment',
  55. component: () => import('@/views/studio/comment.vue'),
  56. meta: {
  57. title: '评论',
  58. requireAuth: true
  59. }
  60. },
  61. {
  62. path: '/studio/admin/invitation',
  63. name: 'invitation',
  64. component: () => import('@/views/admin/invitation.vue'),
  65. meta: {
  66. title: '邀请码',
  67. requireAuth: true
  68. }
  69. },
  70. {
  71. path: '/studio/admin/examine',
  72. name: 'Examine',
  73. component: () => import('@/views/admin/examine.vue'),
  74. meta: {
  75. title: '审核视频',
  76. requireAuth: true
  77. }
  78. },
  79. {
  80. path: '/studio/admin/userlist',
  81. name: 'UserList',
  82. component: () => import('@/views/admin/user-list.vue'),
  83. meta: {
  84. title: '用户列表',
  85. requireAuth: true
  86. }
  87. },
  88. {
  89. path: '/studio/admin/websetting',
  90. name: 'WebSetting',
  91. component: () => import('@/views/admin/web-setting.vue'),
  92. meta: {
  93. title: '网页设置',
  94. requireAuth: true
  95. }
  96. },
  97. {
  98. path: '/studio/admin/category',
  99. name: 'Category',
  100. component: () => import('@/views/admin/category.vue'),
  101. meta: {
  102. title: '分区设置',
  103. requireAuth: true
  104. }
  105. }
  106. ]
  107. },
  108. /* 用户状态模块 */
  109. {
  110. path: '/u/:userId',
  111. name: 'UserHome',
  112. component: () => import('@/views/user/user-home.vue'),
  113. meta: { title: '用户主页' }
  114. },
  115. {
  116. path: '/u/:userId/post',
  117. name: 'UserPost',
  118. component: () => import('@/views/user/user-post.vue'),
  119. meta: {
  120. title: '用户投稿'
  121. },
  122. children: [
  123. {
  124. path: '/u/:userId/video',
  125. name: 'UserVideoPost',
  126. component: () => import('@/views/user/user-video.vue'),
  127. meta: { title: '视频投稿' }
  128. },
  129. {
  130. path: '/u/:userId/audio',
  131. name: 'UserAudioPost',
  132. component: () => import('@/views/user/user-audio.vue'),
  133. meta: { title: '音频投稿' }
  134. },
  135. {
  136. path: '/u/:userId/article',
  137. name: 'UserArticlePost',
  138. component: () => import('@/views/user/user-article.vue'),
  139. meta: { title: '专栏投稿' }
  140. },
  141. {
  142. path: '/u/:userId/album',
  143. name: 'UserAlbumPost',
  144. component: () => import('@/views/user/user-album.vue'),
  145. meta: { title: '用户相薄' }
  146. }
  147. ]
  148. },
  149. {
  150. path: '/u/:userId/status',
  151. name: 'UserStatus',
  152. component: () => import('@/views/user/user-status.vue'),
  153. meta: {
  154. title: '用户状态'
  155. }
  156. },
  157. /* 用户帐号模块 */
  158. {
  159. path: '/user',
  160. name: 'UserCenter',
  161. component: () => import('@/views/user/userindex.vue'),
  162. meta: {
  163. title: '个人中心',
  164. requireAuth: true
  165. },
  166. children: [
  167. {
  168. path: '/user/home',
  169. name: 'MyHome',
  170. component: () => import('@/views/user/home.vue'),
  171. meta: {
  172. title: '个人中心',
  173. requireAuth: true
  174. }
  175. },
  176. {
  177. path: '/user/account',
  178. name: 'UserAccount',
  179. component: () => import('@/views/user/account.vue'),
  180. meta: {
  181. title: '账户设置',
  182. requireAuth: true
  183. }
  184. },
  185. {
  186. path: '/user/favlist',
  187. name: 'UserFavlist',
  188. component: () => import('@/views/user/favlist.vue'),
  189. meta: { title: '收藏列表',
  190. requireAuth: true }
  191. },
  192. {
  193. path: '/user/hislist',
  194. name: 'UserHislist',
  195. component: () => import('@/views/user/hislist.vue'),
  196. meta: { title: '历史记录',
  197. requireAuth: true }
  198. },
  199. {
  200. path: '/user/follow',
  201. name: 'UserFollow',
  202. component: () => import('@/views/user/follow.vue'),
  203. meta: { title: '关注管理',
  204. requireAuth: true }
  205. },
  206. {
  207. path: '/user/vip',
  208. name: 'UserVip',
  209. component: () => import('@/views/user/vip.vue'),
  210. meta: { title: '小会员',
  211. requireAuth: true }
  212. },
  213. {
  214. path: '/user/loginhistory',
  215. name: 'LoginHistory',
  216. component: () => import('@/views/user/LoginHistory.vue'),
  217. meta: { title: '登录历史',
  218. requireAuth: true }
  219. }
  220. ]
  221. },
  222. /* VIP 用户模块 */
  223. {
  224. path: '/vip',
  225. name: 'VipCenter',
  226. component: () => import('@/views/vip/index.vue'),
  227. meta: {
  228. title: 'VIP 中心',
  229. requireAuth: true
  230. },
  231. children: [
  232. {
  233. path: '/vip/plan',
  234. name: 'VipPlan',
  235. component: () => import('@/views/vip/plan.vue'),
  236. meta: {
  237. title: 'VIP 套餐', requireAuth: true
  238. }
  239. },
  240. {
  241. path: '/vip/order',
  242. name: 'VipOrder',
  243. component: () => import('@/views/vip/order.vue'),
  244. meta: {
  245. title: 'VIP 订单', requireAuth: true
  246. }
  247. },
  248. {
  249. path: '/vip/pay',
  250. name: 'VipPay',
  251. component: () => import('@/views/vip/pay.vue'),
  252. meta: {
  253. title: 'VIP 支付', requireAuth: true
  254. }
  255. }
  256. ]
  257. },
  258. /* 消息模块 */
  259. {
  260. path: '/message',
  261. name: 'Message',
  262. component: () => import('@/views/message/index.vue'),
  263. meta: { title: 'Message' },
  264. children: [
  265. {
  266. path: '/message',
  267. name: 'MessageHome',
  268. component: () => import('@/views/message/home.vue'),
  269. meta: { title: '消息主页' }
  270. },
  271. {
  272. path: '/message/setting',
  273. name: 'MessageSetting',
  274. component: () => import('@/views/message/setting.vue'),
  275. meta: { title: '消息设置' }
  276. }
  277. ]
  278. },
  279. /* 状态模块 */
  280. {
  281. path: '/mblog',
  282. name: 'Mblog',
  283. component: () => import('@/views/mblog/mblog.vue'),
  284. meta: { title: 'bili 状态' }
  285. },
  286. /* {
  287. path: '/zhihu',
  288. name: 'Zhihu',
  289. component: () => import('@/views/home/zhihu.vue'),
  290. meta: { title: 'bili 知乎' }
  291. },
  292. {
  293. path: '/t66y',
  294. name: 'T66y',
  295. component: () => import('@/views/home/t66y.vue'),
  296. meta: { title: 'bili 草榴' }
  297. },
  298. {
  299. path: '/t66y/page',
  300. name: 'T66yPage',
  301. component: () => import('@/views/home/t66ypage.vue'),
  302. meta: { title: 'bili 草榴页面' }
  303. },*/
  304. {
  305. path: '/search/result',
  306. name: 'SearchResult',
  307. component: () => import('@/views/home/search-result.vue'),
  308. meta: { title: 'bili 搜索结果' }
  309. },
  310. {
  311. path: '/tag/result',
  312. name: 'TagResult',
  313. component: () => import('@/views/home/tag-result.vue'),
  314. meta: { title: 'bili 视频标签' }
  315. },
  316. /* 视频模块 */
  317. {
  318. path: '/video',
  319. name: 'Video',
  320. component: () => import('@/views/video/index.vue'),
  321. meta: { title: '视频' },
  322. children: [
  323. ]
  324. },
  325. {
  326. path: '/video/:id',
  327. name: 'VideoPage',
  328. component: () => import('@/views/video/video.vue'),
  329. meta: { title: '视频页面' }
  330. },
  331. /* 音频模块 */
  332. {
  333. path: '/audio',
  334. name: 'Audio',
  335. component: () => import('@/views/audio/index.vue'),
  336. meta: { title: '音频' },
  337. children: [
  338. ]
  339. },
  340. {
  341. path: '/audio/:id',
  342. name: 'AudioPage',
  343. component: () => import('@/views/audio/audio.vue'),
  344. meta: { title: '音频页面' }
  345. },
  346. /* 图片模块 */
  347. {
  348. path: '/image',
  349. name: 'Image',
  350. component: () => import('@/views/image/index.vue'),
  351. meta: { title: '图片' },
  352. children: [
  353. {
  354. path: '/image/:id',
  355. name: 'ImagePage',
  356. component: () => import('@/views/image/index.vue'),
  357. meta: { title: '图片主页' }
  358. }
  359. ]
  360. },
  361. /* 文章模块 */
  362. {
  363. path: '/article',
  364. name: 'Article',
  365. component: () => import('@/views/article/index.vue'),
  366. meta: { title: '文章' },
  367. children: [
  368. ]
  369. },
  370. {
  371. path: '/article/:id',
  372. name: 'ArticlePage',
  373. component: () => import('@/views/article/zhihu.vue'),
  374. // component: () => import('@/views/article/article.vue'),
  375. meta: { title: '文章主页' }
  376. },
  377. /* 直播模块 */
  378. {
  379. path: '/live',
  380. name: 'live',
  381. component: () => import('@/views/live/index.vue'),
  382. meta: { title: '直播1' }
  383. },
  384. {
  385. path: '/live',
  386. name: 'Live',
  387. component: () => import('@/views/home/live.vue'),
  388. meta: { title: 'bili 直播' }
  389. }
  390. ]
  391. },
  392. {
  393. path: '/login',
  394. name: 'Login',
  395. component: () => import('@/views/login.vue'),
  396. meta: {
  397. title: '登录'
  398. }
  399. },
  400. {
  401. path: '*',
  402. name: '404',
  403. component: () => import('@/views/404.vue'),
  404. meta: {
  405. title: '404'
  406. }
  407. }
  408. /*
  409. {
  410. path: '/user',
  411. name: 'User',
  412. component: () => import('@/views/user/index.vue')
  413. },
  414. {
  415. path: '/user/studio',
  416. name: 'StudioIndex',
  417. component: () => import('@/views/studio/index.vue'),
  418. meta: {
  419. title: '个人中心',
  420. requireAuth: true
  421. }
  422. },
  423. {
  424. path: '/user/upload',
  425. name: 'Upload',
  426. component: () => import('@/views/studio/upload.vue'),
  427. meta: {
  428. title: '投稿',
  429. requireAuth: true
  430. }
  431. },
  432. {
  433. path: '/user/post',
  434. name: 'Post',
  435. component: () => import('@/views/studio/post.vue'),
  436. meta: {
  437. title: '稿件列表',
  438. requireAuth: true
  439. }
  440. },
  441. {
  442. path: '/user/comment',
  443. name: 'Comment',
  444. component: () => import('@/views/studio/comment.vue'),
  445. meta: {
  446. title: '评论',
  447. requireAuth: true
  448. }
  449. },
  450. {
  451. path: '/user/admin/invitation',
  452. name: 'invitation',
  453. component: () => import('@/views/admin/invitation.vue'),
  454. meta: {
  455. title: '邀请码',
  456. requireAuth: true
  457. }
  458. },
  459. {
  460. path: '/user/admin/examine',
  461. name: 'Examine',
  462. component: () => import('@/views/admin/examine.vue'),
  463. meta: {
  464. title: '审核视频',
  465. requireAuth: true
  466. }
  467. },
  468. {
  469. path: '/user/admin/userlist',
  470. name: 'Examine',
  471. component: () => import('@/views/admin/user-list.vue'),
  472. meta: {
  473. title: '用户列表',
  474. requireAuth: true
  475. }
  476. },
  477. {
  478. path: '/user/admin/websetting',
  479. name: 'Examine',
  480. component: () => import('@/views/admin/web-setting.vue'),
  481. meta: {
  482. title: '网页设置',
  483. requireAuth: true
  484. }
  485. },
  486. {
  487. path: '/user/admin/category',
  488. name: 'Examine',
  489. component: () => import('@/views/admin/category.vue'),
  490. meta: {
  491. title: '分区设置',
  492. requireAuth: true
  493. }
  494. }*/
  495. ]
  496. const router = new VueRouter({
  497. mode: 'history',
  498. routes
  499. })
  500. // 路由导航守卫
  501. router.beforeEach((to, from, next) => {
  502. // const token = window.localStorage.getItem('user')
  503. // console.log(this.$store.state.webInfo.name)
  504. // router.app.$options.store
  505. // 获取网页信息
  506. /*
  507. // TODO 网站信息暂时不从后端获取
  508. if (router.app.$options.store.state.webInfo.name == null) {
  509. fetch(`/api/media/web/info`, {
  510. headers: {
  511. 'mblog-Type': 'application/json; charset=UTF-8'
  512. },
  513. method: 'GET',
  514. credentials: 'include'
  515. }).then(response => response.json())
  516. .then(json => {
  517. router.app.$options.store.state.webInfo = json.data
  518. })
  519. .catch(e => {
  520. return null
  521. })
  522. }*/
  523. // 路由发生变化修改页面 title
  524. if (to.meta.title) {
  525. document.title = to.meta.title
  526. }
  527. const vuexStore = router.app.$options.store
  528. // router.app.$options.store 就是 this.$store
  529. /* if (checkPower.updateUserRole(vuexStore.state.user.userInfo)) {
  530. vuexStore.state.user.userInfo.role = 'ROLE_USER'
  531. vuexStore.commit('SET_USER_INFO', vuexStore.state.user.userInfo)
  532. }*/
  533. // const date = new Date().getTime()
  534. if (vuexStore.state.user.userInfo != null) {
  535. if (to.path === '/login') {
  536. return next({ path: '/' })
  537. }
  538. return next()
  539. // TODO 不判断用户是否过期
  540. /* if (vuexStore.state.user.userInfo.expireTime > date) {
  541. if (to.path === '/login') {
  542. return next({ path: '/' })
  543. }
  544. return next()
  545. } else {
  546. vuexStore.commit('user/SET_USER_INFO', null)
  547. return next({
  548. path: '/login',
  549. query: { redirect: to.fullPath }
  550. })
  551. }*/
  552. } else {
  553. if (to.meta.requireAuth) {
  554. return next({
  555. path: '/login',
  556. query: { redirect: to.fullPath }
  557. })
  558. } else {
  559. return next()
  560. }
  561. }
  562. })
  563. router.afterEach((to, from, next) => {
  564. window.scrollTo(0, 0)
  565. })
  566. export default router