home-hot.vue 4.3 KB

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