Video.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <div>
  3. <el-row>
  4. <el-col :md="12">
  5. <div class="category-btn">
  6. <el-button
  7. v-for="(item, index) in category"
  8. :key="index"
  9. type="primary"
  10. size="medium"
  11. :plain="currentCategory !== index"
  12. circle
  13. @click="chooseCategory(item, index)"
  14. >{{ item }}
  15. </el-button>
  16. </div>
  17. </el-col>
  18. <el-col :md="12">
  19. <!--猜您喜欢-->
  20. <!-- <recommend />-->
  21. </el-col>
  22. </el-row>
  23. <el-row>
  24. <el-col :md="12">
  25. <div class="category-btn">
  26. <el-button
  27. v-for="(item, index) in childCategory"
  28. :key="index"
  29. type="primary"
  30. size="medium"
  31. :plain="currentChildCategory !== index"
  32. circle
  33. @click="getVideoList(item.id, index)"
  34. >{{ item.name }}
  35. </el-button>
  36. </div>
  37. </el-col>
  38. </el-row>
  39. <!--电影列表,与推荐列表-->
  40. <el-row id="movie-list">
  41. <!--电影列表-->
  42. <el-col :md="18">
  43. <el-col v-for="(video, index) in videoList" :key="index" :md="6" :sm="12" :xs="12">
  44. <video-card :video="video" />
  45. </el-col>
  46. <!--
  47. 分页按钮:
  48. page-size:每页显示条数
  49. total:总条数
  50. hide-on-single-page: 页数为一时隐藏
  51. -->
  52. <el-col :span="24" class="pagination">
  53. <el-pagination
  54. background
  55. :small="screenWidth <= 768"
  56. hide-on-single-page
  57. layout="prev, next"
  58. :page-size="pageSize"
  59. :current-page="currentPage"
  60. :total="totalSize"
  61. @prev-click="prevClick"
  62. @next-click="nextClick"
  63. />
  64. </el-col>
  65. </el-col>
  66. <!--热播列表-->
  67. <el-col :md="6">
  68. <hot-list />
  69. </el-col>
  70. </el-row>
  71. <el-row v-if="showEmpty" class="not-result">
  72. <el-col :span="12" :offset="6">
  73. <img src="@/assets/img/icon/not-result.png">
  74. <div>没有视频数据</div>
  75. </el-col>
  76. </el-row>
  77. </div>
  78. </template>
  79. <script>
  80. import VideoCard from 'components/card/VideoCard'
  81. import Recommend from 'components/recommend/Recommend'
  82. import HotList from 'components/hotlist/HotList'
  83. import { videoCategory, videoPage} from '@/api/video'
  84. export default {
  85. name: 'Video',
  86. components: { VideoCard, Recommend, HotList },
  87. data() {
  88. return {
  89. // 屏幕宽度, 为了控制分页条的大小
  90. screenWidth: document.body.clientWidth,
  91. currentPage: 1,
  92. pageSize: 12,
  93. totalPages: 0,
  94. totalSize: 0,
  95. videoList: [],
  96. prevId: '0',
  97. nextId: '0',
  98. categoryId: 2,
  99. currentIndex: 0,
  100. currentCategory: 0,
  101. currentChildCategory: 0,
  102. categoryMap: {
  103. Set: function(key, value) { this[key] = value },
  104. Get: function(key) { return this[key] },
  105. Contains: function(key) { return this.Get(key) !== null },
  106. Remove: function(key) { delete this[key] }
  107. },
  108. category: [],
  109. childCategory: [],
  110. showEmpty: true
  111. }
  112. },
  113. created() {
  114. document.title = '视频'
  115. videoCategory().then(res => {
  116. if (res.code === 0) {
  117. for (let i = 0; i < res.data.length; i++) {
  118. const name = res.data[i].name
  119. this.category.push(name)
  120. this.categoryMap.Set(name, res.data[i])
  121. }
  122. }
  123. })
  124. /*const query = this.$route.query
  125. var nextId = query.nextId
  126. if (nextId !== undefined) {
  127. this.nextId = nextId
  128. }
  129. var pageNumber = query.pageNumber
  130. if (pageNumber !== undefined) {
  131. const pn = parseInt(pageNumber)
  132. if (pn !== this.currentPage) {
  133. this.currentPage = pn
  134. this.$router.push({
  135. path: '/video',
  136. query: {
  137. pageNumber: this.currentPage,
  138. nextId: this.nextId
  139. }
  140. })
  141. }
  142. }*/
  143. this.videoPageWrapper(this.currentPage, this.prevId, this.nextId, this.categoryId)
  144. },
  145. mounted() {
  146. // 当窗口宽度改变时获取屏幕宽度
  147. window.onresize = () => {
  148. return () => {
  149. window.screenWidth = document.body.clientWidth
  150. this.screenWidth = window.screenWidth
  151. }
  152. }
  153. },
  154. methods: {
  155. prevClick(pageNumber) {
  156. this.currentPage = pageNumber
  157. this.videoPageWrapper(this.currentPage, this.prevId, this.prevId, this.categoryId)
  158. // 回到顶部
  159. scrollTo(0, 0)
  160. },
  161. nextClick(pageNumber) {
  162. this.currentPage = pageNumber
  163. this.videoPageWrapper(this.currentPage, this.prevId, this.nextId, this.categoryId)
  164. // 回到顶部
  165. scrollTo(0, 0)
  166. },
  167. videoPageWrapper(pageNumber, prevId, nextId, categoryId) {
  168. videoPage(pageNumber, prevId, nextId, categoryId).then(res => {
  169. if (res.code === 0) {
  170. const resData = res.data
  171. this.videoList = resData.list
  172. this.totalPages = resData.totalPages
  173. this.totalSize = resData.totalSize
  174. this.prevId = resData.prevId
  175. this.nextId = resData.nextId
  176. }
  177. })
  178. },
  179. chooseCategory(item, index) {
  180. this.currentCategory = index
  181. this.childCategory = this.categoryMap.Get(item).children
  182. },
  183. getVideoList(categoryId, index) {
  184. this.currentChildCategory = index
  185. this.categoryId = categoryId;
  186. this.prevId = 0
  187. this.nextId = 0
  188. this.currentPage = 1
  189. this.videoPageWrapper(this.currentPage, this.prevId, this.nextId, this.categoryId)
  190. }
  191. }
  192. }
  193. </script>
  194. <style scoped>
  195. #movie-list {
  196. padding-top: 15px;
  197. padding-left: 6%;
  198. padding-right: 6%;
  199. }
  200. .not-result {
  201. padding-top: 100px;
  202. padding-bottom: 100px;
  203. text-align: center;
  204. }
  205. .pagination {
  206. text-align: center;
  207. padding: 10px;
  208. }
  209. .category-btn {
  210. padding-left: 14%;
  211. padding-right: 6%;
  212. padding-top: 20px;
  213. }
  214. el-btn {
  215. background: #409eff;
  216. }
  217. /*处于手机屏幕时*/
  218. @media screen and (max-width: 768px){
  219. #movie-list {
  220. padding-top: 8px;
  221. padding-left: 0.5%;
  222. padding-right: 0.5%;
  223. }
  224. .category-btn {
  225. padding-left: 0.5%;
  226. padding-right: 0.5%;
  227. padding-top: 3%;
  228. text-align: center;
  229. }
  230. }
  231. </style>