You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
4.3 KiB

3 months ago
  1. <template>
  2. <view class='product-bg'>
  3. <swiper :indicator-dots="indicatorDots" :indicator-active-color="indicatorBg" :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="cover" 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="urlDomain+'crmebimage/perset/staticImg/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="urlDomain+'crmebimage/perset/staticImg/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. import {setThemeColor} from '@/utils/setTheme.js'
  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. urlDomain: this.$Cache.get("imgHost"),
  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. indicatorBg:'#e93323',
  75. };
  76. },
  77. created(){
  78. let that = this;
  79. that.indicatorBg = setThemeColor();
  80. },
  81. mounted() {
  82. if(this.videoline){
  83. this.imgUrls.shift()
  84. }
  85. // #ifndef APP-PLUS
  86. this.videoContext = uni.createVideoContext('myVideo', this);
  87. // #endif
  88. },
  89. methods: {
  90. videoPause(e){
  91. // #ifdef APP-PLUS
  92. this.isPlay= true
  93. this.autoplay = true
  94. // #endif
  95. },
  96. bindPause: function() {
  97. // #ifndef APP-PLUS
  98. this.videoContext.play();
  99. this.$set(this, 'controls', false)
  100. this.autoplay = false
  101. // #endif
  102. // #ifdef APP-PLUS
  103. this.isPlay= false
  104. this.videoContext = uni.createVideoContext('myVideo', this);
  105. this.videoContext.play();
  106. // #endif
  107. },
  108. change: function(e) {
  109. this.$set(this, 'currents', e.detail.current + 1);
  110. }
  111. }
  112. }
  113. </script>
  114. <style scoped lang="scss">
  115. .product-bg {
  116. width: 100%;
  117. height: 750rpx;
  118. position: relative;
  119. }
  120. .product-bg swiper {
  121. width: 100%;
  122. height: 100%;
  123. position: relative;
  124. }
  125. .product-bg .slide-image {
  126. width: 100%;
  127. height: 100%;
  128. }
  129. .product-bg .pages {
  130. position: absolute;
  131. background-color: #fff;
  132. height: 34rpx;
  133. padding: 0 10rpx;
  134. border-radius: 3rpx;
  135. right: 30rpx;
  136. bottom: 30rpx;
  137. line-height: 34rpx;
  138. font-size: 24rpx;
  139. color: #050505;
  140. }
  141. #myVideo {
  142. width: 100%;
  143. height: 100%
  144. }
  145. .product-bg .item {
  146. position: relative;
  147. width: 100%;
  148. height: 100%;
  149. }
  150. .product-bg .item .poster {
  151. position: absolute;
  152. top: 0;
  153. left: 0;
  154. height: 750rpx;
  155. width: 100%;
  156. z-index: 9;
  157. }
  158. .product-bg .item .poster .image {
  159. width: 100%;
  160. height: 100%;
  161. }
  162. .product-bg .item .stop {
  163. position: absolute;
  164. top: 50%;
  165. left: 50%;
  166. width: 136rpx;
  167. height: 136rpx;
  168. margin-top: -68rpx;
  169. margin-left: -68rpx;
  170. z-index: 9;
  171. }
  172. .product-bg .item .stop .image {
  173. width: 100%;
  174. height: 100%;
  175. }
  176. </style>