TvPage.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 class="alert-text" v-show="this.dataList.length>=this.dataTotal">
  38. <div>没有更多数据</div>
  39. </div>
  40. </div>
  41. </template>
  42. <style scoped>
  43. .alert-text{
  44. text-align: center;
  45. font-size: 0.3rem;
  46. color: #999;
  47. }
  48. .tv-list .tv-item {
  49. border-bottom: 1px solid #ccc;
  50. padding-bottom: 0.2rem;
  51. margin-bottom: 0.2rem;
  52. }
  53. .tv-list {
  54. padding: 0.2rem;
  55. }
  56. .tv-list .tv-img {
  57. display: flex;
  58. }
  59. .tv-list .tv-img .left-img {
  60. width: 35%;
  61. height: 3.3rem;
  62. overflow: hidden;
  63. border-radius: 0.1rem;
  64. }
  65. .tv-list .left-img img {
  66. width: 100%;
  67. }
  68. .tv-list .tv-img img {
  69. width: 100%;
  70. }
  71. .tv-list .tv-img .right-img {
  72. margin-left: 2%;
  73. width: 63%;
  74. height: 3.3rem;
  75. overflow: hidden;
  76. border-radius: 0.1rem;
  77. }
  78. /* 信息部分样式 */
  79. .tv-info {
  80. display: flex;
  81. margin-top: 0.1rem;
  82. }
  83. .tv-info .info-left {
  84. width: 80%;
  85. }
  86. .tv-info .info-left .tv-title {
  87. font-size: 0.3rem;
  88. font-weight: 700;
  89. color: #333;
  90. margin-bottom: 0.1rem;
  91. }
  92. .tv-info .info-left .tv-rate {
  93. font-size: 0.2rem;
  94. color: #ff9900;
  95. margin-bottom: 0.1rem;
  96. }
  97. .tv-info .info-left .tv-int {
  98. font-size: 0.2rem;
  99. color: #999;
  100. }
  101. .tv-info .info-right {
  102. width: 20%;
  103. text-align: right;
  104. line-height: 0.1rem;
  105. }
  106. .tv-info .info-right i {
  107. font-size: 0.45rem;
  108. color: #ff9900;
  109. }
  110. /* 评论部分 */
  111. .tv-desc {
  112. font-size: 0.25rem;
  113. color: #666;
  114. margin-top: 0.2rem;
  115. }
  116. </style>
  117. <script>
  118. import TvRate from "@/components/TvRate.vue";
  119. import DescComp from "@/components/DescComp.vue";
  120. import axios from "axios";
  121. export default {
  122. data() {
  123. return {
  124. dataList: [],
  125. isLoading:false,
  126. dataTotal: 0
  127. };
  128. },
  129. beforeMount() {
  130. this.$emit("changePage", "1001");
  131. },
  132. created() {
  133. // 创建变量在当前页面中任何方法中都可以使用
  134. this.startNum = 0;
  135. this.getData();
  136. },
  137. mounted() {
  138. this.scrollHandle();
  139. },
  140. beforeDestroy() {
  141. window.onscroll = null;
  142. },
  143. methods: {
  144. // 获取数据
  145. getData() {
  146. this.isLoading = true;
  147. axios
  148. .get("/api/subject_collection/tv_domestic/items", {
  149. params: {
  150. count: 10,
  151. start: this.startNum,
  152. },
  153. })
  154. .then((res) => {
  155. this.dataTotal = res.data.total;
  156. this.dataList = this.dataList.concat(res.data.subject_collection_items);
  157. setTimeout(()=>{
  158. this.isLoading = false;
  159. },1000)
  160. })
  161. .catch((err) => {
  162. console.log(err);
  163. });
  164. },
  165. // 滚动条事件
  166. scrollHandle() {
  167. let dom = document.documentElement;
  168. window.onscroll = () => {
  169. //scrollTop 滚动条滚动时距离顶部的距离
  170. let scrollTop = dom.scrollTop;
  171. // clientHeight 可视区域的高度
  172. let clientHeight = dom.clientHeight;
  173. // scrollHeight 滚动条的总高度
  174. let scrollHeight = dom.scrollHeight;
  175. if (scrollTop + clientHeight + 100 >= scrollHeight) {
  176. console.log("到底了");
  177. if(!this.isLoading && this.dataTotal>this.startNum){
  178. this.startNum += 10;
  179. this.getData();
  180. }
  181. }
  182. };
  183. },
  184. },
  185. components: {
  186. TvRate,
  187. DescComp,
  188. },
  189. };
  190. </script>