index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <view class="container">
  3. <view class="content">
  4. <view class="col" v-for="(item,index) in list" :key="index" @click="play(index+1,index)">
  5. <view class="videoimgbox">
  6. <view v-if="item.videotype==1">
  7. <video v-if="currentId == (index+1)"
  8. style="width: 400rpx;height: 708rpx; border-radius: 10rpx; display: block;" autoplay="true"
  9. :id="'video'+(index+1)" :src="item.videourl"></video>
  10. <block v-else>
  11. <video style="width: 400rpx;height: 708rpx; border-radius: 10rpx; display: block;"
  12. :src="item.videourl"></video>
  13. </block>
  14. </view>
  15. <view class="imgbox">
  16. <navigator hover-class="none"
  17. :url="item.id > 0 ? '/pages/goodsDetail/goodsDetail?id=' + item.id : ''">
  18. <view style="padding-bottom: 23rpx;">
  19. <image v-if="item.images[0].image" :src="item.images[0].image" class="goods-image"></image>
  20. </view>
  21. <view style="padding-bottom: 23rpx;">
  22. <image v-if="item.images[1].image" :src="item.images[1].image" class="goods-image"></image>
  23. </view>
  24. <view>
  25. <image v-if="item.images[2].image" :src="item.images[2].image" class="goods-image"></image>
  26. </view>
  27. </navigator>
  28. </view>
  29. </view>
  30. <view style="padding-top: 30rpx;">
  31. <navigator hover-class="none"
  32. :url="item.id > 0 ? '/pages/goodsDetail/goodsDetail?id=' + item.id : ''"><button style="background-color: #ed6980;color: #ffffff;">去看看</button></navigator>
  33. </view>
  34. <tui-tabbar :current="current">
  35. </tui-tabbar>
  36. </view>
  37. </view>
  38. <!--加载loadding-->
  39. <tui-loadmore v-if="loadding" :index="3" type="red"></tui-loadmore>
  40. <tui-nomore v-if="!pullUpOn" backgroundColor="#f7f7f7"></tui-nomore>
  41. <!--加载loadding-->
  42. </view>
  43. </template>
  44. <script>
  45. export default {
  46. data() {
  47. return {
  48. list: [],
  49. where: {
  50. page: 1,
  51. limit: 10,
  52. },
  53. current: '',
  54. currentId: 0,
  55. scrollH: 0,
  56. scrollTop: 0,
  57. height: 0,
  58. windowHeight: 0,
  59. loadding: false,
  60. pullUpOn: true
  61. }
  62. },
  63. onLoad() {
  64. let that = this
  65. // #ifdef MP-WEIXIN
  66. this.current = "/" + this.__route__;
  67. // #endif
  68. //#ifdef H5
  69. this.current = this.$route.path;
  70. //#endif
  71. uni.setNavigationBarTitle({
  72. title: '短视频'
  73. });
  74. uni.setNavigationBarColor({
  75. frontColor: '#ffffff',
  76. backgroundColor: '#ed6980',
  77. animation: { //动画效果
  78. duration: 400,
  79. timingFunc: 'easeIn'
  80. }
  81. });
  82. this.getList()
  83. // 获取可视区域高度
  84. uni.getSystemInfo({
  85. success: function(res) {
  86. that.windowHeight = res.windowHeight
  87. }
  88. })
  89. this.play(1, 0);
  90. },
  91. onPageScroll(res) {
  92. // 获取滚动距离
  93. this.scrollH = res.scrollTop
  94. // 判断元素是否已经出了可视区
  95. if (this.scrollH > this.scrollTop) {
  96. const e = uni.createVideoContext("video" + this.currentId, this);
  97. e.pause();
  98. this.play(this.currentId + 1, this.currentId);
  99. }
  100. if (this.scrollH + this.windowHeight < this.scrollTop) {
  101. const e = uni.createVideoContext("video" + this.currentId, this);
  102. e.pause();
  103. this.play(this.currentId - 1, this.currentId - 2);
  104. }
  105. },
  106. onHide() {
  107. this.currentId = 0
  108. },
  109. methods: {
  110. play(id, i) {
  111. this.currentId = id
  112. // 获取当前播放视频 元素距离顶部的高度
  113. if (this.height == 0) {
  114. uni.createSelectorQuery().select('.col').boundingClientRect((res) => {
  115. this.height = res.height
  116. this.scrollTop = res.height * (i + .5)
  117. }).exec()
  118. } else {
  119. this.scrollTop = this.height * (i + .5)
  120. }
  121. },
  122. getList(isPage) {
  123. var that = this;
  124. if (that.loadend) return;
  125. if (that.loading) return;
  126. if (isPage === true) {
  127. that.list = [];
  128. that.where.page =1;
  129. }
  130. this.$request.post('goods.video', that.where).then(res => {
  131. if (res.errno == 0) {
  132. that.list = that.list.concat(res.data.data);
  133. that.loadend = that.list.length < that.where.limit;
  134. that.loading = false;
  135. that.where.page = that.where.page + 1
  136. }
  137. })
  138. }
  139. },
  140. /**
  141. * 页面相关事件处理函数--监听用户下拉动作
  142. */
  143. onPullDownRefresh: function() {
  144. this.where.page = 1;
  145. this.loadend = false;
  146. this.list = [];
  147. this.getList();
  148. uni.stopPullDownRefresh();
  149. },
  150. /**
  151. * 页面上拉触底事件的处理函数
  152. */
  153. onReachBottom: function() {
  154. this.getList();
  155. }
  156. }
  157. </script>
  158. <style lang="scss">
  159. page {
  160. background-color: #ed6980;
  161. }
  162. .container {
  163. padding-bottom: 168rpx;
  164. }
  165. .content {
  166. padding: 30rpx;
  167. }
  168. .col {
  169. overflow: hidden;
  170. position: relative;
  171. overflow: hidden;
  172. padding: 25rpx;
  173. background-color: #ffffff;
  174. border-radius: 20rpx;
  175. margin-bottom: 30rpx;
  176. .videoimgbox {
  177. display: flex;
  178. flex-flow: row;
  179. .imgbox {
  180. margin-left: 25rpx;
  181. display: flex;
  182. flex-flow: column;
  183. .goods-image {
  184. border-radius: 10rpx;
  185. width: 217rpx;
  186. height: 217rpx;
  187. }
  188. }
  189. }
  190. }
  191. </style>