Video.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <div>
  3. <!--电影列表,与推荐列表-->
  4. <el-row id="movie-list">
  5. <el-col :md="6">
  6. <el-card class="box-card" :body-style="{ paddingTop: '0px' }">
  7. <div slot="header" class="clearfix">
  8. <span>视频分区</span>
  9. </div>
  10. <div class="item">
  11. <v-jstree :data="treeNode" @item-click="itemClick" />
  12. </div>
  13. </el-card>
  14. </el-col>
  15. <!--电影列表-->
  16. <el-col :md="18">
  17. <el-col v-for="(video, index) in dataList" :key="index" :md="6" :sm="12" :xs="12">
  18. <video-card :video="video" />
  19. </el-col>
  20. <el-col v-if="totalSize === 0" class="not-result" :md="6" :sm="12" :xs="12">
  21. <img src="@/assets/img/icon/not-result.png">
  22. <div>没有视频数据</div>
  23. </el-col>
  24. <!--
  25. 分页按钮:
  26. page-size:每页显示条数
  27. total:总条数
  28. hide-on-single-page: 页数为一时隐藏
  29. -->
  30. <el-col :span="24" class="pagination">
  31. <el-pagination
  32. :small="screenWidth <= 768"
  33. layout="prev, pager, next"
  34. :page-size="pageSize"
  35. :current-page="currentPage"
  36. :total="totalSize"
  37. @current-change="handleCurrentChange"
  38. />
  39. </el-col>
  40. </el-col>
  41. </el-row>
  42. </div>
  43. </template>
  44. <script>
  45. import VideoCard from 'components/card/VideoCard'
  46. import VJstree from 'vue-jstree'
  47. import { videoCategory, categoryVideos } from '@/api/video'
  48. export default {
  49. name: 'Video',
  50. components: { VideoCard, VJstree },
  51. data() {
  52. return {
  53. // 屏幕宽度, 为了控制分页条的大小
  54. screenWidth: document.body.clientWidth,
  55. currentPage: 1,
  56. pageSize: 12,
  57. totalPages: 0,
  58. totalSize: 0,
  59. dataList: [],
  60. categoryId: 20,
  61. treeNode: []
  62. }
  63. },
  64. created() {
  65. document.title = '视频主页'
  66. videoCategory().then(resp => {
  67. if (resp.code === 0) {
  68. this.treeNode = resp.data
  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. this.videoPageWrapper(this.categoryId, this.currentPage)
  86. },
  87. mounted() {
  88. // 当窗口宽度改变时获取屏幕宽度
  89. window.onresize = () => {
  90. return () => {
  91. window.screenWidth = document.body.clientWidth
  92. this.screenWidth = window.screenWidth
  93. }
  94. }
  95. },
  96. methods: {
  97. handleCurrentChange(currentPage) {
  98. this.currentPage = currentPage
  99. this.videoPageWrapper(this.categoryId, this.currentPage)
  100. // 回到顶部
  101. scrollTo(0, 0)
  102. },
  103. videoPageWrapper(categoryId, currentPage) {
  104. categoryVideos(categoryId, currentPage).then(resp => {
  105. if (resp.code === 0) {
  106. const respData = resp.data
  107. this.dataList = respData.list
  108. this.totalPages = respData.totalPages
  109. this.totalSize = respData.totalSize
  110. } else {
  111. this.$notify({
  112. title: '提示',
  113. message: resp.msg,
  114. type: 'error',
  115. duration: 3000
  116. })
  117. }
  118. }).catch(error => {
  119. this.$notify({
  120. title: '提示',
  121. message: error.message,
  122. type: 'warning',
  123. duration: 3000
  124. })
  125. })
  126. },
  127. itemClick(node) {
  128. const model = node.model
  129. this.categoryId = model.value
  130. /* if (model.children.length === 0) {
  131. this.categoryId = model.value
  132. }*/
  133. this.videoPageWrapper(this.categoryId, this.currentPage)
  134. }
  135. }
  136. }
  137. </script>
  138. <style scoped>
  139. /*处于手机屏幕时*/
  140. @media screen and (max-width: 768px){
  141. #movie-list {
  142. padding-top: 8px;
  143. padding-left: 0.5%;
  144. padding-right: 0.5%;
  145. }
  146. .category-btn {
  147. padding-left: 0.5%;
  148. padding-right: 0.5%;
  149. padding-top: 3%;
  150. text-align: center;
  151. }
  152. }
  153. #movie-list {
  154. padding-top: 15px;
  155. padding-left: 6%;
  156. padding-right: 6%;
  157. }
  158. .not-result {
  159. padding-top: 100px;
  160. padding-bottom: 100px;
  161. text-align: center;
  162. }
  163. .pagination {
  164. text-align: center;
  165. padding: 10px;
  166. }
  167. .category-btn {
  168. padding-left: 14%;
  169. padding-right: 6%;
  170. padding-top: 20px;
  171. }
  172. </style>