index.vue 4.6 KB

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