video.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <scroll-view style="height:100%" :scroll-y="true" :refresher-enabled="true" :refresher-triggered="triggered"
  3. @scrolltolower="scrolltolower" @refresherrefresh="onRefresh" refresher-default-style="black">
  4. <view class="videoBox" v-for="item in videoList" :key="item" @click="goDetail(item)">
  5. <!-- :style='{backgroundImage:"../../../static/1.png"}' -->
  6. <view class="leftBox">
  7. <view class="time">
  8. 04:30
  9. </view>
  10. <i class="custom-icon custom-icon-start-full"></i>
  11. </view>
  12. <view class="info">
  13. <view class="content">
  14. {{item.title}}
  15. </view>
  16. <view class="attentionSituation">
  17. <view class="time">
  18. {{item.updateTime ? formatDate(Date.parse(item.updateTime)): ""}}
  19. </view>
  20. <view class="playCount">
  21. 1万次播放
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </scroll-view>
  27. </template>
  28. <script>
  29. import { getVideoList } from '@/api/video.js'
  30. import { formatDate } from '@/utils/util.js'
  31. export default {
  32. data() {
  33. return {
  34. loadingStatus: 'loadmore', // 上拉loading
  35. triggered: false, // 下拉是否激活
  36. videoList: [],
  37. total: 0,
  38. pageNum: 1,
  39. pageSize: 10,
  40. isRequesting: false, // 是否正在请求,如果是则返回,用于节流
  41. videoParams: {
  42. pageNum: 1,
  43. pageSize: 10,
  44. checkStatus: '5', // 已发布的数据
  45. },
  46. };
  47. },
  48. methods: {
  49. // 上拉加载
  50. scrolltolower() {
  51. if (this.videoList.length < this.total) {
  52. this.pageNum += 1;
  53. // 继续请求下一页,记得保留原先数组
  54. this.getList();
  55. } else {
  56. uni.showToast({
  57. title: "没有更多了",
  58. icon: "none",
  59. duration: 2000,
  60. });
  61. return;
  62. }
  63. },
  64. // 自定义下拉刷新被触发
  65. onRefresh() {
  66. // 开启下拉自定义样式
  67. this.triggered = true;
  68. // 重新调用
  69. this.getList();
  70. // 1秒之后复位
  71. setTimeout(() => {
  72. this.triggered = false;
  73. }, 1000);
  74. },
  75. getList(params={}) {
  76. this.isRequesting = true
  77. getVideoList({...this.videoParams,...params}).then(res => {
  78. // console.log("res:", res)
  79. this.videoList = [...this.videoList, ...res.rows]
  80. // console.log('videoList', this.videoList)
  81. this.total = res.total
  82. this.loadingStatus = this.videoList.length >= this.total ? 'nomore' : 'loading'
  83. }).finally(() => this.isRequesting = false)
  84. },
  85. // 点击资讯跳转详情
  86. goDetail(val) {
  87. console.log('跳转')
  88. uni.navigateTo({
  89. url: '/pages/video/detail'
  90. });
  91. },
  92. }
  93. }
  94. </script>
  95. <style lang="scss">
  96. .videoBox {
  97. width: 96%;
  98. background-color: #fff;
  99. padding: 20rpx;
  100. height: 260rpx;
  101. margin: 0 auto;
  102. margin-top: 20rpx;
  103. border-radius: 24rpx;
  104. box-shadow: 0 0 10rpx 6rpx rgba(0, 0, 0, 0.1);
  105. color: #666;
  106. display: flex;
  107. justify-content: space-between;
  108. .leftBox {
  109. width: 40%;
  110. height: 100%;
  111. margin-right: 20rpx;
  112. // background-color: red;
  113. position: relative;
  114. border-radius: 12rpx;
  115. border: 1px solid #eee;
  116. .time {
  117. width: 90rpx;
  118. height: 40rpx;
  119. border-radius: 40rpx;
  120. text-align: center;
  121. line-height: 40rpx;
  122. color: #fff;
  123. background-color: rgba(0, 0, 0, 0.1);
  124. position: absolute;
  125. top: 20rpx;
  126. right: 10rpx;
  127. }
  128. .custom-icon {
  129. position: absolute;
  130. top: 50%;
  131. left: 50%;
  132. transform: translate(-50%, -50%);
  133. font-size: 60rpx;
  134. &::before {
  135. background: rgba(0,0,0,0.1);
  136. -webkit-background-clip: text;
  137. -webkit-text-fill-color: transparent;
  138. font-weight: bold;
  139. }
  140. }
  141. }
  142. .info {
  143. flex: 1;
  144. // width: 100%;
  145. height: 100%;
  146. display: flex;
  147. flex-direction: column;
  148. justify-content: space-between;
  149. .content {
  150. overflow: hidden;
  151. text-overflow: ellipsis;
  152. display: -webkit-box;
  153. -webkit-line-clamp: 3;
  154. -webkit-box-orient: vertical;
  155. font-size: 32rpx;
  156. font-weight: 600;
  157. }
  158. .attentionSituation {
  159. font-size: 24rpx;
  160. display: flex;
  161. align-items: center;
  162. color: #aaa;
  163. .time {
  164. margin-right: 20rpx;
  165. }
  166. }
  167. }
  168. }
  169. </style>