hy-app 0.5.11 → 0.5.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.
@@ -1,335 +1,335 @@
1
- <template>
2
- <view class="hy-tabs">
3
- <view class="hy-tabs__wrapper">
4
- <slot name="left" />
5
- <view class="hy-tabs__wrapper--scroll-view__wrapper">
6
- <scroll-view
7
- :scroll-x="scrollable"
8
- :scroll-left="scrollLeft"
9
- :scroll-with-animation="true"
10
- class="hy-tabs__wrapper--scroll-view"
11
- :show-scrollbar="false"
12
- ref="hy-tabs__wrapper--scroll-view"
13
- >
14
- <view class="hy-tabs__wrapper--nav" ref="hy-tabs__wrapper__nav">
15
- <view
16
- v-for="(item, index) in list"
17
- :key="index"
18
- @tap="clickHandler(item, index)"
19
- @longpress="longPressHandler(item, index)"
20
- :ref="`u-tabs__wrapper--nav__item-${index}`"
21
- :style="[itemStyle, { flex: scrollable ? '' : 1 }]"
22
- :class="[
23
- 'hy-tabs__wrapper--nav__item',
24
- `hy-tabs__wrapper--nav__item-${index}`,
25
- item.disabled && 'hy-tabs__wrapper--nav__item--disabled',
26
- innerCurrent == index ? 'hy-tabs__wrapper--nav__item--active' : ''
27
- ]"
28
- >
29
- <slot v-if="$slots.icon" name="icon" :record="item" :index="index" />
30
- <view
31
- class="hy-tabs__wrapper--nav__item--prefix-icon"
32
- v-else-if="item.icon"
33
- >
34
- <hy-icon :name="item.icon" :customStyle="iconStyle"></hy-icon>
35
- </view>
36
- <slot
37
- v-if="$slots.content"
38
- name="content"
39
- :record="item"
40
- :index="index"
41
- />
42
- <text
43
- v-else
44
- :class="[
45
- 'hy-tabs__wrapper--nav__item--text',
46
- item.disabled && 'hy-tabs__wrapper--nav__item--text__disabled'
47
- ]"
48
- :style="[textStyle(index)]"
49
- >
50
- {{ item[keyName] }}
51
- </text>
52
- <hy-badge
53
- :show="
54
- !!(
55
- item?.badge &&
56
- (item?.badge?.show ||
57
- item?.badge?.isDot ||
58
- item?.badge?.value)
59
- )
60
- "
61
- :isDot="(item?.badge && item?.badge?.isDot) || propsBadge?.isDot"
62
- :value="(item?.badge && item?.badge?.value) || propsBadge?.value"
63
- :max="(item?.badge && item?.badge?.max) || propsBadge?.max"
64
- :type="(item?.badge && item?.badge?.type) || propsBadge?.type"
65
- :showZero="
66
- (item?.badge && item?.badge?.showZero) || propsBadge?.showZero
67
- "
68
- :bgColor="
69
- (item?.badge && item?.badge?.bgColor) || propsBadge?.bgColor
70
- "
71
- :color="(item?.badge && item?.badge?.color) || propsBadge?.color"
72
- :shape="(item?.badge && item?.badge?.shape) || propsBadge?.shape"
73
- :numberType="
74
- (item?.badge && item?.badge?.numberType) ||
75
- propsBadge?.numberType
76
- "
77
- :inverted="
78
- (item?.badge && item?.badge?.inverted) || propsBadge?.inverted
79
- "
80
- :customStyle="{
81
- marginLeft: '4px'
82
- }"
83
- ></hy-badge>
84
- </view>
85
- <!-- #ifndef APP-NVUE -->
86
- <view
87
- class="hy-tabs__wrapper--nav__line"
88
- ref="hy-tabs__wrapper--nav__line"
89
- :style="[
90
- {
91
- width: addUnit(lineWidth),
92
- transform: `translate(${lineOffsetLeft}px)`,
93
- transitionDuration: `${firstTime ? 0 : duration}ms`,
94
- height: addUnit(lineHeight),
95
- background: lineColor,
96
- backgroundSize: lineBgSize
97
- }
98
- ]"
99
- ></view>
100
- <!-- #endif -->
101
- </view>
102
- </scroll-view>
103
- </view>
104
- <slot name="right" />
105
- </view>
106
-
107
- <!-- 内容轮播图 -->
108
- <slot v-if="$slots.main" name="main"></slot>
109
- <swiper
110
- v-else-if="list.length"
111
- :current="innerCurrent"
112
- @animationfinish="animationFinish"
113
- :style="{ height: swiperHeight }"
114
- >
115
- <swiper-item class="swiper-item" v-for="(item, i) in list" :key="i">
116
- <slot :record="item.content" />
117
- </swiper-item>
118
- </swiper>
119
- </view>
120
- </template>
121
-
122
- <script lang="ts">
123
- export default {
124
- name: 'hy-tabs',
125
- options: {
126
- addGlobalClass: true,
127
- virtualHost: true,
128
- styleIsolation: 'shared'
129
- }
130
- }
131
- </script>
132
-
133
- <script setup lang="ts">
134
- import { computed, ref, watch, nextTick, onMounted, getCurrentInstance } from 'vue'
135
- import type { CSSProperties } from 'vue'
136
- import type { ITabsEmits, TabsItemVo } from './typing'
137
- import { addUnit, getPx, getRect, sleep } from '../../libs'
138
- import tabsProps from './props'
139
- // 组件
140
- import HyBadge from '../hy-badge/hy-badge.vue'
141
- import HyIcon from '../hy-icon/hy-icon.vue'
142
-
143
- /**
144
- * 该组件是一个tabs标签组件,在标签多的时候,可以配置为左右滑动,标签少的时候,可以禁止滑动。 该组件的一个特点是配置为滚动模式时,激活的tab会自动移动到组件的中间位置。
145
- * @displayName hy-tabs
146
- */
147
- defineOptions({})
148
-
149
- const props = defineProps(tabsProps)
150
- const emit = defineEmits<ITabsEmits>()
151
-
152
- const instance = getCurrentInstance()
153
- const firstTime = ref<boolean>(true)
154
- const scrollLeft = ref<number>(0)
155
- const scrollViewWidth = ref<number>(0)
156
- const lineOffsetLeft = ref<number>(0)
157
- const tabsRect = ref<UniApp.NodeInfo>({
158
- left: 0
159
- })
160
- const innerCurrent = ref<number>(0)
161
-
162
- watch(
163
- () => props.current,
164
- (newValue: number) => {
165
- // 内外部值不相等时,才尝试移动滑块
166
- if (newValue !== innerCurrent.value) {
167
- innerCurrent.value = newValue
168
- nextTick(() => {
169
- resize()
170
- })
171
- }
172
- },
173
- { immediate: true }
174
- )
175
- watch(
176
- () => props.list,
177
- () => resize()
178
- )
179
-
180
- const textStyle = computed(() => {
181
- return (index: number): CSSProperties => {
182
- const style: CSSProperties = {}
183
- // 取当期是否激活的样式
184
- const customStyle_1 = index == innerCurrent.value ? props.activeStyle : props.inactiveStyle
185
- // 如果当前菜单被禁用,则加上对应颜色,需要在此做处理,是因为nvue下,无法在style样式中通过!import覆盖标签的内联样式
186
- if (props.list[index]?.disabled) {
187
- style.color = '#c8c9cc'
188
- }
189
- return Object.assign(customStyle_1, style)
190
- }
191
- })
192
-
193
- onMounted(() => {
194
- resize()
195
- })
196
-
197
- /**
198
- * 设置线左边距离
199
- */
200
- const setLineLeft = () => {
201
- const tabItem = props.list[innerCurrent.value]
202
- if (!tabItem) {
203
- return
204
- }
205
- // 获取滑块该移动的位置
206
- let lineOffsetLeft_1 = props.list
207
- .slice(0, innerCurrent.value)
208
- .reduce((total, curr) => total + curr.rect.width, 0)
209
- // 获取下划线的数值px表示法
210
- lineOffsetLeft.value = lineOffsetLeft_1 + (tabItem.rect.width - getPx(props.lineWidth)) / 2
211
-
212
- // 如果是第一次执行此方法,让滑块在初始化时,瞬间滑动到第一个tab item的中间
213
- // 这里需要一个定时器,因为在非nvue下,是直接通过style绑定过渡时间,需要等其过渡完成后,再设置为false(非第一次移动滑块)
214
- if (firstTime.value) {
215
- sleep().then(() => {
216
- firstTime.value = false
217
- })
218
- }
219
- }
220
- // 点击某一个标签
221
- const clickHandler = (item: TabsItemVo, index: number) => {
222
- // 因为标签可能为disabled状态,所以click是一定会发出的,但是change事件是需要可用的状态才发出
223
- emit('click', {
224
- ...item,
225
- index
226
- })
227
- // 如果disabled状态,返回
228
- if (item.disabled) return
229
- innerCurrent.value = index
230
- resize()
231
- emit('update:current', index)
232
- emit('change', item, index)
233
- }
234
- // 长按事件
235
- const longPressHandler = (item: TabsItemVo, index: number) => {
236
- emit('longPress', {
237
- ...item,
238
- index
239
- })
240
- }
241
- const setScrollLeft = () => {
242
- // 当前活动tab的布局信息,有tab菜单的width和left(为元素左边界到父元素左边界的距离)等信息
243
- if (innerCurrent.value < 0) {
244
- innerCurrent.value = 0
245
- }
246
- const tabRect = props.list[innerCurrent.value]
247
- // 累加得到当前item到左边的距离
248
- const offsetLeft = props.list.slice(0, innerCurrent.value).reduce((total: number, curr) => {
249
- return total + curr.rect.width
250
- }, 0)
251
- // 此处为屏幕宽度
252
- const windowWidth = uni.getWindowInfo().windowWidth
253
- // 将活动的tabs-item移动到屏幕正中间,实际上是对scroll-view的移动
254
- let scrollLeft_1 =
255
- offsetLeft -
256
- ((tabsRect.value.width || 0) - tabRect.rect.width) / 2 -
257
- (windowWidth - (tabsRect.value.right || 0)) / 2 +
258
- (tabsRect.value.left || 0) / 2
259
- // 这里做一个限制,限制scrollLeft的最大值为整个scroll-view宽度减去tabs组件的宽度
260
- scrollLeft_1 = Math.min(scrollLeft_1, scrollViewWidth.value - (tabsRect.value.width || 0))
261
- scrollLeft.value = Math.max(0, scrollLeft_1)
262
- }
263
- /**
264
- * 获取所有标签的尺寸
265
- * */
266
- const resize = () => {
267
- // 如果不存在list,则不处理
268
- if (props.list.length === 0) {
269
- return
270
- }
271
- Promise.all([getTabsRect(), getAllItemRect()]).then(
272
- ([tabsRect_1, itemRect = []]: (UniApp.NodeInfo | any)[]) => {
273
- // 兼容在swiper组件中使用
274
- if (
275
- tabsRect_1.left &&
276
- tabsRect_1.width &&
277
- tabsRect_1.right &&
278
- tabsRect_1.left > tabsRect_1.width
279
- ) {
280
- tabsRect_1.right =
281
- tabsRect_1.right -
282
- Math.floor(tabsRect_1.left / tabsRect_1.width) * tabsRect_1.width
283
- tabsRect_1.left = tabsRect_1.left % tabsRect_1.width
284
- }
285
- // console.log(tabsRect)
286
- tabsRect.value = tabsRect_1
287
- scrollViewWidth.value = 0
288
- itemRect.map((item: UniApp.NodeInfo, index: number) => {
289
- // 计算scroll-view的宽度,这里
290
- scrollViewWidth.value += item.width || 0
291
- // 另外计算每一个item的中心点X轴坐标
292
- props.list[index].rect = item
293
- })
294
- // 获取了tabs的尺寸之后,设置滑块的位置
295
- setLineLeft()
296
- setScrollLeft()
297
- }
298
- )
299
- }
300
- /**
301
- * 获取导航菜单的尺寸
302
- * */
303
- const getTabsRect = () => {
304
- return new Promise((resolve) => {
305
- getRect('.hy-tabs__wrapper--scroll-view', false, instance).then((size) => resolve(size))
306
- })
307
- }
308
- /**
309
- * 获取所有标签的尺寸
310
- * */
311
- const getAllItemRect = () => {
312
- return new Promise((resolve) => {
313
- const promiseAllArr = props.list.map((item, index) =>
314
- getRect(`.hy-tabs__wrapper--nav__item-${index}`, false, instance)
315
- )
316
- Promise.all(promiseAllArr).then((sizes) => resolve(sizes))
317
- })
318
- }
319
-
320
- /**
321
- * 滑动页面改变当前值
322
- * */
323
- const animationFinish = (e: any) => {
324
- // 轮播图选项值
325
- innerCurrent.value = e.detail.current
326
- resize()
327
- if (e.detail.source === 'touch') {
328
- emit('change', props.list[props.current], props.current)
329
- }
330
- }
331
- </script>
332
-
333
- <style lang="scss" scoped>
334
- @import './index.scss';
335
- </style>
1
+ <template>
2
+ <view class="hy-tabs">
3
+ <view class="hy-tabs__wrapper">
4
+ <slot name="left" />
5
+ <view class="hy-tabs__wrapper--scroll-view__wrapper">
6
+ <scroll-view
7
+ :scroll-x="scrollable"
8
+ :scroll-left="scrollLeft"
9
+ :scroll-with-animation="true"
10
+ class="hy-tabs__wrapper--scroll-view"
11
+ :show-scrollbar="false"
12
+ ref="hy-tabs__wrapper--scroll-view"
13
+ >
14
+ <view class="hy-tabs__wrapper--nav" ref="hy-tabs__wrapper__nav">
15
+ <view
16
+ v-for="(item, index) in list"
17
+ :key="index"
18
+ @tap="clickHandler(item, index)"
19
+ @longpress="longPressHandler(item, index)"
20
+ :ref="`u-tabs__wrapper--nav__item-${index}`"
21
+ :style="[itemStyle, { flex: scrollable ? '' : 1 }]"
22
+ :class="[
23
+ 'hy-tabs__wrapper--nav__item',
24
+ `hy-tabs__wrapper--nav__item-${index}`,
25
+ item.disabled && 'hy-tabs__wrapper--nav__item--disabled',
26
+ innerCurrent == index ? 'hy-tabs__wrapper--nav__item--active' : ''
27
+ ]"
28
+ >
29
+ <slot v-if="$slots.icon" name="icon" :record="item" :index="index" />
30
+ <view
31
+ class="hy-tabs__wrapper--nav__item--prefix-icon"
32
+ v-else-if="item.icon"
33
+ >
34
+ <hy-icon :name="item.icon" :customStyle="iconStyle"></hy-icon>
35
+ </view>
36
+ <slot
37
+ v-if="$slots.content"
38
+ name="content"
39
+ :record="item"
40
+ :index="index"
41
+ />
42
+ <text
43
+ v-else
44
+ :class="[
45
+ 'hy-tabs__wrapper--nav__item--test',
46
+ item.disabled && 'hy-tabs__wrapper--nav__item--text__disabled'
47
+ ]"
48
+ :style="[textStyle(index)]"
49
+ >
50
+ {{ item[keyName] }}
51
+ </text>
52
+ <hy-badge
53
+ :show="
54
+ !!(
55
+ item?.badge &&
56
+ (item?.badge?.show ||
57
+ item?.badge?.isDot ||
58
+ item?.badge?.value)
59
+ )
60
+ "
61
+ :isDot="(item?.badge && item?.badge?.isDot) || propsBadge?.isDot"
62
+ :value="(item?.badge && item?.badge?.value) || propsBadge?.value"
63
+ :max="(item?.badge && item?.badge?.max) || propsBadge?.max"
64
+ :type="(item?.badge && item?.badge?.type) || propsBadge?.type"
65
+ :showZero="
66
+ (item?.badge && item?.badge?.showZero) || propsBadge?.showZero
67
+ "
68
+ :bgColor="
69
+ (item?.badge && item?.badge?.bgColor) || propsBadge?.bgColor
70
+ "
71
+ :color="(item?.badge && item?.badge?.color) || propsBadge?.color"
72
+ :shape="(item?.badge && item?.badge?.shape) || propsBadge?.shape"
73
+ :numberType="
74
+ (item?.badge && item?.badge?.numberType) ||
75
+ propsBadge?.numberType
76
+ "
77
+ :inverted="
78
+ (item?.badge && item?.badge?.inverted) || propsBadge?.inverted
79
+ "
80
+ :customStyle="{
81
+ marginLeft: '4px'
82
+ }"
83
+ ></hy-badge>
84
+ </view>
85
+ <!-- #ifndef APP-NVUE -->
86
+ <view
87
+ class="hy-tabs__wrapper--nav__line"
88
+ ref="hy-tabs__wrapper--nav__line"
89
+ :style="[
90
+ {
91
+ width: addUnit(lineWidth),
92
+ transform: `translate(${lineOffsetLeft}px)`,
93
+ transitionDuration: `${firstTime ? 0 : duration}ms`,
94
+ height: addUnit(lineHeight),
95
+ background: lineColor,
96
+ backgroundSize: lineBgSize
97
+ }
98
+ ]"
99
+ ></view>
100
+ <!-- #endif -->
101
+ </view>
102
+ </scroll-view>
103
+ </view>
104
+ <slot name="right" />
105
+ </view>
106
+
107
+ <!-- 内容轮播图 -->
108
+ <slot v-if="$slots.main" name="main"></slot>
109
+ <swiper
110
+ v-else-if="list.length"
111
+ :current="innerCurrent"
112
+ @animationfinish="animationFinish"
113
+ :style="{ height: swiperHeight }"
114
+ >
115
+ <swiper-item class="swiper-item" v-for="(item, i) in list" :key="i">
116
+ <slot :record="item.content" />
117
+ </swiper-item>
118
+ </swiper>
119
+ </view>
120
+ </template>
121
+
122
+ <script lang="ts">
123
+ export default {
124
+ name: 'hy-tabs',
125
+ options: {
126
+ addGlobalClass: true,
127
+ virtualHost: true,
128
+ styleIsolation: 'shared'
129
+ }
130
+ }
131
+ </script>
132
+
133
+ <script setup lang="ts">
134
+ import { computed, ref, watch, nextTick, onMounted, getCurrentInstance } from 'vue'
135
+ import type { CSSProperties } from 'vue'
136
+ import type { ITabsEmits, TabsItemVo } from './typing'
137
+ import { addUnit, getPx, getRect, sleep } from '../../libs'
138
+ import tabsProps from './props'
139
+ // 组件
140
+ import HyBadge from '../hy-badge/hy-badge.vue'
141
+ import HyIcon from '../hy-icon/hy-icon.vue'
142
+
143
+ /**
144
+ * 该组件是一个tabs标签组件,在标签多的时候,可以配置为左右滑动,标签少的时候,可以禁止滑动。 该组件的一个特点是配置为滚动模式时,激活的tab会自动移动到组件的中间位置。
145
+ * @displayName hy-tabs
146
+ */
147
+ defineOptions({})
148
+
149
+ const props = defineProps(tabsProps)
150
+ const emit = defineEmits<ITabsEmits>()
151
+
152
+ const instance = getCurrentInstance()
153
+ const firstTime = ref<boolean>(true)
154
+ const scrollLeft = ref<number>(0)
155
+ const scrollViewWidth = ref<number>(0)
156
+ const lineOffsetLeft = ref<number>(0)
157
+ const tabsRect = ref<UniApp.NodeInfo>({
158
+ left: 0
159
+ })
160
+ const innerCurrent = ref<number>(0)
161
+
162
+ watch(
163
+ () => props.current,
164
+ (newValue: number) => {
165
+ // 内外部值不相等时,才尝试移动滑块
166
+ if (newValue !== innerCurrent.value) {
167
+ innerCurrent.value = newValue
168
+ nextTick(() => {
169
+ resize()
170
+ })
171
+ }
172
+ },
173
+ { immediate: true }
174
+ )
175
+ watch(
176
+ () => props.list,
177
+ () => resize()
178
+ )
179
+
180
+ const textStyle = computed(() => {
181
+ return (index: number): CSSProperties => {
182
+ const style: CSSProperties = {}
183
+ // 取当期是否激活的样式
184
+ const customStyle_1 = index == innerCurrent.value ? props.activeStyle : props.inactiveStyle
185
+ // 如果当前菜单被禁用,则加上对应颜色,需要在此做处理,是因为nvue下,无法在style样式中通过!import覆盖标签的内联样式
186
+ if (props.list[index]?.disabled) {
187
+ style.color = '#c8c9cc'
188
+ }
189
+ return Object.assign(customStyle_1, style)
190
+ }
191
+ })
192
+
193
+ onMounted(() => {
194
+ resize()
195
+ })
196
+
197
+ /**
198
+ * 设置线左边距离
199
+ */
200
+ const setLineLeft = () => {
201
+ const tabItem = props.list[innerCurrent.value]
202
+ if (!tabItem) {
203
+ return
204
+ }
205
+ // 获取滑块该移动的位置
206
+ let lineOffsetLeft_1 = props.list
207
+ .slice(0, innerCurrent.value)
208
+ .reduce((total, curr) => total + curr.rect.width, 0)
209
+ // 获取下划线的数值px表示法
210
+ lineOffsetLeft.value = lineOffsetLeft_1 + (tabItem.rect.width - getPx(props.lineWidth)) / 2
211
+
212
+ // 如果是第一次执行此方法,让滑块在初始化时,瞬间滑动到第一个tab item的中间
213
+ // 这里需要一个定时器,因为在非nvue下,是直接通过style绑定过渡时间,需要等其过渡完成后,再设置为false(非第一次移动滑块)
214
+ if (firstTime.value) {
215
+ sleep().then(() => {
216
+ firstTime.value = false
217
+ })
218
+ }
219
+ }
220
+ // 点击某一个标签
221
+ const clickHandler = (item: TabsItemVo, index: number) => {
222
+ // 因为标签可能为disabled状态,所以click是一定会发出的,但是change事件是需要可用的状态才发出
223
+ emit('click', {
224
+ ...item,
225
+ index
226
+ })
227
+ // 如果disabled状态,返回
228
+ if (item.disabled) return
229
+ innerCurrent.value = index
230
+ resize()
231
+ emit('update:current', index)
232
+ emit('change', item, index)
233
+ }
234
+ // 长按事件
235
+ const longPressHandler = (item: TabsItemVo, index: number) => {
236
+ emit('longPress', {
237
+ ...item,
238
+ index
239
+ })
240
+ }
241
+ const setScrollLeft = () => {
242
+ // 当前活动tab的布局信息,有tab菜单的width和left(为元素左边界到父元素左边界的距离)等信息
243
+ if (innerCurrent.value < 0) {
244
+ innerCurrent.value = 0
245
+ }
246
+ const tabRect = props.list[innerCurrent.value]
247
+ // 累加得到当前item到左边的距离
248
+ const offsetLeft = props.list.slice(0, innerCurrent.value).reduce((total: number, curr) => {
249
+ return total + curr.rect.width
250
+ }, 0)
251
+ // 此处为屏幕宽度
252
+ const windowWidth = uni.getWindowInfo().windowWidth
253
+ // 将活动的tabs-item移动到屏幕正中间,实际上是对scroll-view的移动
254
+ let scrollLeft_1 =
255
+ offsetLeft -
256
+ ((tabsRect.value.width || 0) - tabRect.rect.width) / 2 -
257
+ (windowWidth - (tabsRect.value.right || 0)) / 2 +
258
+ (tabsRect.value.left || 0) / 2
259
+ // 这里做一个限制,限制scrollLeft的最大值为整个scroll-view宽度减去tabs组件的宽度
260
+ scrollLeft_1 = Math.min(scrollLeft_1, scrollViewWidth.value - (tabsRect.value.width || 0))
261
+ scrollLeft.value = Math.max(0, scrollLeft_1)
262
+ }
263
+ /**
264
+ * 获取所有标签的尺寸
265
+ * */
266
+ const resize = () => {
267
+ // 如果不存在list,则不处理
268
+ if (props.list.length === 0) {
269
+ return
270
+ }
271
+ Promise.all([getTabsRect(), getAllItemRect()]).then(
272
+ ([tabsRect_1, itemRect = []]: (UniApp.NodeInfo | any)[]) => {
273
+ // 兼容在swiper组件中使用
274
+ if (
275
+ tabsRect_1.left &&
276
+ tabsRect_1.width &&
277
+ tabsRect_1.right &&
278
+ tabsRect_1.left > tabsRect_1.width
279
+ ) {
280
+ tabsRect_1.right =
281
+ tabsRect_1.right -
282
+ Math.floor(tabsRect_1.left / tabsRect_1.width) * tabsRect_1.width
283
+ tabsRect_1.left = tabsRect_1.left % tabsRect_1.width
284
+ }
285
+ // console.log(tabsRect)
286
+ tabsRect.value = tabsRect_1
287
+ scrollViewWidth.value = 0
288
+ itemRect.map((item: UniApp.NodeInfo, index: number) => {
289
+ // 计算scroll-view的宽度,这里
290
+ scrollViewWidth.value += item.width || 0
291
+ // 另外计算每一个item的中心点X轴坐标
292
+ props.list[index].rect = item
293
+ })
294
+ // 获取了tabs的尺寸之后,设置滑块的位置
295
+ setLineLeft()
296
+ setScrollLeft()
297
+ }
298
+ )
299
+ }
300
+ /**
301
+ * 获取导航菜单的尺寸
302
+ * */
303
+ const getTabsRect = () => {
304
+ return new Promise((resolve) => {
305
+ getRect('.hy-tabs__wrapper--scroll-view', false, instance).then((size) => resolve(size))
306
+ })
307
+ }
308
+ /**
309
+ * 获取所有标签的尺寸
310
+ * */
311
+ const getAllItemRect = () => {
312
+ return new Promise((resolve) => {
313
+ const promiseAllArr = props.list.map((item, index) =>
314
+ getRect(`.hy-tabs__wrapper--nav__item-${index}`, false, instance)
315
+ )
316
+ Promise.all(promiseAllArr).then((sizes) => resolve(sizes))
317
+ })
318
+ }
319
+
320
+ /**
321
+ * 滑动页面改变当前值
322
+ * */
323
+ const animationFinish = (e: any) => {
324
+ // 轮播图选项值
325
+ innerCurrent.value = e.detail.current
326
+ resize()
327
+ if (e.detail.source === 'touch') {
328
+ emit('change', props.list[props.current], props.current)
329
+ }
330
+ }
331
+ </script>
332
+
333
+ <style lang="scss" scoped>
334
+ @import './index.scss';
335
+ </style>