ProductConSwiper.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <div class="slider-banner product-bg">
  3. <swiper
  4. class="swiper-wrapper"
  5. :options="ProductConSwiper"
  6. v-if="imgUrls.length > 0"
  7. ref="mySwiper"
  8. >
  9. <swiper-slide
  10. class="swiper-slide"
  11. v-for="(item, index) in imgUrls"
  12. :key="index"
  13. ref="goodSwiper"
  14. >
  15. <div
  16. class="slide-image"
  17. :style="{
  18. background: 'url(' + item + ') no-repeat center center',
  19. 'background-size': '100% 100%'
  20. }"
  21. >
  22. <img
  23. src="../assets/images/videos.png"
  24. class="video_play"
  25. v-if="videolines && index === 0"
  26. />
  27. </div>
  28. </swiper-slide>
  29. </swiper>
  30. <!--<div :class="mobile === 'iPhone' ? 'videoBox' : ''" v-show="isOnPlay">-->
  31. <div class="videoBox" v-show="isOnPlay">
  32. <video
  33. ref="videoIds"
  34. :poster="imgUrls[0]"
  35. class="video-source"
  36. loop=""
  37. controls
  38. style="width:100%;object-fit:fill"
  39. preload="auto"
  40. x-webkit-airplay="true"
  41. x5-video-player-fullscreen="true"
  42. x5-video-orientation="portraint"
  43. x5-video-player-type=""
  44. :src="videolines"
  45. @pause="endVideo"
  46. >
  47. 您的浏览器可能不支持视频播放
  48. </video>
  49. </div>
  50. <div class="pages">{{ currents || 1 }}/{{ imgUrls.length || 1 }}</div>
  51. </div>
  52. </template>
  53. <script>
  54. import { swiper, swiperSlide } from "vue-awesome-swiper";
  55. import "@assets/css/swiper.min.css";
  56. let vm = null;
  57. export default {
  58. name: "ProductConSwiper",
  59. components: {
  60. swiper,
  61. swiperSlide
  62. },
  63. props: {
  64. imgUrls: {
  65. type: Array,
  66. default: () => []
  67. },
  68. videoline: {
  69. type: String,
  70. default: () => ""
  71. }
  72. },
  73. watch: {
  74. videoline: {
  75. handler(newName) {
  76. this.videolines = newName;
  77. },
  78. deep: true
  79. }
  80. },
  81. data: function() {
  82. let that = this;
  83. return {
  84. videolines: this.videoline,
  85. mobile: "",
  86. isOnPlay: false,
  87. currents: 1,
  88. ProductConSwiper: {
  89. // autoplay: {
  90. // disableOnInteraction: false,
  91. // delay: 2000
  92. // },
  93. loop: true,
  94. speed: 1000,
  95. observer: true,
  96. observeParents: true,
  97. autoplayDisableOnInteraction: false, // 这样,即使我们滑动之后, 定时器也不会被清除
  98. on: {
  99. slideChangeTransitionStart: function() {
  100. that.currents = this.realIndex + 1;
  101. if (that.mobile === "iPhone") {
  102. const oDiv = that.$refs.videoIds;
  103. oDiv.pause();
  104. }
  105. },
  106. tap: function() {
  107. const realIndex = this.realIndex;
  108. if (realIndex === 0) {
  109. vm.videoPlay();
  110. }
  111. }
  112. }
  113. }
  114. };
  115. },
  116. computed: {
  117. swiper() {
  118. return this.$refs.mySwiper.swiper;
  119. }
  120. },
  121. mounted: function() {},
  122. created() {
  123. vm = this;
  124. if (navigator.platform.indexOf("Win") !== -1) this.mobile = "iPhone";
  125. },
  126. methods: {
  127. endVideo() {
  128. this.isOnPlay = false;
  129. const oDiv = this.$refs.videoIds;
  130. oDiv.pause();
  131. },
  132. videoPlay() {
  133. if (this.videolines) {
  134. this.isOnPlay = true;
  135. const oDiv = this.$refs.videoIds;
  136. oDiv.play();
  137. }
  138. }
  139. }
  140. };
  141. </script>
  142. <style scoped>
  143. .videoBox {
  144. position: fixed;
  145. z-index: 999;
  146. top: 0;
  147. width: 100%;
  148. height: 100%;
  149. }
  150. .videoBox video {
  151. width: 100%;
  152. height: 100%;
  153. }
  154. .video-source {
  155. width: 100%;
  156. height: 100%;
  157. }
  158. .video_play {
  159. position: absolute;
  160. width: 1rem;
  161. height: 1rem;
  162. left: 45%;
  163. top: 45%;
  164. z-index: 11;
  165. }
  166. </style>