z-tabs.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <view>
  3. <view class="tab flex-n plr-50" :style="{background:bgcolor,width:'calc('+ width +' - 99rpx)'}" :class="shadow?'shadow-2':''">
  4. <view class="flex-1 item flex-n fjc" v-for="(item,index) in tabs" :key="index" :style="{color:idx==index?textselectedcolor:textcolor,'font-size':idx==index?textselectedSize:textSize}"
  5. @click="click(index)">
  6. <view class="text flex-n">
  7. <view class="color_point" v-if="colorList.length>0" :style="{background:colorList[index]}"></view>
  8. {{item}}
  9. <view class="dot" v-if="showdot"></view>
  10. </view>
  11. </view>
  12. <view class="slide" :style="{'margin':'0 calc(((100% - 100rpx) / '+tabs.length+' - 140rpx) / 2)',transform: 'translateX(calc(((100% - 100rpx) / '+tabs.length+') * '+ idx+'))', 'transition-duration': '0.3s'}">
  13. <view class="underline" :style="{background:linecolor}"></view>
  14. </view>
  15. </view>
  16. <view style="height: 98rpx"></view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. name: "z-tabs",
  22. props: {
  23. tabs: Array,
  24. width:{
  25. type: Number|String,
  26. default: '100%',
  27. },
  28. value: {
  29. type: Number,
  30. default: 0
  31. },
  32. colorList:{
  33. type:Array,
  34. default:()=>[]
  35. },
  36. shadow: Boolean,
  37. bgcolor: {
  38. type: String,
  39. default: '#354054'
  40. },
  41. showdot: Boolean,
  42. textcolor: {
  43. type: String,
  44. default: '#737985'
  45. },
  46. textSize: {
  47. type: String,
  48. default: '28rpx'
  49. },
  50. textselectedSize: {
  51. type: String,
  52. default: '32rpx'
  53. },
  54. textselectedcolor: {
  55. type: String,
  56. default: 'white'
  57. },
  58. linecolor: {
  59. type: String,
  60. default: '#0075FF'
  61. },
  62. },
  63. model: {
  64. prop: 'value'
  65. },
  66. data() {
  67. return {
  68. idx: 0,
  69. }
  70. },
  71. watch:{
  72. value(newval,oldval){
  73. this.idx =newval;
  74. }
  75. },
  76. mounted() {
  77. this.idx = this.value;
  78. console.log(this.value)
  79. },
  80. methods: {
  81. click(idx) {
  82. console.log(idx)
  83. if (this.idx != idx) {
  84. this.idx = idx;
  85. }
  86. this.$emit('change', idx)
  87. this.$emit('input', idx)
  88. }
  89. }
  90. }
  91. </script>
  92. <style scoped lang="scss">
  93. .tab {
  94. height: 98rpx;
  95. line-height: 98rpx;
  96. position: fixed;
  97. // width: calc(100% - 100rpx);
  98. z-index: 333;
  99. .item {
  100. text-align: center;
  101. .text {
  102. position: relative;
  103. width: fit-content;
  104. }
  105. .dot {
  106. position: absolute;
  107. width: 10rpx;
  108. height: 10rpx;
  109. border-radius: 5rpx;
  110. background: #ff0000;
  111. right: -15rpx;
  112. top: 20rpx;
  113. }
  114. }
  115. .slide {
  116. position: absolute;
  117. width: 100%;
  118. bottom: 0;
  119. .underline {
  120. width: 140rpx;
  121. height: 10rpx;
  122. }
  123. }
  124. }
  125. .color_point{
  126. width: 20rpx;
  127. height: 20rpx;
  128. border-radius: 10rpx;
  129. margin-top:40rpx;
  130. margin-right: 10rpx;
  131. }
  132. </style>