home-menu.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <!--
  2. * @Author: jmy
  3. * @Date: 2026-01-04 12:02:41
  4. * @LastEditors: Please set LastEditors
  5. * @LastEditTime: 2026-01-04 15:02:20
  6. * @Description: 自定义轮播图组件
  7. -->
  8. <template>
  9. <swiper class="scs-swiper flex flex-nowrap mt-5" :style="{ height: height * 2 + 'rpx', }" :circular="circular"
  10. :indicator-dots="indicatorDots" indicator-active-color=""
  11. indicator-color="" :autoplay="autoplay" :interval="interval" :duration="duration" :current="current"
  12. :display-multiple-items='displayMultipleItems' :next-margin="nextMargin" @change="change"
  13. @transition="transition" @animationfinish="animationfinish">
  14. <swiper-item class="flex flex-wrap h-all w-all ml-4" v-for="(item, i) in swiperList" :key="i">
  15. <view class="item-navbar mr-22 w-52 flex flex-column items-center" @click="handleNavTo(value)"
  16. v-for="(value, i) in item" :key="i">
  17. <image class="w-44 h-44" :src="value.icon"> </image>
  18. <view class=" fs-13 fw-400 text-ellipsis mt-8">{{ value.menuName }}</view>
  19. </view>
  20. </swiper-item>
  21. </swiper>
  22. </template>
  23. <script>
  24. export default {
  25. props: {
  26. swiperList: {
  27. type: Array,
  28. default: () => []
  29. },
  30. // 轮播图高度rpx
  31. height: {
  32. type: Number,
  33. default: 76
  34. },
  35. // 是否显示指示器
  36. indicatorDots: {
  37. type: Boolean,
  38. default: false
  39. },
  40. // 是否循环播放
  41. circular: {
  42. type: Boolean,
  43. default: true
  44. },
  45. // 是否自动切换
  46. autoplay: {
  47. type: Boolean,
  48. default: true
  49. },
  50. // 自动切换时间间隔
  51. interval: {
  52. type: Number,
  53. default: 3000
  54. },
  55. // 切换动画时长
  56. duration: {
  57. type: Number,
  58. default: 1000
  59. },
  60. // 显示多个项
  61. displayMultipleItems: {
  62. type: Number,
  63. default: 1
  64. },
  65. // 下一个项的外边距
  66. nextMargin: {
  67. type: String,
  68. default: '0'
  69. },
  70. // 当前滑块显示项的索引
  71. current: {
  72. type: Number,
  73. default: 0
  74. },
  75. },
  76. methods: {
  77. // current 改变时会触发 change 事件
  78. change(e) {
  79. this.$emit('change', e.detail.current)
  80. },
  81. // swiper-item 的位置发生改变时会触发
  82. transition(e) {
  83. // console.log('transition:', e.detail)
  84. this.$emit('transition', e.detail.current)
  85. },
  86. // swiper-item 的位置发生改变并且动画结束时会触发
  87. animationfinish(e) {
  88. this.$emit('animationfinish', e.detail.current)
  89. },
  90. // 导航到对应页面
  91. handleNavTo(value) {
  92. // 根据实际需求实现导航逻辑
  93. console.log('导航到:', value)
  94. }
  95. }
  96. }
  97. </script>
  98. <style lang="scss" scoped>
  99. .scs-swiper {
  100. width: 100%;
  101. .item-navbar {
  102. &:nth-child(5n) {
  103. margin-right: 0;
  104. }
  105. }
  106. }
  107. </style>