home-hot.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <!--
  2. * @Author: jmy
  3. * @Date: 2026-01-06 12:02:41
  4. * @LastEditors: Please set LastEditors
  5. * @LastEditTime: 2026-01-06 15:02:20
  6. * @Description: 自定义轮播图组件
  7. -->
  8. <template>
  9. <view class="w-all relative zi-2 mt-4">
  10. <swiper class="w-all" :style="{ height: height * 2 + 'rpx', }" :circular="circular"
  11. :indicator-dots="indicatorDots" indicator-active-color="#02B176 " indicator-color="#EEEEEE"
  12. :autoplay="autoplay" :interval="interval" :duration="duration" :current="current"
  13. :display-multiple-items='displayMultipleItems' :next-margin="nextMargin" @change="change"
  14. @transition="transition" @animationfinish="animationfinish">
  15. <swiper-item class="flex flex-wrap h-all " v-for="(item, index) in swiperList" :key="index">
  16. <view class="w-74 h-82 bg-white flex items-center justify-center">
  17. <view class="w-64 h-82 flex flex-column items-center justify-center">
  18. <view class="box">
  19. <image style="border: 1px solid #ffffff;"
  20. :src="item.imageUrl || item.img || 'https://img1.baidu.com/it/u=2172818577,3783888802&fm=253&app=138&f=JPEG?w=800&h=1422'"
  21. class="image" />
  22. </view>
  23. <view class="fs20 fw-500 text-D46C0D mt14">{{ item.rankText || '营养保健Top1' }}</view>
  24. <view class="w-54 h-16 rounded-16 text-D46C0D text-center fs-10 fw-400 relative">
  25. 热销{{ item.sales || '0' }}件
  26. <image src="https://cdn.his.cdwjyyh.com/images/hot_selling_list_img.png"
  27. class="w-8 h-12 absolute top-0 left--4 zi-10 rotateY-180" />
  28. <image src="https://cdn.his.cdwjyyh.com/images/hot_selling_list_img.png"
  29. class="w-8 h-12 absolute top-0 right--4 zi-10" />
  30. </view>
  31. </view>
  32. </view>
  33. </swiper-item>
  34. </swiper>
  35. <view class="flex items-center justify-center w-all gap-6 mt-11" v-if="isCustomDot">
  36. <view v-for="(item, index) in swiperList" :key="index" class="w-10 h-2 rounded-1"
  37. :class="index == current ? 'bg-02B176' : 'bg-EEEEEE'"></view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. props: {
  44. swiperList: {
  45. type: Array,
  46. default: () => []
  47. },
  48. // 轮播图高度rpx
  49. height: {
  50. type: Number,
  51. default: 85
  52. },
  53. // 是否显示指示器
  54. indicatorDots: {
  55. type: Boolean,
  56. default: false
  57. },
  58. // 是否循环播放
  59. circular: {
  60. type: Boolean,
  61. default: true
  62. },
  63. // 是否自动切换
  64. autoplay: {
  65. type: Boolean,
  66. default: false
  67. },
  68. // 自动切换时间间隔
  69. interval: {
  70. type: Number,
  71. default: 3000
  72. },
  73. // 切换动画时长
  74. duration: {
  75. type: Number,
  76. default: 1000
  77. },
  78. // 显示多个项
  79. displayMultipleItems: {
  80. type: Number,
  81. default: 2
  82. },
  83. // 下一个项的外边距
  84. nextMargin: {
  85. type: String,
  86. default: '0'
  87. },
  88. // 当前滑块显示项的索引
  89. current: {
  90. type: Number,
  91. default: 0
  92. },
  93. // 是否显示自定义指示点
  94. isCustomDot: {
  95. type: Boolean,
  96. default: false
  97. },
  98. },
  99. data() {
  100. return {
  101. currentDot: 0,
  102. }
  103. },
  104. methods: {
  105. // current 改变时会触发 change 事件
  106. change(e) {
  107. this.$emit('change', e.detail.current)
  108. },
  109. // swiper-item 的位置发生改变时会触发
  110. transition(e) {
  111. // console.log('transition:', e.detail)
  112. this.$emit('transition', e.detail.current)
  113. },
  114. // swiper-item 的位置发生改变并且动画结束时会触发
  115. animationfinish(e) {
  116. this.$emit('animationfinish', e.detail.current)
  117. },
  118. // 导航到对应页面
  119. handleNavTo(value) {
  120. // 根据实际需求实现导航逻辑
  121. console.log('导航到:', value)
  122. }
  123. }
  124. }
  125. </script>
  126. <style lang="scss" scoped>
  127. .image{
  128. width: 92rpx;
  129. height: 92rpx;
  130. flex-shrink: 0;
  131. }
  132. .box{
  133. width: 96rpx;
  134. height: 96rpx;
  135. background: #FFFFFF;
  136. box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(0,0,0,0.1);
  137. border-radius: 12rpx 12rpx 12rpx 12rpx;
  138. border: 2rpx solid #FFFFFF;
  139. overflow: hidden;
  140. }
  141. </style>