| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <template>
- <view>
-
-
-
- <view class="tab flex-n plr-50" :style="{background:bgcolor,width:'calc('+ width +' - 99rpx)'}" :class="shadow?'shadow-2':''">
- <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}"
- @click="click(index)">
- <view class="text flex-n">
- <view class="color_point" v-if="colorList.length>0" :style="{background:colorList[index]}"></view>
- {{item}}
- <view class="dot" v-if="showdot"></view>
- </view>
- </view>
- <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'}">
- <view class="underline" :style="{background:linecolor}"></view>
- </view>
- </view>
-
- <view style="height: 98rpx"></view>
- </view>
- </template>
- <script>
- export default {
- name: "z-tabs",
- props: {
- tabs: Array,
- width:{
- type: Number|String,
- default: '100%',
- },
- value: {
- type: Number,
- default: 0
- },
- colorList:{
- type:Array,
- default:()=>[]
- },
- shadow: Boolean,
- bgcolor: {
- type: String,
- default: '#354054'
- },
- showdot: Boolean,
- textcolor: {
- type: String,
- default: '#737985'
- },
- textSize: {
- type: String,
- default: '28rpx'
- },
- textselectedSize: {
- type: String,
- default: '32rpx'
- },
- textselectedcolor: {
- type: String,
- default: 'white'
- },
- linecolor: {
- type: String,
- default: '#0075FF'
- },
- },
- model: {
- prop: 'value'
- },
- data() {
- return {
- idx: 0,
- }
- },
- watch:{
- value(newval,oldval){
- this.idx =newval;
- }
- },
- mounted() {
- this.idx = this.value;
- console.log(this.value)
- },
- methods: {
- click(idx) {
- console.log(idx)
- if (this.idx != idx) {
- this.idx = idx;
- }
- this.$emit('change', idx)
- this.$emit('input', idx)
- }
- }
- }
- </script>
- <style scoped lang="scss">
- .tab {
- height: 98rpx;
- line-height: 98rpx;
- position: fixed;
- // width: calc(100% - 100rpx);
- z-index: 333;
-
- .item {
- text-align: center;
- .text {
- position: relative;
- width: fit-content;
- }
- .dot {
- position: absolute;
- width: 10rpx;
- height: 10rpx;
- border-radius: 5rpx;
- background: #ff0000;
- right: -15rpx;
- top: 20rpx;
- }
- }
- .slide {
- position: absolute;
- width: 100%;
- bottom: 0;
- .underline {
- width: 140rpx;
- height: 10rpx;
- }
- }
- }
- .color_point{
- width: 20rpx;
- height: 20rpx;
- border-radius: 10rpx;
- margin-top:40rpx;
- margin-right: 10rpx;
- }
- </style>
|