product-swiper.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view class="swiper-wrap">
  3. <swiper class="swiper" ref="swiper" :autoplay="autoplay" :circular="circular"
  4. :interval="interval" :duration="duration" @change="swiperChange">
  5. <swiper-item v-if="video">
  6. <view class="video-wrap">
  7. <j-video :url="video" height="750rpx" width="750rpx" :poster="poster"></j-video>
  8. </view>
  9. </swiper-item>
  10. <block v-for="(item, index) in urls" :key="index">
  11. <swiper-item @tap="previewImage(index)">
  12. <u-image width="100%" height="750rpx" :src="item.url" :borderRadius="borderRadius"></u-image>
  13. </swiper-item>
  14. </block>
  15. </swiper>
  16. <view class="dots black sm bg-white br60">{{currentSwiper + 1}}/{{swiperLength}}</view>
  17. </view>
  18. </template>
  19. <script>
  20. var app = getApp();
  21. export default {
  22. data() {
  23. return {
  24. currentSwiper: 0,
  25. urls: [],
  26. showPlay: true,
  27. showControls: false,
  28. };
  29. },
  30. props: {
  31. imgUrls: {
  32. type: Array,
  33. default: () => [],
  34. },
  35. circular: {
  36. type: Boolean,
  37. default: true,
  38. },
  39. interval: {
  40. type: Number,
  41. default: 3000,
  42. },
  43. duration: {
  44. type: Number,
  45. default: 500,
  46. },
  47. video: {
  48. type: String,
  49. },
  50. autoplay: {
  51. type: Boolean,
  52. default: true
  53. },
  54. borderRadius: {
  55. type: [Number, String],
  56. default: 0,
  57. }
  58. },
  59. watch: {
  60. imgUrls: {
  61. handler(val) {
  62. this.urls = val.map(item => {
  63. return {
  64. url: item.uri || item.image,
  65. }
  66. });
  67. },
  68. immediate: true
  69. },
  70. },
  71. methods: {
  72. swiperChange(e) {
  73. this.currentSwiper = e.detail.current
  74. },
  75. previewImage(current) {
  76. uni.previewImage({
  77. current,
  78. urls: this.imgUrls.map((item) => item.uri)
  79. })
  80. },
  81. },
  82. computed: {
  83. poster() {
  84. return this.urls[0] ? this.urls[0].url : ''
  85. },
  86. swiperLength() {
  87. let length = this.urls.length
  88. return this.video ? (++length) : length
  89. }
  90. }
  91. };
  92. </script>
  93. <style>
  94. .swiper-wrap {
  95. width: 100%;
  96. height: 750rpx;
  97. position: relative;
  98. }
  99. .swiper-wrap .swiper {
  100. width: 100%;
  101. height: 100%;
  102. position: relative;
  103. }
  104. .swiper-wrap .swiper .slide-image {
  105. width: 100%;
  106. height: 100%;
  107. }
  108. .swiper-wrap .dots {
  109. position: absolute;
  110. right: 24rpx;
  111. bottom: 24rpx;
  112. display: flex;
  113. height: 34rpx;
  114. padding: 0 15rpx;
  115. }
  116. .swiper-wrap .video-wrap {
  117. width: 100%;
  118. height: 100%;
  119. position: relative;
  120. overflow: hidden;
  121. }
  122. .swiper-wrap .my-video {
  123. width: 100%;
  124. height: 100%;
  125. }
  126. .swiper-wrap .icon-play {
  127. width: 90rpx;
  128. height: 90rpx;
  129. position: absolute;
  130. top: 50%;
  131. left: 50%;
  132. transform: translate(-50%, -50%);
  133. z-index: 999;
  134. }
  135. </style>