SlideImage.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <!-- 商品图片 -->
  3. <view class="images-swiper">
  4. <swiper class="swiper-box" :autoplay="autoplay" :duration="duration" :indicator-dots="indicatorDots"
  5. :interval="interval" :circular="true" @change="setCurrent">
  6. <!-- 主图视频 -->
  7. <swiper-item v-if="video">
  8. <view class="slide-video">
  9. <video id="myVideo" class="video" :poster="videoCover.preview_url" :src="video.external_url" controls
  10. x5-playsinline playsinline webkit-playsinline webkit-playsinline x5-video-player-type="h5"
  11. x5-video-player-fullscreen x5-video-orientation="portrait" :enable-progress-gesture="false"
  12. @play="onVideoPlay"></video>
  13. </view>
  14. </swiper-item>
  15. <!-- 轮播图片 -->
  16. <swiper-item v-for="(item, index) in images" :key="index" @click="onPreviewImages(index)">
  17. <view class="slide-image">
  18. <image class="image" :draggable="false" :src="item.preview_url"></image>
  19. </view>
  20. </swiper-item>
  21. </swiper>
  22. <view class="swiper-count">
  23. <text>{{ currentIndex }}</text>
  24. <text>/</text>
  25. <text>{{ images.length + (video ? 1 : 0) }}</text>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. props: {
  32. // 主图视频
  33. video: {
  34. type: Object,
  35. default () {
  36. return null
  37. }
  38. },
  39. // 主图视频封面
  40. videoCover: {
  41. type: Object,
  42. default () {
  43. return null
  44. }
  45. },
  46. // 图片轮播
  47. images: {
  48. type: Array,
  49. default: []
  50. }
  51. },
  52. data() {
  53. return {
  54. indicatorDots: true, // 是否显示面板指示点
  55. autoplay: true, // 是否自动切换
  56. interval: 4000, // 自动切换时间间隔
  57. duration: 800, // 滑动动画时长
  58. currentIndex: 1, // 轮播图指针
  59. }
  60. },
  61. methods: {
  62. // 事件:视频开始播放
  63. onVideoPlay(e) {
  64. this.autoplay = false
  65. },
  66. // 设置轮播图当前指针 数字
  67. setCurrent({ detail }) {
  68. const app = this
  69. app.currentIndex = detail.current + 1
  70. },
  71. // 浏览商品图片
  72. onPreviewImages(index) {
  73. const app = this
  74. const imageUrls = []
  75. app.images.forEach(item => {
  76. imageUrls.push(item.preview_url);
  77. });
  78. uni.previewImage({
  79. current: imageUrls[index],
  80. urls: imageUrls
  81. })
  82. }
  83. }
  84. }
  85. </script>
  86. <style lang="scss" scoped>
  87. // swiper组件
  88. .images-swiper {
  89. position: relative;
  90. }
  91. .swiper-box {
  92. width: 100%;
  93. height: 100vw;
  94. /* #ifdef H5 */
  95. max-width: 480px;
  96. max-height: 480px;
  97. margin: 0 auto;
  98. /* #endif */
  99. // 主图视频
  100. .slide-video {
  101. width: 100%;
  102. height: 100%;
  103. .video {
  104. display: block;
  105. width: 100%;
  106. height: 100%;
  107. }
  108. }
  109. // 图片轮播
  110. .slide-image {
  111. position: relative;
  112. width: 100%;
  113. height: 100%;
  114. .image {
  115. display: block;
  116. width: 100%;
  117. height: 100%;
  118. }
  119. }
  120. }
  121. // swiper计数
  122. .swiper-count {
  123. position: absolute;
  124. right: 36rpx;
  125. bottom: 72rpx;
  126. padding: 2rpx 18rpx;
  127. background: rgba(0, 0, 0, 0.363);
  128. border-radius: 50rpx;
  129. color: #fff;
  130. font-size: 26rpx;
  131. }
  132. </style>