index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <view class='product-bg'>
  3. <swiper :indicator-dots="indicatorDots" indicator-active-color="var(--view-theme)" :autoplay="autoplay"
  4. :circular="circular" :interval="interval" :duration="duration" @change="change" v-if="isPlay">
  5. <!-- #ifndef APP-PLUS -->
  6. <swiper-item v-if="videoline">
  7. <view class="item">
  8. <view v-show="!controls" style="width:100%;height:100% ">
  9. <video id="myVideo" :src='videoline' objectFit="contain" controls
  10. style="width:100%;height:100% " show-center-play-btn show-mute-btn="true"
  11. auto-pause-if-navigate :custom-cache="false" :enable-progress-gesture="false"
  12. :poster="imgUrls[0]" @pause="videoPause"></video>
  13. </view>
  14. <view class="poster" v-show="controls">
  15. <image class="image" :src="imgUrls[0]"></image>
  16. </view>
  17. <view class="stop" v-show="controls" @tap="bindPause">
  18. <image class="image" src="../../static/images/stop.png"></image>
  19. </view>
  20. </view>
  21. </swiper-item>
  22. <!-- #endif -->
  23. <!-- #ifdef APP-PLUS -->
  24. <swiper-item v-if="videoline">
  25. <view class="item">
  26. <view class="poster" v-show="controls">
  27. <image class="image" :src="imgUrls[0]"></image>
  28. </view>
  29. <view class="stop" v-show="controls" @tap="bindPause">
  30. <image class="image" src="../../static/images/stop.png"></image>
  31. </view>
  32. </view>
  33. </swiper-item>
  34. <!-- #endif -->
  35. <block v-for="(item,index) in imgUrls" :key='index'>
  36. <swiper-item v-if="videoline?index>=1:index>=0">
  37. <image :src="item" class="slide-image" />
  38. </swiper-item>
  39. </block>
  40. </swiper>
  41. <!-- #ifdef APP-PLUS -->
  42. <view v-if="!isPlay" style="width: 750rpx; height: 750rpx;">
  43. <video id="myVideo" class="goods-video" :src='videoline' controls show-center-play-btn show-mute-btn="true"
  44. autoplay="true" auto-pause-if-navigate :custom-cache="false" :enable-progress-gesture="false"
  45. :poster="imgUrls[0]" @pause="videoPause"></video>
  46. </view>
  47. <!-- #endif -->
  48. </view>
  49. </template>
  50. <script>
  51. export default {
  52. props: {
  53. imgUrls: {
  54. type: Array,
  55. default: function() {
  56. return [];
  57. }
  58. },
  59. videoline: {
  60. type: String,
  61. value: ""
  62. }
  63. },
  64. data() {
  65. return {
  66. indicatorDots: true,
  67. circular: true,
  68. autoplay: true,
  69. interval: 3000,
  70. duration: 500,
  71. currents: "1",
  72. controls: true,
  73. isPlay: true,
  74. videoContext: ''
  75. };
  76. },
  77. mounted() {
  78. if (this.videoline) {
  79. this.imgUrls.shift()
  80. }
  81. // #ifndef APP-PLUS
  82. this.videoContext = uni.createVideoContext('myVideo', this);
  83. // #endif
  84. },
  85. methods: {
  86. videoPause(e) {
  87. // #ifdef APP-PLUS
  88. this.isPlay = true
  89. this.autoplay = true
  90. // #endif
  91. },
  92. videoIsPause() {
  93. this.videoContext = uni.createVideoContext('myVideo', this);
  94. this.videoContext.pause();
  95. },
  96. bindPause: function() {
  97. // #ifndef APP-PLUS
  98. this.videoContext.play();
  99. this.$set(this, 'controls', false)
  100. this.autoplay = false
  101. // #endif
  102. // #ifdef APP-PLUS
  103. this.isPlay = false
  104. this.videoContext = uni.createVideoContext('myVideo', this);
  105. this.videoContext.play();
  106. // #endif
  107. },
  108. change: function(e) {
  109. this.$set(this, 'currents', e.detail.current + 1);
  110. }
  111. }
  112. }
  113. </script>
  114. <style scoped lang="scss">
  115. .product-bg {
  116. width: 100%;
  117. height: 750rpx;
  118. position: relative;
  119. }
  120. .product-bg swiper {
  121. width: 100%;
  122. height: 100%;
  123. position: relative;
  124. }
  125. .product-bg .slide-image {
  126. width: 100%;
  127. height: 100%;
  128. }
  129. .product-bg .pages {
  130. position: absolute;
  131. background-color: #fff;
  132. height: 34rpx;
  133. padding: 0 10rpx;
  134. border-radius: 3rpx;
  135. right: 30rpx;
  136. bottom: 30rpx;
  137. line-height: 34rpx;
  138. font-size: 24rpx;
  139. color: #050505;
  140. }
  141. #myVideo {
  142. width: 100%;
  143. height: 100%;
  144. }
  145. .goods-video{
  146. width: 100%;
  147. height: 100%;
  148. }
  149. .product-bg .item {
  150. position: relative;
  151. width: 100%;
  152. height: 100%;
  153. }
  154. .product-bg .item .poster {
  155. position: absolute;
  156. top: 0;
  157. left: 0;
  158. height: 750rpx;
  159. width: 100%;
  160. z-index: 9;
  161. }
  162. .product-bg .item .poster .image {
  163. width: 100%;
  164. height: 100%;
  165. }
  166. .product-bg .item .stop {
  167. position: absolute;
  168. top: 50%;
  169. left: 50%;
  170. width: 136rpx;
  171. height: 136rpx;
  172. margin-top: -68rpx;
  173. margin-left: -68rpx;
  174. z-index: 9;
  175. }
  176. .product-bg .item .stop .image {
  177. width: 100%;
  178. height: 100%;
  179. }
  180. </style>