tui-swiper-dot.vue
3.41 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<template>
<view v-if="type==1 || type==2" class="tui-swiper__dot" :style="{left:left,bottom:bottom}">
<view class="tui-dot__item" :class="{'tui-text__center':type==2}"
:style="{width:index==current?width:height,height:height,borderRadius:radius,backgroundColor:index==current?getActiveBgColor:backgroundColor,margin:margin,color:current==index?color:activeColor,fontSize:size+'rpx'}"
v-for="(item,index) in countArr" :key="index">{{type==2?index+1:''}}</view>
</view>
<view class="tui-swiper__dot" :style="{width:type==4?width:'100%', right:right,bottom:bottom}" v-else>
<view class="tui-dot__item"
:style="{width:width,height:height,padding:padding,color:color,backgroundColor:backgroundColor,fontSize:size+'rpx'}"
v-if="type==3"><text class="tui-nav__ellipsis">{{currentTitle}}</text></view>
<view class="tui-dot__item tui-text__center"
:style="{width:width,height:height,borderRadius:radius,backgroundColor:backgroundColor,color:color,fontSize:size+'rpx'}"
v-if="type==4">{{current+1}}/{{count}}</view>
</view>
</template>
<script>
export default {
name: "tuiSwiperDot",
props: {
//显示类型:1-dot 2-index 3-title 4-右侧停靠index
type: {
type: Number,
default: 1
},
//总数
count: {
type: Number,
default: 0
},
//当前索引
current: {
type: Number,
default: 0
},
//当前标题
currentTitle: {
type: String,
default: ""
},
//left值
left: {
type: String,
default: "0"
},
right: {
type: String,
default: "auto"
},
bottom: {
type: String,
default: "30rpx"
},
//指示点[type in (1,2)]或外层盒子[type in (3,4)]宽度
width: {
type: String,
default: "16rpx"
},
//指示点[type in (1,2)]或外层盒子[type in (3,4)]高度
height: {
type: String,
default: "16rpx"
},
//指示点圆角
radius: {
type: String,
default: "50%"
},
//背景色
backgroundColor: {
type: String,
default: "#bfbfbf"
},
//当前展示item背景色
activeBgColor: {
type: String,
default: ""
},
//字体颜色
color: {
type: String,
default: "#333"
},
//当前展示item字体颜色,type=2时生效
activeColor: {
type: String,
default: "#fff"
},
//字体大小
size: {
type: Number,
default: 28
},
//指示点margin值
margin: {
type: String,
default: "0 8rpx"
},
//type=3时生效
padding: {
type: String,
default: "0 30rpx"
}
},
watch: {
count(val) {
this.countArr = this.generateArray(1, val)
}
},
computed:{
getActiveBgColor(){
return this.activeBgColor || (uni && uni.$tui && uni.$tui.color.primary) || '#5677fc'
}
},
data() {
return {
//百度小程序循环数字有问题
countArr: []
};
},
created() {
this.countArr = this.generateArray(1, this.count)
},
methods: {
generateArray: function(start, end) {
return Array.from(new Array(end + 1).keys()).slice(start);
}
}
}
</script>
<style scoped>
.tui-swiper__dot {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
position: absolute;
z-index: 2;
}
.tui-dot__item {
flex-shrink: 0;
display: flex;
align-items: center;
box-sizing: border-box;
}
.tui-nav__ellipsis {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.tui-text__center {
justify-content: center;
}
</style>