index1.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="MenuTab">
  3. <!-- 第一层tab -->
  4. <view class="menuBox">
  5. <!-- <view v-for="item in firstList" :key="item.id" :class="{active:activeId ===item.id}"
  6. @click="handleSelect(item.id)">
  7. {{item.name}}
  8. </view>
  9. <i :class="['custom-icon', 'custom-icon-all', {active:activeId ===-1}]" @click="handleSelect(-1)"></i> -->
  10. <u-tabs :list="firstList">
  11. <view slot="right" style="padding-left: 4px;" @tap="$u.toast('插槽被点击')">
  12. <i class="custom-icon custom-icon-all" @click="handleSelect(-1)"></i>
  13. </view>
  14. </u-tabs>
  15. </view>
  16. <!-- 第二层tab -->
  17. <view class="subMenuBox" v-show="show">
  18. <view class="subTitle">所有分类</view>
  19. <view class="subMenu">
  20. <view v-for="item in secondList" :key="item.id" @click="handleSelectTab(item.id)">
  21. {{item.name}}
  22. </view>
  23. </view>
  24. <!-- <u-tabs :list="secondList" @click="handleSelectTab" :activeStyle="{color: '#303133',fontWeight: 'bold',transform: 'scale(1.05)'}"></u-tabs> -->
  25. </view>
  26. <!-- 遮罩层 -->
  27. <view class="overlay" v-show="show"></view>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. data() {
  33. return {
  34. // 第一层tab
  35. firstList: [{
  36. id: 1,
  37. name: "全部"
  38. },
  39. {
  40. id: 2,
  41. name: "推荐"
  42. },
  43. {
  44. id: 3,
  45. name: "泰兴"
  46. },
  47. {
  48. id: 4,
  49. name: "科技"
  50. },
  51. {
  52. id: 5,
  53. name: "生活"
  54. },{
  55. id: 5,
  56. name: "生活"
  57. },{
  58. id: 5,
  59. name: "生活"
  60. },{
  61. id: 5,
  62. name: "生活"
  63. },{
  64. id: 5,
  65. name: "生活"
  66. },
  67. ],
  68. secondList: [{
  69. id: 1,
  70. name: "全部"
  71. },
  72. {
  73. id: 2,
  74. name: "推荐"
  75. },
  76. {
  77. id: 3,
  78. name: "泰兴"
  79. },
  80. {
  81. id: 4,
  82. name: "科技"
  83. },
  84. {
  85. id: 5,
  86. name: "生活"
  87. },
  88. {
  89. id: 6,
  90. name: "金融"
  91. },
  92. {
  93. id: 7,
  94. name: "其他"
  95. }
  96. ],
  97. activeId: 1,
  98. show: false,
  99. }
  100. },
  101. methods: {
  102. open() {
  103. // console.log('open');
  104. },
  105. close() {
  106. this.show = false
  107. // console.log('close');
  108. },
  109. change(index) {
  110. this.current = index;
  111. },
  112. // 选中第一层的tab
  113. handleSelect(id) {
  114. console.log(id)
  115. this.activeId = id
  116. if (id === -1) {
  117. this.show = !this.show
  118. } else {
  119. this.show = false
  120. }
  121. },
  122. // 选中第二层tab
  123. handleSelectTab() {
  124. this.show = false
  125. }
  126. }
  127. }
  128. </script>
  129. <style lang="scss">
  130. .MenuTab {
  131. position: relative;
  132. height: 80rpx;
  133. line-height: 80rpx;
  134. z-index: 2;
  135. .menuBox {
  136. display: flex;
  137. justify-content: space-between;
  138. align-items: center;
  139. padding: 0 40rpx;
  140. }
  141. .active {
  142. font-size: 40rpx;
  143. font-weight: bold;
  144. }
  145. .subMenuBox {
  146. width: 100%;
  147. position: absolute;
  148. left: 0;
  149. top: 100%;
  150. z-index: 10;
  151. background-color: #fff;
  152. box-shadow: 0 12rpx 24rpx rgba(0, 0, 0, 0.175);
  153. border-radius: 0 0 20rpx 20rpx;
  154. padding: 50rpx 40rpx;
  155. .subTitle {
  156. font-size: 40rpx;
  157. margin-bottom: 50rpx;
  158. font-weight: 600;
  159. }
  160. .subMenu {
  161. display: flex;
  162. justify-content: space-between;
  163. align-items: center;
  164. }
  165. }
  166. .overlay {
  167. width: 100%;
  168. // 高度是减去了页面 上padding20 头部100 搜索88和上下margin40 tab80
  169. height: calc(100vh - 20rpx - 100rpx - (88rpx + 40rpx) - 80rpx);
  170. background-color: rgba(0, 0, 0, 0.5);
  171. }
  172. }
  173. </style>