Index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div>
  3. <el-row id="movie-list">
  4. <el-col :md="6">
  5. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  6. <site-notice />
  7. </el-row>
  8. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  9. <hot-video />
  10. </el-row>
  11. </el-col>
  12. <el-col :md="18">
  13. <!--电影列表,与推荐列表-->
  14. <el-row
  15. v-if="dataList.length !== 0"
  16. v-infinite-scroll="load"
  17. infinite-scroll-disabled="loading"
  18. infinite-scroll-distance="10"
  19. >
  20. <!--电影列表-->
  21. <el-col :md="24">
  22. <el-col v-for="(item, index) in dataList" :key="index" :md="6" :sm="12" :xs="12">
  23. <video-card :video="item" />
  24. </el-col>
  25. </el-col>
  26. </el-row>
  27. <el-row v-else class="not-result">
  28. <el-col :span="12" :offset="6">
  29. <img src="@/assets/img/icon/not-collection.png">
  30. <div>推荐数据正在计算中</div>
  31. </el-col>
  32. </el-row>
  33. </el-col>
  34. </el-row>
  35. </div>
  36. </template>
  37. <script>
  38. import VideoCard from '@/components/card/VideoCard'
  39. import HotVideo from '@/components/card/HotVideo'
  40. import SiteNotice from '@/components/card/SiteNotice'
  41. import { videoRecommend } from '@/api/video'
  42. export default {
  43. name: 'Index',
  44. components: { VideoCard, HotVideo, SiteNotice },
  45. data() {
  46. return {
  47. // 屏幕宽度, 为了控制分页条的大小
  48. screenWidth: document.body.clientWidth,
  49. nextId: '1',
  50. dataList: [],
  51. loading: false,
  52. max: 0
  53. }
  54. },
  55. created() {
  56. this.videoRecommendWrapper(this.nextId)
  57. },
  58. mounted() {
  59. // 当窗口宽度改变时获取屏幕宽度
  60. window.onresize = () => {
  61. return () => {
  62. window.screenWidth = document.body.clientWidth
  63. this.screenWidth = window.screenWidth
  64. }
  65. }
  66. },
  67. methods: {
  68. videoRecommendWrapper(nextId) {
  69. videoRecommend(nextId).then(resp => {
  70. if (resp.code === 0) {
  71. const respData = resp.data
  72. if (respData.length === 0) {
  73. this.loading = false
  74. return
  75. }
  76. for (const item of respData) {
  77. this.dataList.push(item)
  78. }
  79. this.loading = false
  80. } else {
  81. this.$notify(
  82. {
  83. title: '提示',
  84. message: '获取数据失败, 请重新刷新页面',
  85. type: 'warning',
  86. duration: 3000
  87. }
  88. )
  89. }
  90. })
  91. },
  92. load() {
  93. this.max++
  94. if (this.max > 1) {
  95. return
  96. }
  97. this.loading = true
  98. setTimeout(() => {
  99. this.videoRecommendWrapper(this.nextId)
  100. }, 1000)
  101. }
  102. }
  103. }
  104. </script>
  105. <style scoped>
  106. /*处于手机屏幕时*/
  107. @media screen and (max-width: 768px){
  108. #movie-list {
  109. padding-top: 8px;
  110. padding-left: 0.5%;
  111. padding-right: 0.5%;
  112. }
  113. }
  114. #movie-list {
  115. padding-top: 15px;
  116. padding-left: 6%;
  117. padding-right: 6%;
  118. }
  119. .not-result {
  120. padding-top: 100px;
  121. padding-bottom: 100px;
  122. text-align: center;
  123. }
  124. </style>