ProductConSwiper.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. <swiperSlide
  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. </swiperSlide>
  29. </swiper>
  30. <div class="videoBox" v-show="isOnPlay">
  31. <video
  32. ref="videoIds"
  33. :poster="imgUrls[0]"
  34. class="video-source"
  35. loop=""
  36. controls
  37. style="width:100%;object-fit:fill"
  38. preload="auto"
  39. x-webkit-airplay="true"
  40. x5-video-player-fullscreen="true"
  41. x5-video-orientation="portraint"
  42. x5-video-player-type=""
  43. :src="videolines"
  44. @pause="endVideo"
  45. >
  46. 您的浏览器可能不支持视频播放
  47. </video>
  48. </div>
  49. <div class="pages">{{ currents || 1 }}/{{ imgUrls.length || 1 }}</div>
  50. </div>
  51. </template>
  52. <script>
  53. import { swiper, swiperSlide } from "vue-awesome-swiper";
  54. import "@assets/css/swiper.min.css";
  55. let vm = null;
  56. export default {
  57. name: "ProductConSwiper",
  58. components: {
  59. swiper,
  60. swiperSlide
  61. },
  62. props: {
  63. imgUrls: {
  64. type: Array,
  65. default: () => []
  66. },
  67. videoline: {
  68. type: String,
  69. default: () => ""
  70. }
  71. },
  72. watch: {
  73. videoline: {
  74. handler(newName) {
  75. this.videolines = newName;
  76. },
  77. deep: true
  78. }
  79. },
  80. data: function() {
  81. let that = this;
  82. return {
  83. videolines: this.videoline,
  84. mobile: "",
  85. isOnPlay: false,
  86. currents: 1,
  87. ProductConSwiper: {
  88. // autoplay: {
  89. // disableOnInteraction: false,
  90. // delay: 2000
  91. // },
  92. loop: true,
  93. speed: 1000,
  94. observer: true,
  95. observeParents: true,
  96. on: {
  97. slideChangeTransitionStart: function() {
  98. that.currents = this.realIndex + 1;
  99. if (that.mobile === "iPhone") {
  100. const oDiv = that.$refs.videoIds;
  101. oDiv.pause();
  102. }
  103. },
  104. tap: function() {
  105. const realIndex = this.realIndex;
  106. if (realIndex === 0) {
  107. vm.videoPlay();
  108. }
  109. }
  110. }
  111. }
  112. };
  113. },
  114. mounted: function() {},
  115. created() {
  116. vm = this;
  117. if (navigator.platform.indexOf("Win") !== -1) this.mobile = "iPhone";
  118. },
  119. methods: {
  120. endVideo() {
  121. this.isOnPlay = false;
  122. const oDiv = this.$refs.videoIds;
  123. oDiv.pause();
  124. },
  125. videoPlay() {
  126. if (this.videolines) {
  127. this.isOnPlay = true;
  128. const oDiv = this.$refs.videoIds;
  129. oDiv.play();
  130. }
  131. }
  132. }
  133. };
  134. </script>
  135. <style scoped>
  136. .videoBox {
  137. position: fixed;
  138. z-index: 999;
  139. top: 0;
  140. width: 100%;
  141. height: 100%;
  142. }
  143. .videoBox video {
  144. width: 100%;
  145. height: 100%;
  146. }
  147. .video-source {
  148. width: 100%;
  149. height: 100%;
  150. }
  151. .video_play {
  152. position: absolute;
  153. width: 1rem;
  154. height: 1rem;
  155. left: 45%;
  156. top: 45%;
  157. z-index: 11;
  158. }
  159. </style>