index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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">
  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. videoPause(e){
  84. // #ifdef APP-PLUS
  85. this.isPlay= true
  86. this.autoplay = true
  87. // #endif
  88. },
  89. bindPause: function() {
  90. // #ifndef APP-PLUS
  91. this.videoContext.play();
  92. this.$set(this, 'controls', false)
  93. this.autoplay = false
  94. // #endif
  95. // #ifdef APP-PLUS
  96. this.isPlay= false
  97. this.videoContext = uni.createVideoContext('myVideo', this);
  98. this.videoContext.play();
  99. // #endif
  100. },
  101. change: function(e) {
  102. this.$set(this, 'currents', e.detail.current + 1);
  103. }
  104. }
  105. }
  106. </script>
  107. <style scoped lang="scss">
  108. .product-bg {
  109. width: 100%;
  110. height: 750rpx;
  111. position: relative;
  112. }
  113. .product-bg swiper {
  114. width: 100%;
  115. height: 100%;
  116. position: relative;
  117. }
  118. .product-bg .slide-image {
  119. width: 100%;
  120. height: 100%;
  121. }
  122. .product-bg .pages {
  123. position: absolute;
  124. background-color: #fff;
  125. height: 34rpx;
  126. padding: 0 10rpx;
  127. border-radius: 3rpx;
  128. right: 30rpx;
  129. bottom: 30rpx;
  130. line-height: 34rpx;
  131. font-size: 24rpx;
  132. color: #050505;
  133. }
  134. #myVideo {
  135. width: 100%;
  136. height: 100%
  137. }
  138. .product-bg .item {
  139. position: relative;
  140. width: 100%;
  141. height: 100%;
  142. }
  143. .product-bg .item .poster {
  144. position: absolute;
  145. top: 0;
  146. left: 0;
  147. height: 750rpx;
  148. width: 100%;
  149. z-index: 9;
  150. }
  151. .product-bg .item .poster .image {
  152. width: 100%;
  153. height: 100%;
  154. }
  155. .product-bg .item .stop {
  156. position: absolute;
  157. top: 50%;
  158. left: 50%;
  159. width: 136rpx;
  160. height: 136rpx;
  161. margin-top: -68rpx;
  162. margin-left: -68rpx;
  163. z-index: 9;
  164. }
  165. .product-bg .item .stop .image {
  166. width: 100%;
  167. height: 100%;
  168. }
  169. </style>