subsection.vue
1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<template>
<div class="u-subsection" ref="container">
<div class="u-subsection-item" :class="{ active: index + 1 === value }" v-for="(item, index) in list" :key="index" @click="handleClick(index + 1)">
{{ item.label }}
</div>
<!-- 滑动高亮条 - 保持不变 -->
<div
class="slider"
:class="'slider-position-' + value"
:style="{
background: value === 1 ? '#ffd700' : '#32b92b',
}"
></div>
</div>
</template>
<script>
export default {
name: 'USubsection',
props: {
list: {
type: Array,
default: () => [],
},
value: {
type: Number,
default: 1,
},
},
methods: {
handleClick(val) {
this.$emit('input', val) // 保持v-model原有逻辑
this.$emit('tab-change', val) // 新增:派发自定义切换事件,携带选中值
},
},
}
</script>
<style scoped>
.u-subsection {
width: 16vw;
height: 3vw;
display: flex;
position: relative;
background: #e0e0e0;
border-radius: 0.6vw;
margin: 0;
overflow: hidden;
border: 0.12vw solid #3f3e3e;
box-shadow: 0.2vw 0.2vw 0.2vw #333, 0.3vw 0.3vw 1vw rgba(0, 0, 0, 0.3);
}
.u-subsection-item {
flex: 1;
padding: 0.5vw 0;
cursor: pointer;
font-size: 1vw;
color: #333;
position: relative;
z-index: 2;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
user-select: none;
}
.u-subsection-item.active {
color: #fff;
text-shadow: 0.1vw 0.1vw 0.2vw rgba(0, 0, 0, 0.3);
}
.slider {
width: 6.6vw;
height: 2.2vw;
position: absolute;
top: 0.3vw;
border-radius: 0.4vw;
z-index: 1;
box-shadow: 0 0.1vw 0.3vw rgba(0, 0, 0, 0.2);
transition: all 0.3s ease;
}
/* 固定位置版本 */
.slider-position-1 {
left: 0.5vw;
width: 6.8vw;
background: #ffd700 !important; /* 强制黄色 */
}
.slider-position-2 {
left: 8.6vw;
width: 6.8vw;
background: #32b92b !important; /* 强制绿色 */
}
</style>