ShortVideo.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <div>
  3. <el-row id="movie-list">
  4. <el-scrollbar style="width: 100%; height: 75vh;">
  5. <el-row
  6. v-if="dataList.length !== 0"
  7. v-infinite-scroll="load"
  8. infinite-scroll-disabled="loading"
  9. infinite-scroll-distance="10"
  10. >
  11. <el-col v-for="(video, index) in dataList" :key="index" :md="6" :sm="12" :xs="12">
  12. <video-card :video="video" />
  13. </el-col>
  14. <el-col v-if="dataList.length === 0" class="not-result" :md="6" :sm="12" :xs="12">
  15. <img src="@/assets/img/icon/not-result.png">
  16. <div>没有视频数据</div>
  17. </el-col>
  18. </el-row>
  19. </el-scrollbar>
  20. </el-row>
  21. </div>
  22. </template>
  23. <script>
  24. import VideoCard from 'components/card/VideoCard'
  25. import { categoryShortVideos } from '@/api/video'
  26. export default {
  27. name: 'ShortVideo',
  28. components: { VideoCard },
  29. data() {
  30. return {
  31. // 屏幕宽度, 为了控制分页条的大小
  32. screenWidth: document.body.clientWidth,
  33. currentPage: 1,
  34. pageSize: 12,
  35. totalSize: 0,
  36. dataList: [],
  37. categoryId: 1,
  38. treeNode: [],
  39. defaultProps: {
  40. children: 'children',
  41. label: 'label',
  42. value: 'value'
  43. },
  44. loading: false
  45. }
  46. },
  47. created() {
  48. document.title = '短视频主页'
  49. this.videoPageWrapper(this.categoryId, this.currentPage)
  50. },
  51. mounted() {
  52. // 当窗口宽度改变时获取屏幕宽度
  53. window.onresize = () => {
  54. return () => {
  55. window.screenWidth = document.body.clientWidth
  56. this.screenWidth = window.screenWidth
  57. }
  58. }
  59. },
  60. methods: {
  61. videoPageWrapper(categoryId, currentPage) {
  62. categoryShortVideos(categoryId, currentPage).then(resp => {
  63. if (resp.code === 0) {
  64. for (const item of resp.data.list) {
  65. this.dataList.push(item)
  66. }
  67. this.currentPage += 1
  68. this.loading = false
  69. } else {
  70. this.$notify({
  71. title: '提示',
  72. message: resp.msg,
  73. type: 'error',
  74. duration: 3000
  75. })
  76. }
  77. }).catch(error => {
  78. this.$notify({
  79. title: '提示',
  80. message: error.message,
  81. type: 'warning',
  82. duration: 3000
  83. })
  84. })
  85. },
  86. load() {
  87. this.loading = true
  88. setTimeout(() => {
  89. this.videoPageWrapper(this.categoryId, this.currentPage)
  90. }, 1000)
  91. }
  92. }
  93. }
  94. </script>
  95. <style scoped>
  96. /*处于手机屏幕时*/
  97. @media screen and (max-width: 768px){
  98. #movie-list {
  99. padding-top: 8px;
  100. padding-left: 0.5%;
  101. padding-right: 0.5%;
  102. }
  103. }
  104. #movie-list {
  105. padding-top: 15px;
  106. padding-left: 6%;
  107. padding-right: 6%;
  108. }
  109. .not-result {
  110. padding-top: 100px;
  111. padding-bottom: 100px;
  112. text-align: center;
  113. }
  114. </style>