SlideImage.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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
  10. x5-playsinline playsinline x5-video-player-type="h5" x5-video-player-fullscreen x5-video-orientation="portrait"
  11. :enable-progress-gesture="false" @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: false, // 是否显示面板指示点
  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: 750rpx;
  92. height: 750rpx;
  93. // 主图视频
  94. .slide-video {
  95. width: 100%;
  96. height: 100%;
  97. .video {
  98. display: block;
  99. width: 100%;
  100. height: 100%;
  101. }
  102. }
  103. // 图片轮播
  104. .slide-image {
  105. position: relative;
  106. width: 100%;
  107. height: 100%;
  108. .image {
  109. display: block;
  110. width: 100%;
  111. height: 100%;
  112. }
  113. }
  114. }
  115. // swiper计数
  116. .swiper-count {
  117. position: absolute;
  118. right: 36rpx;
  119. bottom: 72rpx;
  120. padding: 2rpx 18rpx;
  121. background: rgba(0, 0, 0, 0.363);
  122. border-radius: 50rpx;
  123. color: #fff;
  124. font-size: 26rpx;
  125. }
  126. </style>