videoList.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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" mode="aspectFill"></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. }else{
  89. uni.setStorage({
  90. key: 'liveImgUrl',
  91. data: item.imgUrl
  92. })
  93. uni.setStorage({
  94. key: 'liveName',
  95. data: item.liveName
  96. })
  97. }
  98. uni.navigateTo({
  99. url: '/pagesGood/' + (this.videoType == 1 ? ('liveDetail?liveId=' + item.liveId + '&roomId=' + item.roomId) :
  100. ('videoDetail?videoId=' + item.videoId))
  101. });
  102. }
  103. },
  104. }
  105. </script>
  106. <style lang="less" scoped>
  107. page {
  108. width: 100%;
  109. height: 100%;
  110. }
  111. .container {
  112. width: 100%;
  113. height: 100%;
  114. .search-box {
  115. width: 100%;
  116. height: 58px;
  117. box-sizing: border-box;
  118. padding: 2px 12px 1px 12px;
  119. }
  120. .video-box {
  121. width: 100%;
  122. height: calc(100% - 58px) !important;
  123. overflow-y: auto;
  124. .video-col {
  125. float: left;
  126. background: #FFFFFF;
  127. box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.15);
  128. border-radius: 5px;
  129. width: calc(50% - 18px);
  130. margin-top: 4px;
  131. margin-bottom: 6px;
  132. padding-bottom: 10px;
  133. position: relative;
  134. .video-img {
  135. width: 100%;
  136. height: 170px;
  137. object-fit: cover;
  138. float: left;
  139. }
  140. .video-title {
  141. width: 100%;
  142. height: 18px;
  143. box-sizing: border-box;
  144. padding-left: 8px;
  145. float: left;
  146. font-size: 15px;
  147. font-family: PingFang SC;
  148. color: #333333;
  149. line-height: 18px;
  150. overflow: hidden;
  151. white-space: nowrap;
  152. text-overflow: ellipsis;
  153. margin: 6px 0 2px 0;
  154. }
  155. .video-date {
  156. width: 100%;
  157. box-sizing: border-box;
  158. padding-left: 8px;
  159. height: 16px;
  160. float: left;
  161. font-size: 12px;
  162. font-family: PingFang SC;
  163. color: #52A63A;
  164. line-height: 16px;
  165. overflow: hidden;
  166. white-space: nowrap;
  167. text-overflow: ellipsis;
  168. }
  169. .video-mask {
  170. width: 100%;
  171. height: 100%;
  172. position: absolute;
  173. background-color: rgba(0, 0, 0, 0.3);
  174. border-radius: 5px;
  175. .video-mask-horn {
  176. width: 0;
  177. height: 0;
  178. border-bottom: 4px solid #52A63A;
  179. border-right: 4px solid transparent;
  180. position: absolute;
  181. right: -4px;
  182. top: 8px;
  183. }
  184. .video-mask-text {
  185. position: absolute;
  186. right: -4px;
  187. top: 12px;
  188. width: 52px;
  189. height: 18px;
  190. border-radius: 9px 0 0 9px;
  191. background: #52A63A;
  192. line-height: 18px;
  193. font-size: 10px;
  194. font-family: PingFang SC;
  195. color: #FFFFFF;
  196. text-align: center;
  197. }
  198. }
  199. }
  200. .video-col:nth-child(odd) {
  201. margin-left: 15px;
  202. margin-right: 3px;
  203. }
  204. .video-col:nth-child(even) {
  205. margin-left: 3px;
  206. margin-right: 15px;
  207. }
  208. }
  209. }
  210. </style>