tabNav.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <view class="navTabBox">
  3. <view class="longTab">
  4. <scroll-view scroll-x="true" style="white-space: nowrap; display: flex;" scroll-with-animation :scroll-left="tabLeft" show-scrollbar="true">
  5. <view
  6. class="longItem" :style='"width:"+isWidth+"px"'
  7. :data-index="index"
  8. :class="index===tabClick?'click':''"
  9. v-for="(item,index) in tabTitle"
  10. :key="index" :id="'id'+index"
  11. @click="longClick(tabClick,index)">
  12. <view>{{item.title}}</view>
  13. <!-- <view class="tab">{{item.content}}</view> -->
  14. <!-- <view class="lines"></view> -->
  15. </view>
  16. <view class="underlineBox" :style='"transform:translateX("+isLeft+"px);width:"+isWidth+"px"'>
  17. <view class="underline"></view>
  18. </view>
  19. </scroll-view>
  20. </view>
  21. <!--
  22. <view class="child-box" v-if="tabClick>0 && tabTitle[tabClick].children.length>0">
  23. <scroll-view scroll-x="true" style="white-space: nowrap; display: flex;align-items: center; height: 100%;" scroll-with-animation :scroll-left="tabLeft" show-scrollbar="false">
  24. <view class="wrapper">
  25. <view v-for="(item,index) in tabTitle[tabClick].children" class="child-item" :class="{on:index == childIndex}" @click="childTab(tabClick,index)">
  26. <image :src="item.pic" mode=""></image>
  27. <view class="txt">{{item.cate_name}}</view>
  28. </view>
  29. </view>
  30. </scroll-view>
  31. </view>-->
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. name: 'navTab',
  37. props: {
  38. tabTitle: {
  39. type: Array,
  40. default: []
  41. }
  42. },
  43. data() {
  44. return {
  45. tabClick: 0, //导航栏被点击
  46. isLeft: 0, //导航栏下划线位置
  47. isWidth: 0, //每个导航栏占位
  48. tabLeft:0,
  49. swiperIndex:0,
  50. childIndex:0,
  51. childID:0
  52. };
  53. },
  54. created() {
  55. var that = this
  56. // 获取设备宽度
  57. uni.getSystemInfo({
  58. success(e) {
  59. that.isWidth = e.windowWidth /4
  60. }
  61. })
  62. },
  63. methods: {
  64. // 导航栏点击
  65. longClick(tabClick,index){
  66. this.childIndex = 0;
  67. if(this.tabTitle.length>5){
  68. var tempIndex = index - 2;
  69. tempIndex = tempIndex<=0 ? 0 : tempIndex;
  70. this.tabLeft = (index-2) * this.isWidth //设置下划线位置
  71. }
  72. this.tabClick = index //设置导航点击了哪一个
  73. this.isLeft = index * this.isWidth //设置下划线位置
  74. let obj = {
  75. type:'big', //大标题
  76. index:index
  77. }
  78. this.childTab(tabClick,index)
  79. //this.parentEmit(obj)
  80. // this.$parent.currentTab = index //设置swiper的第几页
  81. },
  82. // 导航子类点击
  83. childTab(tabClick,index){
  84. this.childIndex = index
  85. let obj = {
  86. parentIndex:tabClick,
  87. childIndex:index,
  88. type:'small' //小标题
  89. }
  90. this.parentEmit(obj)
  91. },
  92. parentEmit(data){
  93. this.$emit('changeTab', data);
  94. }
  95. }
  96. }
  97. </script>
  98. <style lang="scss">
  99. .navTabBox {
  100. width: 100%;
  101. color: #333333;
  102. .tab{
  103. width: 80%;
  104. overflow: hidden;
  105. margin: 0rpx auto;
  106. text-align: center;
  107. color: #b1b1b1;
  108. font-size: 26rpx;
  109. line-height: 44rpx;
  110. border-radius: 22rpx;
  111. }
  112. .click {
  113. color: #E83323;
  114. .tab{
  115. overflow: hidden;
  116. text-align: center;
  117. background: #E83323;
  118. line-height: 44rpx;
  119. border-radius: 22rpx;
  120. color: #fff;
  121. }
  122. }
  123. .longTab {
  124. width: 100%;
  125. padding-top: 12rpx;
  126. padding-bottom: 0rpx;
  127. background-color: #fff;
  128. // .longItem:nth-child(5){
  129. // margin-left: 30rpx;
  130. // }
  131. // .longItem:nth-child(6){
  132. // margin-left: 30rpx;
  133. // }
  134. .longItem{
  135. height: 77upx;
  136. display: inline-block;
  137. line-height: 77upx;
  138. text-align: center;
  139. font-size: 30rpx;
  140. position: relative;
  141. .lines{
  142. position: absolute;
  143. width: 2rpx;
  144. height: 60rpx;
  145. right: 2rpx;
  146. top: 18rpx;
  147. background: #333;
  148. }
  149. &.click{
  150. }
  151. }
  152. .underlineBox {
  153. height: 3px;
  154. width: 30%;
  155. display: flex;
  156. align-content: center;
  157. justify-content: center;
  158. transition: .5s;
  159. .underline {
  160. width: 33rpx;
  161. height: 4rpx;
  162. background-color: #E83323;
  163. }
  164. }
  165. // scroll-view ::-webkit-scrollbar {
  166. //     width: 0;
  167. //     height: 0;
  168. //     background-color: transparent;
  169. // }
  170. }
  171. }
  172. .child-box{
  173. width: 100%;
  174. position: relative;
  175. // height: 152rpx;
  176. background-color: #fff;
  177. /* #ifdef H5 */
  178. box-shadow: 0 2px 5px 1px rgba(0, 0, 0, 0.02);
  179. /* #endif */
  180. /* #ifdef MP */
  181. box-shadow: 0 2rpx 3rpx 1rpx #f9f9f9;
  182. /* #endif */
  183. .wrapper{
  184. display: flex;
  185. align-items: center;
  186. padding: 20rpx 0;
  187. background: #fff;
  188. /* #ifdef H5 */
  189. //box-shadow: 0 2px 5px 1px rgba(0, 0, 0, 0.06);
  190. /* #endif */
  191. }
  192. .child-item{
  193. flex-shrink: 0;
  194. width:140rpx;
  195. display: flex;
  196. flex-direction: column;
  197. align-items: center;
  198. justify-content: center;
  199. margin-left: 10rpx;
  200. image{
  201. width: 90rpx;
  202. height: 90rpx;
  203. border-radius: 50%;
  204. }
  205. .txt{
  206. font-size: 24rpx;
  207. color: #282828;
  208. text-align: center;
  209. margin-top: 10rpx;
  210. }
  211. &.on{
  212. image{
  213. border: 1px solid #e2e2e2;
  214. }
  215. .txt{
  216. color: #333;
  217. }
  218. }
  219. }
  220. }
  221. </style>