TvPage.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <div class="tv-container">
  3. <div class="tv-list">
  4. <div class="tv-item" v-for="item in dataList" :key="item.id">
  5. <div class="tv-img">
  6. <div class="left-img">
  7. <img
  8. :src="'https://images.weserv.nl/?url=' + item.pic.normal"
  9. alt=""
  10. />
  11. </div>
  12. <div class="right-img">
  13. <img
  14. :src="'https://images.weserv.nl/?url=' + item.photos[0]"
  15. alt=""
  16. srcset=""
  17. />
  18. </div>
  19. </div>
  20. <div class="tv-info">
  21. <div class="info-left">
  22. <div class="tv-title">{{ item.title }}({{ item.year }})</div>
  23. <div class="tv-rate">
  24. <TvRate :val="item.rating"></TvRate>
  25. </div>
  26. <div class="tv-int">{{ item.card_subtitle }}</div>
  27. </div>
  28. <div class="info-right">
  29. <i class="iconfont icon-xiangkan"></i>
  30. </div>
  31. </div>
  32. <div class="tv-desc">
  33. <DescComp :val="item.comment" />
  34. </div>
  35. </div>
  36. </div>
  37. </div>
  38. </template>
  39. <style scoped>
  40. .tv-list .tv-item {
  41. border-bottom: 1px solid #ccc;
  42. padding-bottom: 0.2rem;
  43. margin-bottom: 0.2rem;
  44. }
  45. .tv-list {
  46. padding: 0.2rem;
  47. }
  48. .tv-list .tv-img {
  49. display: flex;
  50. }
  51. .tv-list .tv-img .left-img {
  52. width: 35%;
  53. height: 3.3rem;
  54. overflow: hidden;
  55. border-radius: 0.1rem;
  56. }
  57. .tv-list .left-img img {
  58. width: 100%;
  59. }
  60. .tv-list .tv-img img {
  61. width: 100%;
  62. }
  63. .tv-list .tv-img .right-img {
  64. margin-left: 2%;
  65. width: 63%;
  66. height: 3.3rem;
  67. overflow: hidden;
  68. border-radius: 0.1rem;
  69. }
  70. /* 信息部分样式 */
  71. .tv-info {
  72. display: flex;
  73. margin-top: 0.1rem;
  74. }
  75. .tv-info .info-left {
  76. width: 80%;
  77. }
  78. .tv-info .info-left .tv-title {
  79. font-size: 0.3rem;
  80. font-weight: 700;
  81. color: #333;
  82. margin-bottom: 0.1rem;
  83. }
  84. .tv-info .info-left .tv-rate {
  85. font-size: 0.2rem;
  86. color: #ff9900;
  87. margin-bottom: 0.1rem;
  88. }
  89. .tv-info .info-left .tv-int {
  90. font-size: 0.2rem;
  91. color: #999;
  92. }
  93. .tv-info .info-right {
  94. width: 20%;
  95. text-align: right;
  96. line-height: 0.1rem;
  97. }
  98. .tv-info .info-right i {
  99. font-size: 0.45rem;
  100. color: #ff9900;
  101. }
  102. /* 评论部分 */
  103. .tv-desc {
  104. font-size: 0.25rem;
  105. color: #666;
  106. margin-top: 0.2rem;
  107. }
  108. </style>
  109. <script>
  110. import TvRate from "@/components/TvRate.vue";
  111. import DescComp from "@/components/DescComp.vue";
  112. import axios from "axios";
  113. export default {
  114. data() {
  115. return {
  116. dataList: [],
  117. isLoading:false
  118. };
  119. },
  120. beforeMount() {
  121. this.$emit("changePage", "1001");
  122. },
  123. created() {
  124. // 创建变量在当前页面中任何方法中都可以使用
  125. this.startNum = 0;
  126. this.getData();
  127. },
  128. mounted() {
  129. this.scrollHandle();
  130. },
  131. methods: {
  132. // 获取数据
  133. getData() {
  134. this.isLoading = true;
  135. axios
  136. .get("/api/subject_collection/tv_domestic/items", {
  137. params: {
  138. count: 10,
  139. start: this.startNum,
  140. },
  141. })
  142. .then((res) => {
  143. // console.log(res);
  144. this.dataList = this.dataList.concat(res.data.subject_collection_items);
  145. setTimeout(()=>{
  146. this.isLoading = false;
  147. },1000)
  148. })
  149. .catch((err) => {
  150. console.log(err);
  151. });
  152. },
  153. // 滚动条事件
  154. scrollHandle() {
  155. let dom = document.documentElement;
  156. window.onscroll = () => {
  157. //scrollTop 滚动条滚动时距离顶部的距离
  158. let scrollTop = dom.scrollTop;
  159. // clientHeight 可视区域的高度
  160. let clientHeight = dom.clientHeight;
  161. // scrollHeight 滚动条的总高度
  162. let scrollHeight = dom.scrollHeight;
  163. if (scrollTop + clientHeight + 100 >= scrollHeight) {
  164. console.log("到底了");
  165. if(!this.isLoading){
  166. this.startNum += 10;
  167. this.getData();
  168. }
  169. }
  170. };
  171. },
  172. },
  173. components: {
  174. TvRate,
  175. DescComp,
  176. },
  177. };
  178. </script>