|
|
@@ -1,36 +1,20 @@
|
|
|
<template>
|
|
|
- <view
|
|
|
- class="uv-subsection"
|
|
|
- ref="uv-subsection"
|
|
|
- :class="[`uv-subsection--${mode}`]"
|
|
|
+ <view class="uv-subsection" ref="uv-subsection" :class="[`uv-subsection--${mode}`]"
|
|
|
:style="[$uv.addStyle(customStyle), wrapperStyle]">
|
|
|
- <view
|
|
|
- class="uv-subsection__bar"
|
|
|
- ref="uv-subsection__bar"
|
|
|
- :style="[barStyle]"
|
|
|
- :class="[
|
|
|
+ <view class="uv-subsection__bar" ref="uv-subsection__bar" :style="[barStyle]" :class="[
|
|
|
mode === 'button' && 'uv-subsection--button__bar',
|
|
|
current === 0 && mode === 'subsection' && 'uv-subsection__bar--first',
|
|
|
current > 0 && current < list.length - 1 && mode === 'subsection' && 'uv-subsection__bar--center',
|
|
|
current === list.length - 1 && mode === 'subsection' && 'uv-subsection__bar--last'
|
|
|
- ]"
|
|
|
- ></view>
|
|
|
- <view class="uv-subsection__item"
|
|
|
- :class="[
|
|
|
+ ]"></view>
|
|
|
+ <view class="uv-subsection__item" :class="[
|
|
|
`uv-subsection__item--${index}`,
|
|
|
index < list.length - 1 && 'uv-subsection__item--no-border-right',
|
|
|
index === 0 && 'uv-subsection__item--first',
|
|
|
index === list.length - 1 && 'uv-subsection__item--last'
|
|
|
- ]"
|
|
|
- :ref="`uv-subsection__item--${index}`"
|
|
|
- :style="[itemStyle(index)]"
|
|
|
- @tap="clickHandler(index)"
|
|
|
- v-for="(item, index) in list"
|
|
|
- :key="index"
|
|
|
- >
|
|
|
- <text
|
|
|
- class="uv-subsection__item__text"
|
|
|
- :style="[textStyle(index)]">{{ getText(item) }}
|
|
|
+ ]" :ref="`uv-subsection__item--${index}`" :style="[itemStyle(index)]" @tap="clickHandler(index)"
|
|
|
+ v-for="(item, index) in list" :key="index">
|
|
|
+ <text class="uv-subsection__item__text" :style="[textStyle(index)]">{{ getText(item) }}
|
|
|
</text>
|
|
|
</view>
|
|
|
</view>
|
|
|
@@ -77,7 +61,7 @@
|
|
|
watch: {
|
|
|
list: {
|
|
|
deep: true,
|
|
|
- handler(){
|
|
|
+ handler() {
|
|
|
this.init();
|
|
|
}
|
|
|
},
|
|
|
@@ -116,6 +100,7 @@
|
|
|
const style = {};
|
|
|
style.width = `${this.itemRect.width}px`;
|
|
|
style.height = `${this.itemRect.height}px`;
|
|
|
+ style.backgroundColor = this.barBg
|
|
|
// 通过translateX移动滑块,其移动的距离为索引*item的宽度
|
|
|
// #ifndef APP-NVUE
|
|
|
style.transform = `translateX(${ this.current * this.itemRect.width }px)`;
|
|
|
@@ -191,6 +176,7 @@
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
@import '@/uni_modules/uv-ui-tools/libs/css/components.scss';
|
|
|
+
|
|
|
.uv-subsection {
|
|
|
@include flex;
|
|
|
position: relative;
|
|
|
@@ -198,6 +184,7 @@
|
|
|
/* #ifndef APP-NVUE */
|
|
|
width: 100%;
|
|
|
box-sizing: border-box;
|
|
|
+
|
|
|
/* #endif */
|
|
|
&--button {
|
|
|
height: 32px;
|
|
|
@@ -205,19 +192,23 @@
|
|
|
padding: 3px;
|
|
|
border-radius: 3px;
|
|
|
align-items: stretch;
|
|
|
+
|
|
|
&__bar {
|
|
|
background-color: #ffffff;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
&--subsection {
|
|
|
height: 30px;
|
|
|
}
|
|
|
+
|
|
|
&__bar {
|
|
|
position: absolute;
|
|
|
/* #ifndef APP-NVUE */
|
|
|
transition-property: transform, color;
|
|
|
transition-duration: 0.3s;
|
|
|
transition-timing-function: ease-in-out;
|
|
|
+
|
|
|
/* #endif */
|
|
|
&--first {
|
|
|
border-top-left-radius: 3px;
|
|
|
@@ -225,12 +216,14 @@
|
|
|
border-top-right-radius: 0px;
|
|
|
border-bottom-right-radius: 0px;
|
|
|
}
|
|
|
+
|
|
|
&--center {
|
|
|
border-top-left-radius: 0px;
|
|
|
border-bottom-left-radius: 0px;
|
|
|
border-top-right-radius: 0px;
|
|
|
border-bottom-right-radius: 0px;
|
|
|
}
|
|
|
+
|
|
|
&--last {
|
|
|
border-top-left-radius: 0px;
|
|
|
border-bottom-left-radius: 0px;
|
|
|
@@ -238,6 +231,7 @@
|
|
|
border-bottom-right-radius: 3px;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
&__item {
|
|
|
// background-color: rgba(100,158,72,0.25);
|
|
|
@include flex;
|
|
|
@@ -246,17 +240,21 @@
|
|
|
align-items: center;
|
|
|
// vue环境下,需要设置相对定位,因为滑块为绝对定位,item需要在滑块的上面
|
|
|
position: relative;
|
|
|
+
|
|
|
&--no-border-right {
|
|
|
border-right-width: 0 !important;
|
|
|
}
|
|
|
+
|
|
|
&--first {
|
|
|
border-top-left-radius: 3px;
|
|
|
border-bottom-left-radius: 3px;
|
|
|
}
|
|
|
+
|
|
|
&--last {
|
|
|
border-top-right-radius: 3px;
|
|
|
border-bottom-right-radius: 3px;
|
|
|
}
|
|
|
+
|
|
|
&__text {
|
|
|
font-size: 12px;
|
|
|
line-height: 12px;
|