@kaiyinchem/ky-uniui 1.1.11 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/ky-tab.vue +56 -28
- package/package.json +1 -1
package/components/ky-tab.vue
CHANGED
|
@@ -10,9 +10,10 @@
|
|
|
10
10
|
card: type === 'card',
|
|
11
11
|
'white-bg': !noBg
|
|
12
12
|
}"
|
|
13
|
+
:id="`ky-tab-wrap-${id}`"
|
|
13
14
|
class="ky-tab-wrap"
|
|
14
15
|
>
|
|
15
|
-
<view
|
|
16
|
+
<view class="ky-tab-components">
|
|
16
17
|
<view class="ky-tab-box">
|
|
17
18
|
<view
|
|
18
19
|
v-for="(tab, i) in menu"
|
|
@@ -29,7 +30,12 @@
|
|
|
29
30
|
</view>
|
|
30
31
|
<view
|
|
31
32
|
v-if="tabItemWidth > 0 && !hasIcon"
|
|
32
|
-
:style="{
|
|
33
|
+
:style="{
|
|
34
|
+
left: tabItemOffsetLeft + 'px',
|
|
35
|
+
width: tabItemWidth + 'px',
|
|
36
|
+
height: tabItemHeight + 'px',
|
|
37
|
+
'background-color': activeColor
|
|
38
|
+
}"
|
|
33
39
|
class="ky-tab-slider"
|
|
34
40
|
>
|
|
35
41
|
</view>
|
|
@@ -42,6 +48,10 @@
|
|
|
42
48
|
emits: ['update:value', 'change'],
|
|
43
49
|
props: {
|
|
44
50
|
// 显示字体图标传入icon: '\'
|
|
51
|
+
id: {
|
|
52
|
+
type: [String, Number],
|
|
53
|
+
default: 1
|
|
54
|
+
},
|
|
45
55
|
menu: {
|
|
46
56
|
type: Array,
|
|
47
57
|
default: () => [],
|
|
@@ -98,6 +108,7 @@
|
|
|
98
108
|
return {
|
|
99
109
|
tabItemOffsetLeft: 0,
|
|
100
110
|
tabItemWidth: 0,
|
|
111
|
+
tabItemHeight: 2,
|
|
101
112
|
tabIndex: 0,
|
|
102
113
|
}
|
|
103
114
|
},
|
|
@@ -123,27 +134,43 @@
|
|
|
123
134
|
},
|
|
124
135
|
methods: {
|
|
125
136
|
onTabClick(item, index) {
|
|
137
|
+
this.$nextTick(() => {
|
|
138
|
+
const query = uni.createSelectorQuery().in(this)
|
|
139
|
+
query.select(`#ky-tab-wrap-${this.id}`).boundingClientRect()
|
|
140
|
+
query.select(`#ky_tab_${index}`).boundingClientRect()
|
|
141
|
+
query.exec(data => {
|
|
142
|
+
const parent = data[0]
|
|
143
|
+
const tab = data[1]
|
|
144
|
+
this.tabItemWidth = tab.width
|
|
145
|
+
this.tabItemOffsetLeft = tab.left - parent.left
|
|
146
|
+
if (this.type === 'card') {
|
|
147
|
+
this.tabItemHeight = tab.height
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
})
|
|
126
151
|
if (this.disabled) {
|
|
127
152
|
return
|
|
128
153
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
154
|
+
if (this.tabIndex === index) {
|
|
155
|
+
return
|
|
156
|
+
}
|
|
157
|
+
this.tabIndex = index
|
|
158
|
+
this.$emit('change', index)
|
|
159
|
+
this.$emit('update:value', index)
|
|
160
|
+
// tabEl.boundingClientRect(data => {
|
|
161
|
+
// console.log(data)
|
|
162
|
+
// this.tabItemWidth = data.width
|
|
163
|
+
// this.tabItemOffsetLeft = data.left
|
|
164
|
+
// if (this.type === 'card') {
|
|
165
|
+
// this.tabItemHeight = data.height
|
|
166
|
+
// }
|
|
167
|
+
// if (this.tabIndex === index) {
|
|
168
|
+
// return
|
|
169
|
+
// }
|
|
170
|
+
// this.tabIndex = index
|
|
171
|
+
// this.$emit('change', index)
|
|
172
|
+
// this.$emit('update:value', index)
|
|
173
|
+
// }).exec()
|
|
147
174
|
}
|
|
148
175
|
}
|
|
149
176
|
}
|
|
@@ -184,13 +211,12 @@
|
|
|
184
211
|
justify-content: center;
|
|
185
212
|
border-right: 1px solid var(--color-primary);
|
|
186
213
|
box-sizing: border-box;
|
|
187
|
-
&:last-child {
|
|
188
|
-
border-right: 0;
|
|
189
|
-
}
|
|
190
214
|
&.active {
|
|
191
|
-
background: var(--color-primary);
|
|
192
215
|
color: #ffffff;
|
|
193
216
|
}
|
|
217
|
+
&:last-child {
|
|
218
|
+
border-right: 0;
|
|
219
|
+
}
|
|
194
220
|
}
|
|
195
221
|
}
|
|
196
222
|
}
|
|
@@ -223,6 +249,8 @@
|
|
|
223
249
|
margin: 0 12rpx;
|
|
224
250
|
padding: 15rpx 0;
|
|
225
251
|
transition: all 0.3s;
|
|
252
|
+
position: relative;
|
|
253
|
+
z-index: 1;
|
|
226
254
|
color: var(--color-gray);
|
|
227
255
|
&.active {
|
|
228
256
|
font-weight: bold;
|
|
@@ -247,11 +275,11 @@
|
|
|
247
275
|
.ky-tab-slider {
|
|
248
276
|
position: absolute;
|
|
249
277
|
background-color: var(--color-primary);
|
|
250
|
-
height:
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
bottom: 0;
|
|
278
|
+
height: 0;
|
|
279
|
+
width: 0;
|
|
280
|
+
bottom: 1px;
|
|
254
281
|
transition: all 0.3s;
|
|
282
|
+
z-index: -1;
|
|
255
283
|
}
|
|
256
284
|
}
|
|
257
285
|
}
|