SlideImage.vue 3.3 KB

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