小程序端工程代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
3.2 KiB

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