@kaiyinchem/ky-uniui 1.1.12 → 1.1.14
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 +33 -35
- 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"
|
|
@@ -21,14 +22,14 @@
|
|
|
21
22
|
:class="{ active: i === tabIndex, icon: tab.icon }"
|
|
22
23
|
:id="'ky_tab_'+i"
|
|
23
24
|
class="ky-tab-item"
|
|
24
|
-
@click="onTabClick(
|
|
25
|
+
@click="onTabClick(i)"
|
|
25
26
|
>
|
|
26
27
|
<text v-if="tab.icon" class="ky-tab-icon iconfont">{{ tab.icon }}</text>
|
|
27
28
|
<text class="ky-tab-text">{{ tab[label] }}</text>
|
|
28
29
|
</view>
|
|
29
30
|
</view>
|
|
30
31
|
<view
|
|
31
|
-
v-if="tabItemWidth > 0
|
|
32
|
+
v-if="tabItemWidth > 0"
|
|
32
33
|
:style="{
|
|
33
34
|
left: tabItemOffsetLeft + 'px',
|
|
34
35
|
width: tabItemWidth + 'px',
|
|
@@ -47,6 +48,10 @@
|
|
|
47
48
|
emits: ['update:value', 'change'],
|
|
48
49
|
props: {
|
|
49
50
|
// 显示字体图标传入icon: '\'
|
|
51
|
+
id: {
|
|
52
|
+
type: [String, Number],
|
|
53
|
+
default: 1
|
|
54
|
+
},
|
|
50
55
|
menu: {
|
|
51
56
|
type: Array,
|
|
52
57
|
default: () => [],
|
|
@@ -104,55 +109,48 @@
|
|
|
104
109
|
tabItemOffsetLeft: 0,
|
|
105
110
|
tabItemWidth: 0,
|
|
106
111
|
tabItemHeight: 2,
|
|
107
|
-
tabIndex:
|
|
112
|
+
tabIndex: -1,
|
|
108
113
|
}
|
|
109
114
|
},
|
|
110
115
|
watch: {
|
|
111
116
|
value(v) {
|
|
112
|
-
|
|
117
|
+
this.onTabClick(v)
|
|
113
118
|
}
|
|
114
119
|
},
|
|
115
120
|
computed: {
|
|
116
|
-
hasIcon() {
|
|
117
|
-
return this.menu.find(e => e.icon)
|
|
118
|
-
},
|
|
119
121
|
$safeBottom() {
|
|
120
122
|
return uni.getSystemInfoSync().safeAreaInsets.bottom
|
|
121
123
|
}
|
|
122
124
|
},
|
|
123
125
|
mounted() {
|
|
124
|
-
|
|
125
|
-
this.onTabClick(this.menu[this.index], this.index)
|
|
126
|
-
} else {
|
|
127
|
-
this.tabIndex = typeof this.value !== 'undefined' ? this.value : this.index
|
|
128
|
-
}
|
|
126
|
+
this.onTabClick(typeof this.value !== 'undefined' ? this.value : this.index)
|
|
129
127
|
},
|
|
130
128
|
methods: {
|
|
131
|
-
onTabClick(
|
|
129
|
+
onTabClick(index) {
|
|
130
|
+
console.log('当前索引:', index)
|
|
132
131
|
if (this.disabled) {
|
|
133
132
|
return
|
|
134
133
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
this.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}).exec()
|
|
134
|
+
if (this.tabIndex === index) {
|
|
135
|
+
return
|
|
136
|
+
}
|
|
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
|
+
})
|
|
151
|
+
this.tabIndex = index
|
|
152
|
+
this.$emit('change', index)
|
|
153
|
+
this.$emit('update:value', index)
|
|
156
154
|
}
|
|
157
155
|
}
|
|
158
156
|
}
|