index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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-mute-btn="true"
  10. auto-pause-if-navigate @ended="endedFun()"></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" @click='getpreviewImage(item)' mode="widthFix" />
  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" @ended="endedFun()"></video>
  43. </view>
  44. <!-- #endif -->
  45. </view>
  46. </template>
  47. <script>
  48. // +----------------------------------------------------------------------
  49. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  50. // +----------------------------------------------------------------------
  51. // | Copyright (c) 2016~2024 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. getpreviewImage: function(item) {
  97. uni.previewImage({
  98. urls: this.imgUrls,
  99. current: item
  100. });
  101. },
  102. videoPause(e) {
  103. // #ifdef APP-PLUS
  104. this.isPlay = true
  105. this.autoplay = true
  106. // #endif
  107. },
  108. bindPause: function() {
  109. // #ifndef APP-PLUS
  110. this.videoContext.play();
  111. this.$set(this, 'controls', false)
  112. this.autoplay = false
  113. // #endif
  114. // #ifdef APP-PLUS
  115. this.isPlay = false
  116. this.videoContext = uni.createVideoContext('myVideo', this);
  117. this.$nextTick(()=>{
  118. this.videoContext.play();
  119. })
  120. // #endif
  121. },
  122. change: function(e) {
  123. this.$set(this, 'currents', e.detail.current + 1);
  124. },
  125. endedFun() {
  126. this.controls = true
  127. }
  128. }
  129. }
  130. </script>
  131. <style scoped lang="scss">
  132. .product-bg {
  133. width: 100%;
  134. height: 750rpx;
  135. position: relative;
  136. }
  137. .product-bg swiper {
  138. width: 100%;
  139. height: 100%;
  140. position: relative;
  141. }
  142. .product-bg .slide-image {
  143. width: 100%;
  144. height: 100%;
  145. }
  146. .product-bg .pages {
  147. position: absolute;
  148. background-color: #fff;
  149. height: 34rpx;
  150. padding: 0 10rpx;
  151. border-radius: 3rpx;
  152. right: 30rpx;
  153. bottom: 30rpx;
  154. line-height: 34rpx;
  155. font-size: 24rpx;
  156. color: #050505;
  157. }
  158. #myVideo {
  159. width: 100%;
  160. height: 100%
  161. }
  162. .product-bg .item {
  163. position: relative;
  164. width: 100%;
  165. height: 100%;
  166. }
  167. .product-bg .item .poster {
  168. position: absolute;
  169. top: 0;
  170. left: 0;
  171. height: 750rpx;
  172. width: 100%;
  173. z-index: 9;
  174. }
  175. .product-bg .item .poster .image {
  176. width: 100%;
  177. height: 100%;
  178. }
  179. .product-bg .item .stop {
  180. position: absolute;
  181. top: 50%;
  182. left: 50%;
  183. width: 136rpx;
  184. height: 136rpx;
  185. margin-top: -68rpx;
  186. margin-left: -68rpx;
  187. z-index: 9;
  188. }
  189. .product-bg .item .stop .image {
  190. width: 100%;
  191. height: 100%;
  192. }
  193. </style>