|
@ -1,7 +1,7 @@ |
|
|
<template> |
|
|
<template> |
|
|
<view class="niu-x-tabs component"> |
|
|
<view class="niu-x-tabs component" :style="{opacity: isShow?1:0}" multiSlots> |
|
|
<!-- <view class="scroll-view"> --> |
|
|
<!-- <view class="scroll-view"> --> |
|
|
<scroll-view :show-scrollbar="false" class="scroll-view" :scroll-x='!full' :scroll-with-animation='true' :scroll-left="left"> |
|
|
<scroll-view :show-scrollbar="false" class="scroll-view" :scroll-x='!full' :scroll-with-animation='anim' :scroll-left="left"> |
|
|
<view class="niu-x-tabs__wrapper"> |
|
|
<view class="niu-x-tabs__wrapper"> |
|
|
<view class="niu-x-tabs__inner" :class="{full,capsule}" :style="{backgroundColor: bg, height: height}"> |
|
|
<view class="niu-x-tabs__inner" :class="{full,capsule}" :style="{backgroundColor: bg, height: height}"> |
|
|
<view class="niu-x-tabs__item" :class="[ |
|
|
<view class="niu-x-tabs__item" :class="[ |
|
@ -9,18 +9,22 @@ |
|
|
value==index?activeClass:normalClass |
|
|
value==index?activeClass:normalClass |
|
|
]" |
|
|
]" |
|
|
:style="[value==index?activeCustomStyle:normalCustomStyle, anim?{transition: '.3s linear'}:{}]" :key="index" v-for="(item,index) in list" @click="click(index,true)"> |
|
|
:style="[value==index?activeCustomStyle:normalCustomStyle, anim?{transition: '.3s linear'}:{}]" :key="index" v-for="(item,index) in list" @click="click(index,true)"> |
|
|
<slot :data="item" :pData="pData" :index="index"> |
|
|
<!-- 循环中使用slot会报警告,暂时去除,未找到处理办法 --> |
|
|
|
|
|
<!-- <slot :data="item" :pData="pData" :index="index"> --> |
|
|
<text>{{item[akey]}}</text> |
|
|
<text>{{item[akey]}}</text> |
|
|
<view v-if="value==index && activeImage" class="niu-x-tabs__bg"> |
|
|
<view v-if="value==index && activeImage" class="niu-x-tabs__bg"> |
|
|
<image class="image" :src="activeImage" mode="widthFix"></image> |
|
|
<image class="image" :src="activeImage" mode="widthFix"></image> |
|
|
</view> |
|
|
</view> |
|
|
</slot> |
|
|
<!-- </slot> --> |
|
|
</view> |
|
|
</view> |
|
|
<!-- {{ !!(value<list.length) }} --> |
|
|
<!-- {{ !!(value<list.length) }} --> |
|
|
<slot name="bar" |
|
|
<slot name="bar" |
|
|
:show="barIsShow" |
|
|
:show="barIsShow" |
|
|
|
|
|
:anim="anim" |
|
|
:barLeft="barLeft" |
|
|
:barLeft="barLeft" |
|
|
:barWidth="barWidth" |
|
|
:barWidth="barWidth" |
|
|
|
|
|
:item="list[value]" |
|
|
|
|
|
:props="{normalColor, activeColor}" |
|
|
> |
|
|
> |
|
|
<view v-if="bar&&value<list.length" class="niu-x-tabs__bar" :class="{capsule}" :style="[{left:barLeft + 'px',width:barWidth + 'px',backgroundColor: barColor},, anim?{transition: 'left .3s ease, width .3s ease'}:{}]"></view> |
|
|
<view v-if="bar&&value<list.length" class="niu-x-tabs__bar" :class="{capsule}" :style="[{left:barLeft + 'px',width:barWidth + 'px',backgroundColor: barColor},, anim?{transition: 'left .3s ease, width .3s ease'}:{}]"></view> |
|
|
</slot> |
|
|
</slot> |
|
@ -48,7 +52,7 @@ |
|
|
}, |
|
|
}, |
|
|
width: { |
|
|
width: { |
|
|
type: String, |
|
|
type: String, |
|
|
default: 'auto' |
|
|
default: '' |
|
|
}, |
|
|
}, |
|
|
height: { |
|
|
height: { |
|
|
type: String, |
|
|
type: String, |
|
@ -116,9 +120,10 @@ |
|
|
anim: false, |
|
|
anim: false, |
|
|
left: 0, |
|
|
left: 0, |
|
|
isRender: false, |
|
|
isRender: false, |
|
|
|
|
|
isShow: false, |
|
|
allLeft: [], |
|
|
allLeft: [], |
|
|
barLeft: 0, |
|
|
barLeft: 0, |
|
|
barWidth: 200, |
|
|
barWidth: 0, |
|
|
x_ml: 0 // 容器距离左侧屏幕的距离 |
|
|
x_ml: 0 // 容器距离左侧屏幕的距离 |
|
|
}; |
|
|
}; |
|
|
}, |
|
|
}, |
|
@ -144,11 +149,12 @@ |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
mounted() { |
|
|
mounted() { |
|
|
this.init() |
|
|
this.init(this.value) |
|
|
}, |
|
|
}, |
|
|
watch: { |
|
|
watch: { |
|
|
list(newValue, oldValue) { |
|
|
list(newValue, oldValue) { |
|
|
this.init() |
|
|
this.anim = false |
|
|
|
|
|
this.init(this.value) |
|
|
}, |
|
|
}, |
|
|
value(newValue, oldValue) { |
|
|
value(newValue, oldValue) { |
|
|
if (this.isRender) return |
|
|
if (this.isRender) return |
|
@ -169,8 +175,11 @@ |
|
|
return [v.left - this.x_ml, v.width] |
|
|
return [v.left - this.x_ml, v.width] |
|
|
}) |
|
|
}) |
|
|
this.isRender = false |
|
|
this.isRender = false |
|
|
this.clickHere(index) |
|
|
if(index < this.list.length){ |
|
|
this.left = index != 0 ? (this.allLeft[index][0]) : 0; |
|
|
this.clickHere(index) |
|
|
|
|
|
this.left = index != 0 ? (this.allLeft[index][0] - this.allLeft[index][1] * 2) : 0; |
|
|
|
|
|
} |
|
|
|
|
|
this.isShow = true |
|
|
setTimeout(()=>{ |
|
|
setTimeout(()=>{ |
|
|
this.anim = true |
|
|
this.anim = true |
|
|
},300) |
|
|
},300) |
|
@ -254,6 +263,7 @@ |
|
|
|
|
|
|
|
|
.niu-x-tabs__item { |
|
|
.niu-x-tabs__item { |
|
|
flex: 1; |
|
|
flex: 1; |
|
|
|
|
|
width: 0; |
|
|
text-align: center; |
|
|
text-align: center; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -297,7 +307,7 @@ |
|
|
position: absolute; |
|
|
position: absolute; |
|
|
bottom: 0; |
|
|
bottom: 0; |
|
|
left: 0; |
|
|
left: 0; |
|
|
width: 50rpx; |
|
|
width: 0; |
|
|
height: 2px; |
|
|
height: 2px; |
|
|
background-color: $themeColor; |
|
|
background-color: $themeColor; |
|
|
|
|
|
|
|
|