Index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <el-row>
  3. <el-row class="movie-list">
  4. <el-col :md="12">
  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. <el-carousel :interval="3000" height="300px">
  10. <el-carousel-item v-for="(item, index) in carouselList" :key="index">
  11. <router-link target="_blank" :to="`/video/${item.videoId}`">
  12. <img class="carousel_image_type" :src="item.coverUrl" alt="img">
  13. </router-link>
  14. </el-carousel-item>
  15. </el-carousel>
  16. </el-row>
  17. </el-col>
  18. <el-col :md="12">
  19. <!--电影列表,与推荐列表-->
  20. <el-row>
  21. <!--电影列表-->
  22. <el-col :md="24">
  23. <el-col v-for="(item, index) in sideDataList" :key="index" :md="12" :sm="12" :xs="12">
  24. <video-card :video="item" />
  25. </el-col>
  26. </el-col>
  27. </el-row>
  28. </el-col>
  29. </el-row>
  30. <el-row class="movie-list">
  31. <!--电影列表,与推荐列表-->
  32. <el-row
  33. v-if="dataList.length !== 0"
  34. v-infinite-scroll="load"
  35. infinite-scroll-disabled="loading"
  36. infinite-scroll-distance="10"
  37. >
  38. <!--电影列表-->
  39. <el-col :md="24">
  40. <el-col v-for="(item, index) in dataList" :key="index" :md="6" :sm="12" :xs="12">
  41. <video-card :video="item" />
  42. </el-col>
  43. </el-col>
  44. </el-row>
  45. <el-row v-else class="not-result">
  46. <el-col :span="12" :offset="6">
  47. <img src="@/assets/img/icon/not-collection.png">
  48. <div>推荐数据正在计算中</div>
  49. </el-col>
  50. </el-row>
  51. </el-row>
  52. </el-row>
  53. </template>
  54. <script>
  55. import VideoCard from '@/components/card/VideoCard'
  56. import SiteNotice from '@/components/card/SiteNotice'
  57. import { getHotVideo, videoRecommend } from '@/api/video'
  58. export default {
  59. name: 'Index',
  60. components: { VideoCard, SiteNotice },
  61. data() {
  62. return {
  63. // 屏幕宽度, 为了控制分页条的大小
  64. screenWidth: document.body.clientWidth,
  65. nextId: 0,
  66. sideDataList: [],
  67. dataList: [],
  68. loading: false,
  69. max: 0,
  70. carouselList: []
  71. }
  72. },
  73. created() {
  74. this.videoRecommendWrapper(this.nextId)
  75. },
  76. mounted() {
  77. // 当窗口宽度改变时获取屏幕宽度
  78. window.onresize = () => {
  79. return () => {
  80. window.screenWidth = document.body.clientWidth
  81. this.screenWidth = window.screenWidth
  82. }
  83. }
  84. getHotVideo().then(resp => {
  85. if (resp.code === 0) {
  86. this.carouselList = resp.data
  87. }
  88. })
  89. },
  90. methods: {
  91. videoRecommendWrapper(nextId) {
  92. videoRecommend(nextId).then(resp => {
  93. if (resp.code === 0) {
  94. const respData = resp.data
  95. if (respData.length === 0) {
  96. this.loading = false
  97. return
  98. }
  99. if (this.nextId === 0) {
  100. this.sideDataList = respData.slice(0, 4)
  101. this.dataList = respData.slice(4, 12)
  102. } else {
  103. for (const item of respData) {
  104. this.dataList.push(item)
  105. }
  106. }
  107. this.loading = false
  108. this.nextId++
  109. } else {
  110. this.$notify(
  111. {
  112. title: '提示',
  113. message: '获取数据失败, 请重新刷新页面',
  114. type: 'warning',
  115. duration: 3000
  116. }
  117. )
  118. }
  119. })
  120. },
  121. load() {
  122. this.max++
  123. if (this.max > 0) {
  124. return
  125. }
  126. this.loading = true
  127. setTimeout(() => {
  128. this.videoRecommendWrapper(this.nextId)
  129. }, 1000)
  130. }
  131. }
  132. }
  133. </script>
  134. <style scoped>
  135. /*处于手机屏幕时*/
  136. @media screen and (max-width: 768px){
  137. .movie-list {
  138. padding-top: 8px;
  139. padding-left: 0.5%;
  140. padding-right: 0.5%;
  141. }
  142. }
  143. .movie-list {
  144. padding-top: 15px;
  145. padding-left: 6%;
  146. padding-right: 6%;
  147. }
  148. .not-result {
  149. padding-top: 100px;
  150. padding-bottom: 100px;
  151. text-align: center;
  152. }
  153. .el-carousel__item h3 {
  154. color: #475669;
  155. font-size: 18px;
  156. opacity: 0.75;
  157. line-height: 300px;
  158. margin: 0;
  159. }
  160. .carousel_image_type{
  161. width: 100%;
  162. }
  163. </style>