Menu.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view class="menu-list-box" v-if="carousel" :style="list.length <= menu ? `height:160rpx` : `height:320rpx`">
  3. <swiper
  4. class="menu-swiper-box"
  5. :style="list.length <= menu ? `height:160rpx` : `height:320rpx`"
  6. @change="onSwiper"
  7. circular
  8. :autoplay="false"
  9. :interval="3000"
  10. :duration="1000"
  11. >
  12. <swiper-item class="menu-swiper-item" v-for="(itemList, index) in carousel" :key="index" :style="list.length <= menu ? `height:200rpx` : `height:340rpx`">
  13. <view class="menu-tab-box">
  14. <view class="tab-list" v-for="item in itemList" :key="item.menuName" @tap="routerTo(item)">
  15. <image class="tab-img Shop-selector-circular" :style="{ width: imgW + 'rpx', height: imgW + 'rpx' }" :src="item.icon"></image>
  16. <text class="Shop-selector-rect">{{ item.menuName }}</text>
  17. </view>
  18. </view>
  19. </swiper-item>
  20. </swiper>
  21. <view class="menu-dots" v-if="carousel.length > 1">
  22. <text :class="menuCurrent === index ? 'dot-active' : 'dot'" v-for="(dot, index) in carousel.length" :key="index"></text>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. components: {},
  29. data() {
  30. return {
  31. menuCurrent: 0 //轮播下标
  32. };
  33. },
  34. props: {
  35. list: {
  36. type: Array,
  37. default: []
  38. },
  39. menu: {
  40. default: 4
  41. },
  42. imgW: {
  43. type: Number,
  44. default: 88
  45. }
  46. },
  47. computed: {
  48. carousel() {
  49. if (this.list) {
  50. let data = this.sortData(this.list, this.menu * 2);
  51. return data;
  52. }
  53. }
  54. },
  55. created() {},
  56. methods: {
  57. // 数据分层
  58. sortData(oArr, length) {
  59. let arr = [];
  60. let minArr = [];
  61. oArr.forEach(c => {
  62. if (minArr.length === length) {
  63. minArr = [];
  64. }
  65. if (minArr.length === 0) {
  66. arr.push(minArr);
  67. }
  68. minArr.push(c);
  69. });
  70. return arr;
  71. },
  72. // 轮播
  73. onSwiper(e) {
  74. this.menuCurrent = e.detail.current;
  75. },
  76. routerTo(item) {
  77. this.$emit('menuClick',item);
  78. }
  79. }
  80. };
  81. </script>
  82. <style lang="scss">
  83. .menu-list-box {
  84. padding: 0rpx;
  85. background: #fff;
  86. box-sizing: border-box;
  87. }
  88. .menu-list-box,
  89. .menu-swiper-box {
  90. position: relative;
  91. background: #fff;
  92. .menu-swiper-item {
  93. background: #fff;
  94. height: 100%;
  95. width: 100%;
  96. }
  97. .menu-tab-box {
  98. display: flex;
  99. flex-wrap: wrap;
  100. .tab-list {
  101. width: 25%;
  102. display: -webkit-box;
  103. display: -webkit-flex;
  104. display: flex;
  105. -webkit-box-orient: vertical;
  106. -webkit-box-direction: normal;
  107. -webkit-flex-direction: column;
  108. flex-direction: column;
  109. -webkit-box-align: center;
  110. -webkit-align-items: center;
  111. align-items: center;
  112. font-size: 22rpx;
  113. font-family: PingFang SC;
  114. font-weight: 500;
  115. color: rgba(51, 51, 51, 1);
  116. padding-bottom: 30rpx;
  117. .tab-img {
  118. border-radius: 25rpx;
  119. margin-bottom: 10rpx;
  120. }
  121. }
  122. }
  123. .menu-dots {
  124. display: flex;
  125. position: absolute;
  126. left: 50%;
  127. transform: translateX(-50%);
  128. .dot {
  129. width: 40rpx;
  130. height: 3rpx;
  131. background: #eeeeee;
  132. margin-right: 10rpx;
  133. }
  134. .dot-active {
  135. width: 40rpx;
  136. height: 3rpx;
  137. background: #018C39;
  138. margin-right: 10rpx;
  139. }
  140. }
  141. }
  142. </style>