tui-segmented-control.vue
2.83 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<template>
<view class="tui-segmented__control" :class="{'tui-segmented__disabled':disabled}">
<view class="tui-segmented__item" v-for="(item,index) in values" :key="index"
:style="{borderTopLeftRadius:index===0?radius:'0',borderBottomLeftRadius:index===0?radius:'0',borderTopRightRadius:index===values.length - 1?radius:'0',borderBottomRightRadius:index===values.length - 1?radius:'0',borderColor:getActiveColor,backgroundColor:currentIndex===index?getActiveColor:'transparent',height:height}"
:class="{'tui-segmented__first':index===0}" @click="handleClick(index)">
<text :style="{fontSize:size,color:currentIndex===index?'#fff':getActiveColor}">{{item}}</text>
</view>
</view>
</template>
<script>
export default {
name: "tui-segmented-control",
emits: ['click'],
props: {
values: {
type: Array,
default () {
return []
}
},
current: {
type: Number,
default: 0
},
activeColor: {
type: String,
default: ''
},
height: {
type: String,
default: '56rpx'
},
//字体大小
size: {
type: String,
default: '28rpx'
},
radius: {
type: String,
default: '4px'
},
disabled: {
type: Boolean,
default: false
}
},
computed:{
getActiveColor(){
return this.activeColor || (uni && uni.$tui && uni.$tui.color.primary) || '#5677fc'
}
},
data() {
return {
currentIndex: 0
};
},
watch: {
current(val) {
if (val !== this.currentIndex) {
this.currentIndex = val
}
}
},
created() {
this.currentIndex = this.current
},
methods: {
handleClick(index) {
if (this.currentIndex !== index && !this.disabled) {
this.currentIndex = index
this.$emit('click', {
index: index
})
}
}
}
}
</script>
<style scoped>
.tui-segmented__control {
flex: 1;
/* #ifndef APP-NVUE */
width: 100%;
display: flex;
box-sizing: border-box;
/* #endif */
flex-direction: row;
overflow: hidden;
/* #ifdef H5 */
cursor: pointer;
/* #endif */
}
.tui-segmented__item {
/* #ifndef APP-NVUE */
display: inline-flex;
box-sizing: border-box;
transition: all 0.1s linear;
/* #endif */
flex: 1;
justify-content: center;
align-items: center;
border-style: solid;
border-left-width: 0;
/* #ifdef APP-NVUE */
border-top-width: 0.5px;
border-bottom-width: 0.5px;
border-right-width: 0.5px;
/* #endif */
/* #ifndef APP-NVUE */
border-top-width: 1px;
border-bottom-width: 1px;
border-right-width: 1px;
/* #endif */
position: relative;
}
.tui-segmented__disabled {
opacity: 0.5;
/* #ifdef H5 */
cursor: not-allowed !important;
/* #endif */
}
.tui-segmented__first {
border-left-style: solid;
/* #ifndef APP-NVUE */
border-left-width:1px;
/* #endif */
/* #ifdef APP-NVUE */
border-left-width: 0.5px;
/* #endif */
}
</style>