videoList.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <view class="container">
  3. <view class="search-box">
  4. <uni-search-bar ref="searchBar" radius="5" placeholder="搜索" clearButton="auto" cancelButton="none" bgColor="#F8F8F8"
  5. @confirm="search" class="search-bar" />
  6. </view>
  7. <scroll-view class="video-box" scroll-y="true" @scrolltolower="handleLoadMore()">
  8. <view class="video-col" v-for="(item, index) in videoList" :key="index" @click="goToVideoDetail(item)">
  9. <image class="video-img" :src="videoType == 1 ? item.imgUrl : item.coverUrl"></image>
  10. <view class="video-title">{{videoType == 1 ? item.liveName : item.videoName}}</view>
  11. <view class="video-date" v-if="videoType == 1">直播时间:{{item.liveStartTime}}-{{item.liveEndTime}}</view>
  12. <view class="video-mask" v-if="videoType == 1 && item.liveStatus == 2">
  13. <view class="video-mask-horn"></view>
  14. <view class="video-mask-text">未开播</view>
  15. </view>
  16. </view>
  17. </scroll-view>
  18. <u-top-tips ref="uTips"></u-top-tips>
  19. </view>
  20. </template>
  21. <script>
  22. const NET = require('@/utils/request')
  23. const API = require('@/config/api')
  24. export default {
  25. data() {
  26. return {
  27. videoType: 1,
  28. pageIndex: 1,
  29. isOver: false,
  30. videoName: '',
  31. videoList: [],
  32. }
  33. },
  34. onLoad(options) {
  35. this.videoType = options.videoType
  36. if (this.videoType == 2) {
  37. uni.setNavigationBarTitle({
  38. title: '短视频'
  39. });
  40. }
  41. this.getVideoList()
  42. },
  43. onPullDownRefresh() {
  44. this.pageIndex = 1
  45. this.videoList = []
  46. this.getVideoList('refresh')
  47. },
  48. methods: {
  49. // 搜索直播
  50. search(data) {
  51. this.videoName = data.value
  52. this.videoList = []
  53. this.pageIndex = 1
  54. this.getVideoList()
  55. },
  56. // 懒加载
  57. handleLoadMore() {
  58. if (!this.isOver) {
  59. this.pageIndex++
  60. this.getVideoList()
  61. }
  62. },
  63. // 获取直播列表
  64. getVideoList(type) {
  65. NET.request((this.videoType == 1 ? API.getLiveTelecastList : API.getShortVideo) + '/' + this.pageIndex + '/10', {
  66. liveName: this.videoName,
  67. videoName: this.videoName,
  68. }, 'GET').then(res => {
  69. if (type == 'refresh') {
  70. uni.stopPullDownRefresh();
  71. }
  72. this.isOver = res.data.list.length != 10
  73. this.videoList = this.videoList.concat(res.data.list)
  74. }).catch(res => {
  75. this.$refs.uTips.show({
  76. title: '获取直播列表失败',
  77. type: 'warning',
  78. })
  79. })
  80. },
  81. // 跳转直播详情
  82. goToVideoDetail(item) {
  83. if (this.videoType != 1) {
  84. uni.setStorage({
  85. key: 'videoUrl',
  86. data: item.mediaUrl
  87. })
  88. }
  89. uni.navigateTo({
  90. url: '/pagesGood/' + (this.videoType == 1 ? ('liveDetail?liveId=' + item.liveId + '&roomId=' + item.roomId) :
  91. ('videoDetail?videoId=' + item.videoId))
  92. });
  93. }
  94. },
  95. }
  96. </script>
  97. <style lang="less" scoped>
  98. page {
  99. width: 100%;
  100. height: 100%;
  101. }
  102. .container {
  103. width: 100%;
  104. height: 100%;
  105. .search-box {
  106. width: 100%;
  107. height: 58px;
  108. box-sizing: border-box;
  109. padding: 2px 12px 1px 12px;
  110. }
  111. .video-box {
  112. width: 100%;
  113. height: calc(100% - 58px) !important;
  114. overflow-y: auto;
  115. .video-col {
  116. float: left;
  117. background: #FFFFFF;
  118. box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.15);
  119. border-radius: 5px;
  120. width: calc(50% - 18px);
  121. margin-top: 4px;
  122. margin-bottom: 6px;
  123. padding-bottom: 10px;
  124. position: relative;
  125. .video-img {
  126. width: 100%;
  127. height: 170px;
  128. object-fit: cover;
  129. float: left;
  130. }
  131. .video-title {
  132. width: 100%;
  133. height: 18px;
  134. box-sizing: border-box;
  135. padding-left: 8px;
  136. float: left;
  137. font-size: 15px;
  138. font-family: PingFang SC;
  139. color: #333333;
  140. line-height: 18px;
  141. overflow: hidden;
  142. white-space: nowrap;
  143. text-overflow: ellipsis;
  144. margin: 6px 0 2px 0;
  145. }
  146. .video-date {
  147. width: 100%;
  148. box-sizing: border-box;
  149. padding-left: 8px;
  150. height: 16px;
  151. float: left;
  152. font-size: 12px;
  153. font-family: PingFang SC;
  154. color: #52A63A;
  155. line-height: 16px;
  156. overflow: hidden;
  157. white-space: nowrap;
  158. text-overflow: ellipsis;
  159. }
  160. .video-mask {
  161. width: 100%;
  162. height: 100%;
  163. position: absolute;
  164. background-color: rgba(0, 0, 0, 0.3);
  165. border-radius: 5px;
  166. .video-mask-horn {
  167. width: 0;
  168. height: 0;
  169. border-bottom: 4px solid #52A63A;
  170. border-right: 4px solid transparent;
  171. position: absolute;
  172. right: -4px;
  173. top: 8px;
  174. }
  175. .video-mask-text {
  176. position: absolute;
  177. right: -4px;
  178. top: 12px;
  179. width: 52px;
  180. height: 18px;
  181. border-radius: 9px 0 0 9px;
  182. background: #52A63A;
  183. line-height: 18px;
  184. font-size: 10px;
  185. font-family: PingFang SC;
  186. color: #FFFFFF;
  187. text-align: center;
  188. }
  189. }
  190. }
  191. .video-col:nth-child(odd) {
  192. margin-left: 15px;
  193. margin-right: 3px;
  194. }
  195. .video-col:nth-child(even) {
  196. margin-left: 3px;
  197. margin-right: 15px;
  198. }
  199. }
  200. }
  201. </style>