index.vue 4.2 KB

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