index.vue 4.4 KB

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