index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view class='product-bg'>
  3. <swiper :indicator-dots="indicatorDots" indicator-active-color="#e93323" :autoplay="autoplay"
  4. :circular="circular" :interval="interval" :duration="duration" @change="change">
  5. <swiper-item v-if="videoline">
  6. <view class="item">
  7. <view v-show="!controls" style="width:100%;height:100% ">
  8. <video id="myVideo" :src='videoline' objectFit="cover" controls style="width:100%;height:100% "
  9. show-center-play-btn show-mute-btn="true" auto-pause-if-navigate :custom-cache="false"
  10. :enable-progress-gesture="false" :poster="imgUrls[0]" @pause="videoPause"></video>
  11. </view>
  12. <view class="poster" v-show="controls">
  13. <image class="image" :src="imgUrls[0]"></image>
  14. </view>
  15. <view class="stop" v-show="controls" @tap="bindPause">
  16. <image class="image" src="@/static/images/stop.png"></image>
  17. </view>
  18. </view>
  19. </swiper-item>
  20. <block v-for="(item,index) in imgUrls" :key='index'>
  21. <swiper-item>
  22. <image :src="item" class="slide-image" />
  23. </swiper-item>
  24. </block>
  25. </swiper>
  26. </view>
  27. </template>
  28. <script setup>
  29. import { ref, onMounted } from 'vue';
  30. const props = defineProps({
  31. imgUrls: {
  32. type: Array,
  33. default: () => []
  34. },
  35. videoline: {
  36. type: String,
  37. default: ""
  38. }
  39. });
  40. const indicatorDots = ref(true);
  41. const circular = ref(true);
  42. const autoplay = ref(true);
  43. const interval = ref(3000);
  44. const duration = ref(500);
  45. const currents = ref("1");
  46. const controls = ref(true);
  47. const isPlay = ref(true);
  48. const videoContext = ref('');
  49. onMounted(() => {
  50. if (props.videoline) {
  51. props.imgUrls.shift();
  52. }
  53. });
  54. const bindPause = () => {
  55. videoContext.value.play();
  56. controls.value = false;
  57. autoplay.value = false;
  58. };
  59. const change = (e) => {
  60. currents.value = e.detail.current + 1;
  61. };
  62. const videoPause = (e) => {
  63. // Handle video pause event if needed
  64. };
  65. </script>
  66. <style scoped lang="scss">
  67. .product-bg {
  68. width: 100%;
  69. height: 750rpx;
  70. position: relative;
  71. }
  72. .product-bg swiper {
  73. width: 100%;
  74. height: 100%;
  75. position: relative;
  76. }
  77. .product-bg .slide-image {
  78. width: 100%;
  79. height: 100%;
  80. }
  81. .product-bg .pages {
  82. position: absolute;
  83. background-color: #fff;
  84. height: 34rpx;
  85. padding: 0 10rpx;
  86. border-radius: 3rpx;
  87. right: 30rpx;
  88. bottom: 30rpx;
  89. line-height: 34rpx;
  90. font-size: 24rpx;
  91. color: #050505;
  92. }
  93. #myVideo {
  94. width: 100%;
  95. height: 100%
  96. }
  97. .product-bg .item {
  98. position: relative;
  99. width: 100%;
  100. height: 100%;
  101. }
  102. .product-bg .item .poster {
  103. position: absolute;
  104. top: 0;
  105. left: 0;
  106. height: 750rpx;
  107. width: 100%;
  108. z-index: 9;
  109. }
  110. .product-bg .item .poster .image {
  111. width: 100%;
  112. height: 100%;
  113. }
  114. .product-bg .item .stop {
  115. position: absolute;
  116. top: 50%;
  117. left: 50%;
  118. width: 136rpx;
  119. height: 136rpx;
  120. margin-top: -68rpx;
  121. margin-left: -68rpx;
  122. z-index: 9;
  123. }
  124. .product-bg .item .stop .image {
  125. width: 100%;
  126. height: 100%;
  127. }
  128. </style>