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