You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
2.0 KiB

4 years ago
  1. <template>
  2. <view class="mix-product-detail-swiper">
  3. <swiper
  4. class="swiper"
  5. circular
  6. autoplay
  7. interval="80000"
  8. @change="onSwiperChange"
  9. >
  10. <swiper-item class="item" v-for="(item, index) in renderList" :key="index" >
  11. <view class="image-wrapper lazyload lazypic" :class="{loaded: item.loaded}">
  12. <image
  13. :src="item.src"
  14. mode="aspectFill"
  15. @load="imageOnLoad(item)"
  16. @click="previewImage(index)"
  17. ></image>
  18. </view>
  19. </swiper-item>
  20. </swiper>
  21. <view class="dots row center">
  22. <view class="dot" :class="{current: current === index}" v-for="(item, index) in renderList" :key="index"></view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. /**
  28. * 商品详情页 顶部轮播图
  29. */
  30. export default {
  31. name: 'MixProductDetailSwiper',
  32. data() {
  33. return {
  34. current: 0,
  35. renderList: []
  36. };
  37. },
  38. props: {
  39. list: {
  40. type: Array,
  41. default(){
  42. return []
  43. }
  44. }
  45. },
  46. watch: {
  47. list(list){
  48. this.renderList = list.map(src=>{
  49. return {
  50. loaded: !!this.loaded,
  51. src
  52. }
  53. });
  54. this.loaded = true;
  55. }
  56. },
  57. methods: {
  58. onSwiperChange(e){
  59. this.current = e.detail.current;
  60. },
  61. previewImage(current){
  62. uni.previewImage({
  63. current,
  64. urls: this.list
  65. })
  66. },
  67. imageOnLoad(data, key){
  68. setTimeout(()=>{
  69. this.$set(data, 'loaded', true);
  70. }, 100)
  71. }
  72. }
  73. }
  74. </script>
  75. <style scoped lang="scss">
  76. .mix-product-detail-swiper{
  77. position: relative;
  78. }
  79. .swiper{
  80. width: 750rpx;
  81. height: 750rpx;
  82. }
  83. .image-wrapper{
  84. flex-shrink: 0;
  85. width: 750rpx;
  86. height: 750rpx;
  87. margin-right: 20rpx;
  88. overflow: hidden;
  89. image{
  90. width: 100%;
  91. height: 100%;
  92. }
  93. }
  94. .dots{
  95. position: absolute;
  96. left: 0;
  97. bottom: 12rpx;
  98. width: 100%;
  99. }
  100. .dot{
  101. width: 32rpx;
  102. height: 8rpx;
  103. margin: 0 6rpx;
  104. background-color: #fff;
  105. border-radius: 10px;
  106. &.current{
  107. background-color: $base-color;
  108. }
  109. }
  110. </style>