ThreeItemSwiper.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <view class="custom-swiper-wrapper">
  3. <swiper class="custom-swiper" :current="activeIndex" @change="onSwiperChange" circular :duration="300"
  4. indicator-dots="false" autoplay="false" display-multiple-items="1" :previous-margin="outerMargin"
  5. :next-margin="outerMargin" indicator-color="rgba(255, 255, 255, 0.5)" indicator-active-color="#FFEB66">
  6. <swiper-item v-for="(item, index) in (products||[])" :key="index">
  7. <view class="item-container">
  8. <view class="swiper-item" :class="{ 'swiper-item-active': index === currentCenterIndex }">
  9. <image class="item-image" :src="item.imgUrl" mode="aspectFit"></image>
  10. <view class="item-text" v-if="index === currentCenterIndex">
  11. <view class="text-title">{{ item.prizeLevel }}等奖</view>
  12. <view class="text-desc">{{ item.productName }}</view>
  13. </view>
  14. </view>
  15. </view>
  16. </swiper-item>
  17. </swiper>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. props: {
  23. products: {
  24. type: Array,
  25. default:() => [],
  26. }
  27. },
  28. data() {
  29. return {
  30. activeIndex: 0, // 初始激活项索引(建议从1开始,避免循环时偏移)
  31. outerMargin: '120rpx', // 轮播左右外部间距
  32. };
  33. },
  34. computed: {
  35. currentCenterIndex() {
  36. if (this.products.length === 0) return 0;
  37. return this.activeIndex % this.products.length;
  38. }
  39. },
  40. methods: {
  41. onSwiperChange(e) {
  42. this.activeIndex = e.detail.current;
  43. },
  44. },
  45. };
  46. </script>
  47. <style scoped>
  48. .custom-swiper-wrapper {
  49. width: 100%;
  50. overflow: hidden;
  51. }
  52. .custom-swiper {
  53. width: 100%;
  54. height: 500rpx;
  55. }
  56. .item-container {
  57. padding: 0 20rpx;
  58. }
  59. .swiper-item {
  60. width: 100% !important;
  61. height: 348rpx;
  62. background: #FFFFFF;
  63. box-shadow: 0rpx 12rpx 19rpx 2rpx rgba(219, 73, 22, 0.6);
  64. border-radius: 24rpx;
  65. border: 4rpx solid #FFCA96;
  66. display: flex;
  67. flex-direction: column;
  68. align-items: center;
  69. box-sizing: border-box;
  70. padding: 20rpx 0;
  71. transition: all 0.3s ease;
  72. }
  73. .swiper-item-active {
  74. transition: all 0.5s ease;
  75. height: 420rpx;
  76. z-index: 10;
  77. }
  78. .item-image {
  79. width: 280rpx;
  80. height: 280rpx;
  81. }
  82. .item-text {
  83. text-align: center;
  84. }
  85. .text-title {
  86. font-weight: 500;
  87. font-size: 32rpx;
  88. color: #222222;
  89. margin: 20rpx 0 10rpx;
  90. }
  91. .text-desc {
  92. font-size: 24rpx;
  93. color: #757575;
  94. }
  95. </style>