index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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="#e93323" :autoplay="autoplay" :circular="circular"
  15. :interval="interval" :duration="duration" @change="change" v-if="isPlay">
  16. <!-- #ifndef APP-PLUS -->
  17. <swiper-item v-if="videoline && videoline != '' && videoline != 'https:'">
  18. <view class="item">
  19. <video id="myVideo" :src='videoline && (videoline.substring(0,4) == "http" || videoline.substring(0,5) == "https") ? videoline : ("http:" + videoline)'
  20. objectFit="cover" controls style="width:100%;height:100% " show-mute-btn="true"
  21. auto-pause-if-navigate></video>
  22. <view class="poster" v-if="controls">
  23. <image class="image" :src="videoCoverImg"></image>
  24. </view>
  25. <view class="stop" v-if="controls" @tap="bindPause">
  26. <image class="image" src="../../static/images/stop.png"></image>
  27. </view>
  28. </view>
  29. </swiper-item>
  30. <!-- #endif -->
  31. <!-- #ifdef APP-PLUS -->
  32. <swiper-item v-if="videoline">
  33. <view class="item">
  34. <view class="poster" v-show="controls">
  35. <image class="image" :src="videoCoverImg"></image>
  36. </view>
  37. <view class="stop" v-show="controls" @tap="bindPause">
  38. <image class="image" src="../../static/images/stop.png"></image>
  39. </view>
  40. </view>
  41. </swiper-item>
  42. <!-- #endif -->
  43. <block v-for="(item,index) in imgUrls" :key='index'>
  44. <swiper-item>
  45. <image :src="item" class="slide-image" />
  46. </swiper-item>
  47. </block>
  48. </swiper>
  49. <!-- #ifdef APP-PLUS -->
  50. <view v-if="!isPlay" style="width: 100%; height: 750rpx;">
  51. <video id="myVideo" :src='videoline && (videoline.substring(0,4) == "http" || videoline.substring(0,5) == "https") ? videoline : "http:" + videoline'
  52. objectFit="cover" controls style="width:100%;height:100% " show-center-play-btn show-mute-btn="true"
  53. auto-pause-if-navigate :enable-progress-gesture="false" :poster="videoCoverImg" @pause="videoPause"></video>
  54. </view>
  55. <!-- #endif -->
  56. </view>
  57. </template>
  58. <script>
  59. // +----------------------------------------------------------------------
  60. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  61. // +----------------------------------------------------------------------
  62. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  63. // +----------------------------------------------------------------------
  64. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  65. // +----------------------------------------------------------------------
  66. // | Author: CRMEB Team <admin@crmeb.com>
  67. // +----------------------------------------------------------------------
  68. export default {
  69. props: {
  70. imgUrls: {
  71. type: Array,
  72. default: function() {
  73. return [];
  74. }
  75. },
  76. videoline: {
  77. type: String,
  78. value: ""
  79. },
  80. videoCoverImg: {
  81. type: String,
  82. }
  83. },
  84. data() {
  85. return {
  86. indicatorDots: true,
  87. circular: true,
  88. autoplay: true,
  89. interval: 5000,
  90. duration: 500,
  91. currents: "1",
  92. controls: true,
  93. isPlay: true,
  94. videoContext: ''
  95. };
  96. },
  97. created() {
  98. },
  99. watch: {
  100. },
  101. mounted() {
  102. // #ifndef APP-PLUS
  103. this.videoContext = uni.createVideoContext('myVideo', this);
  104. // #endif
  105. },
  106. methods: {
  107. videoPause(e) {
  108. // #ifdef APP-PLUS
  109. this.isPlay = true
  110. this.autoplay = true
  111. // #endif
  112. },
  113. bindPause: function() {
  114. // #ifndef APP-PLUS
  115. this.videoContext.play();
  116. this.$set(this, 'controls', false)
  117. this.autoplay = false
  118. // #endif
  119. // #ifdef APP-PLUS
  120. this.isPlay = false
  121. this.videoContext = uni.createVideoContext('myVideo', this);
  122. this.$nextTick(()=>{
  123. this.videoContext.play();
  124. })
  125. // #endif
  126. },
  127. change: function(e) {
  128. this.$set(this, 'currents', e.detail.current + 1);
  129. }
  130. }
  131. }
  132. </script>
  133. <style scoped lang="scss">
  134. .product-bg {
  135. width: 100%;
  136. height: 750rpx;
  137. position: relative;
  138. }
  139. .product-bg swiper {
  140. width: 100%;
  141. height: 100%;
  142. position: relative;
  143. }
  144. .product-bg .slide-image {
  145. width: 100%;
  146. height: 100%;
  147. }
  148. .product-bg .pages {
  149. position: absolute;
  150. background-color: #fff;
  151. height: 34rpx;
  152. padding: 0 10rpx;
  153. border-radius: 3rpx;
  154. right: 30rpx;
  155. bottom: 30rpx;
  156. line-height: 34rpx;
  157. font-size: 24rpx;
  158. color: #050505;
  159. }
  160. #myVideo {
  161. width: 100%;
  162. height: 100%
  163. }
  164. .product-bg .item {
  165. position: relative;
  166. width: 100%;
  167. height: 100%;
  168. }
  169. .product-bg .item .poster {
  170. position: absolute;
  171. top: 0;
  172. left: 0;
  173. height: 750rpx;
  174. width: 100%;
  175. z-index: 9;
  176. }
  177. .product-bg .item .poster .image {
  178. width: 100%;
  179. height: 100%;
  180. }
  181. .product-bg .item .stop {
  182. position: absolute;
  183. top: 50%;
  184. left: 50%;
  185. width: 136rpx;
  186. height: 136rpx;
  187. margin-top: -68rpx;
  188. margin-left: -68rpx;
  189. z-index: 9;
  190. }
  191. .product-bg .item .stop .image {
  192. width: 100%;
  193. height: 100%;
  194. }
  195. </style>