index.vue 5.0 KB

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