index.vue 4.1 KB

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