videoList.vue 5.2 KB

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