hy-app 0.3.0 → 0.3.2
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/README.md +6 -3
- package/common/shakeService.ts +31 -29
- package/components/avatar.zip +0 -0
- package/components/hy-action-sheet/hy-action-sheet.vue +71 -46
- package/components/hy-address-picker/hy-address-picker.vue +94 -83
- package/components/hy-avatar/hy-avatar.vue +84 -85
- package/components/hy-back-top/hy-back-top.vue +8 -6
- package/components/hy-badge/hy-badge.vue +47 -46
- package/components/hy-button/hy-button.vue +117 -93
- package/components/hy-calendar/hy-calendar.vue +168 -160
- package/components/hy-card/hy-card.vue +50 -43
- package/components/hy-card/typing.d.ts +33 -32
- package/components/hy-cell/hy-cell.vue +73 -51
- package/components/hy-check-button/hy-check-button.vue +54 -47
- package/components/hy-checkbox/hy-checkbox.vue +97 -105
- package/components/hy-code-input/hy-code-input.vue +80 -89
- package/components/hy-config-provider/hy-config-provider.vue +20 -21
- package/components/hy-count-down/hy-count-down.vue +66 -67
- package/components/hy-count-to/hy-count-to.vue +105 -99
- package/components/hy-count-to/typing.d.ts +13 -12
- package/components/hy-datetime-picker/hy-datetime-picker.vue +261 -253
- package/components/hy-datetime-picker/typing.d.ts +42 -40
- package/components/hy-divider/hy-divider.vue +68 -73
- package/components/hy-dropdown/hy-dropdown.vue +20 -19
- package/components/hy-dropdown-item/hy-dropdown-item.vue +66 -61
- package/components/hy-dropdown-item/typing.d.ts +9 -9
- package/components/hy-empty/hy-empty.vue +42 -42
- package/components/hy-flex/hy-flex.vue +99 -0
- package/components/hy-flex/index.scss +8 -0
- package/components/hy-flex/typing.d.ts +23 -0
- package/components/hy-float-button/hy-float-button.vue +218 -210
- package/components/hy-folding-panel/hy-folding-panel.vue +32 -33
- package/components/hy-form/hy-form.vue +264 -252
- package/components/hy-form/typing.d.ts +4 -0
- package/components/hy-form-group/hy-form-group.vue +114 -183
- package/components/hy-form-item/hy-form-item.vue +12 -10
- package/components/hy-form-item/index.scss +2 -2
- package/components/hy-form-item/typing.d.ts +3 -6
- package/components/hy-grid/hy-grid.vue +44 -43
- package/components/hy-icon/hy-icon.vue +61 -67
- package/components/hy-image/hy-image.vue +112 -88
- package/components/hy-image/typing.d.ts +27 -23
- package/components/hy-input/hy-input.vue +157 -127
- package/components/hy-input/typing.d.ts +53 -47
- package/components/hy-line/hy-line.vue +26 -26
- package/components/hy-line-progress/hy-line-progress.vue +42 -35
- package/components/hy-list/hy-list.vue +76 -85
- package/components/hy-loading/hy-loading.vue +26 -23
- package/components/hy-login/TheUserLogin.vue +1 -1
- package/components/hy-menu/hy-menu.vue +48 -43
- package/components/hy-menu/typing.d.ts +18 -17
- package/components/hy-modal/hy-modal.vue +39 -35
- package/components/hy-navbar/hy-navbar.vue +25 -25
- package/components/hy-navbar/typing.d.ts +24 -22
- package/components/hy-notice-bar/hy-notice-bar.vue +26 -27
- package/components/hy-notify/hy-notify.vue +53 -53
- package/components/hy-number-step/hy-number-step.vue +134 -146
- package/components/hy-number-step/typing.d.ts +35 -35
- package/components/hy-overlay/hy-overlay.vue +23 -21
- package/components/hy-pagination/hy-pagination.vue +41 -36
- package/components/hy-picker/hy-picker.vue +184 -154
- package/components/hy-picker/typing.d.ts +39 -39
- package/components/hy-popover/hy-popover.vue +97 -77
- package/components/hy-popup/hy-popup.vue +107 -98
- package/components/hy-price/hy-price.vue +38 -34
- package/components/hy-qrcode/hy-qrcode.vue +50 -51
- package/components/hy-radio/hy-radio.vue +101 -113
- package/components/hy-rate/hy-rate.vue +107 -88
- package/components/hy-read-more/hy-read-more.vue +64 -49
- package/components/hy-scroll-list/hy-scroll-list.vue +45 -48
- package/components/hy-search/hy-search.vue +73 -66
- package/components/hy-search/typing.d.ts +36 -35
- package/components/hy-signature/hy-signature.vue +282 -240
- package/components/hy-slider/hy-slider.vue +195 -153
- package/components/hy-slider/typing.d.ts +21 -21
- package/components/hy-steps/hy-steps.vue +118 -90
- package/components/hy-steps/index.scss +31 -21
- package/components/hy-submit-bar/hy-submit-bar.vue +61 -70
- package/components/hy-subsection/hy-subsection.vue +99 -102
- package/components/hy-subsection/typing.d.ts +19 -19
- package/components/hy-swipe-action/hy-swipe-action.vue +131 -118
- package/components/hy-swiper/hy-swiper.vue +85 -71
- package/components/hy-switch/hy-switch.vue +67 -72
- package/components/hy-switch/typing.d.ts +21 -19
- package/components/hy-tabs/hy-tabs.vue +168 -113
- package/components/hy-tag/hy-tag.vue +90 -86
- package/components/hy-tag/typing.d.ts +26 -21
- package/components/hy-text/hy-text.vue +119 -111
- package/components/hy-textarea/hy-textarea.vue +100 -93
- package/components/hy-textarea/typing.d.ts +36 -31
- package/components/hy-toast/hy-toast.vue +77 -67
- package/components/hy-tooltip/hy-tooltip.vue +109 -91
- package/components/hy-transition/hy-transition.vue +62 -66
- package/components/hy-upload/hy-upload.vue +294 -152
- package/components/hy-upload/typing.d.ts +41 -36
- package/components/hy-warn/hy-warn.vue +34 -27
- package/components/hy-waterfall/hy-waterfall.vue +83 -74
- package/components/hy-watermark/hy-watermark.vue +134 -115
- package/components/index.ts +1 -1
- package/composables/usePopover.ts +236 -221
- package/composables/useQueue.ts +53 -52
- package/global.d.ts +1 -0
- package/package.json +2 -2
- package/store/index.ts +9 -1
- package/theme.scss +5 -5
- package/typing/index.ts +0 -1
- package/typing/modules/common.d.ts +0 -2
- package/web-types.json +1 -1
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<scroll-view
|
|
7
7
|
:scroll-x="scrollable"
|
|
8
8
|
:scroll-left="scrollLeft"
|
|
9
|
-
scroll-with-animation
|
|
9
|
+
:scroll-with-animation="true"
|
|
10
10
|
class="hy-tabs__wrapper__scroll-view"
|
|
11
11
|
:show-scrollbar="false"
|
|
12
12
|
ref="hy-tabs__wrapper__scroll-view"
|
|
@@ -23,19 +23,37 @@
|
|
|
23
23
|
'hy-tabs__wrapper__nav__item',
|
|
24
24
|
`hy-tabs__wrapper__nav__item-${index}`,
|
|
25
25
|
item.disabled && 'hy-tabs__wrapper__nav__item--disabled',
|
|
26
|
-
innerCurrent == index
|
|
26
|
+
innerCurrent == index
|
|
27
|
+
? 'hy-tabs__wrapper__nav__item--active'
|
|
28
|
+
: '',
|
|
27
29
|
]"
|
|
28
30
|
>
|
|
29
|
-
<slot
|
|
31
|
+
<slot
|
|
32
|
+
v-if="$slots.icon"
|
|
33
|
+
name="icon"
|
|
34
|
+
:record="item"
|
|
35
|
+
:index="index"
|
|
36
|
+
/>
|
|
30
37
|
<template v-else>
|
|
31
|
-
<view
|
|
38
|
+
<view
|
|
39
|
+
class="hy-tabs__wrapper__nav__item__prefix-icon"
|
|
40
|
+
v-if="item.icon"
|
|
41
|
+
>
|
|
32
42
|
<HyIcon :name="item.icon" :customStyle="iconStyle"></HyIcon>
|
|
33
43
|
</view>
|
|
34
44
|
</template>
|
|
35
|
-
<slot
|
|
45
|
+
<slot
|
|
46
|
+
v-if="$slots.content"
|
|
47
|
+
name="content"
|
|
48
|
+
:record="item"
|
|
49
|
+
:index="index"
|
|
50
|
+
/>
|
|
36
51
|
<text
|
|
37
52
|
v-else
|
|
38
|
-
:class="[
|
|
53
|
+
:class="[
|
|
54
|
+
item.disabled &&
|
|
55
|
+
'hy-tabs__wrapper__nav__item__text--disabled',
|
|
56
|
+
]"
|
|
39
57
|
class="hy-tabs__wrapper__nav__item--text"
|
|
40
58
|
:style="[textStyle(index)]"
|
|
41
59
|
>
|
|
@@ -43,18 +61,40 @@
|
|
|
43
61
|
</text>
|
|
44
62
|
<HyBadge
|
|
45
63
|
:show="
|
|
46
|
-
!!(
|
|
64
|
+
!!(
|
|
65
|
+
item?.badge &&
|
|
66
|
+
(item?.badge?.show ||
|
|
67
|
+
item?.badge?.isDot ||
|
|
68
|
+
item?.badge?.value)
|
|
69
|
+
)
|
|
70
|
+
"
|
|
71
|
+
:isDot="
|
|
72
|
+
(item?.badge && item?.badge?.isDot) || propsBadge?.isDot
|
|
73
|
+
"
|
|
74
|
+
:value="
|
|
75
|
+
(item?.badge && item?.badge?.value) || propsBadge?.value
|
|
47
76
|
"
|
|
48
|
-
:isDot="(item?.badge && item?.badge?.isDot) || propsBadge?.isDot"
|
|
49
|
-
:value="(item?.badge && item?.badge?.value) || propsBadge?.value"
|
|
50
77
|
:max="(item?.badge && item?.badge?.max) || propsBadge?.max"
|
|
51
78
|
:type="(item?.badge && item?.badge?.type) || propsBadge?.type"
|
|
52
|
-
:showZero="
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
:
|
|
56
|
-
|
|
57
|
-
|
|
79
|
+
:showZero="
|
|
80
|
+
(item?.badge && item?.badge?.showZero) || propsBadge?.showZero
|
|
81
|
+
"
|
|
82
|
+
:bgColor="
|
|
83
|
+
(item?.badge && item?.badge?.bgColor) || propsBadge?.bgColor
|
|
84
|
+
"
|
|
85
|
+
:color="
|
|
86
|
+
(item?.badge && item?.badge?.color) || propsBadge?.color
|
|
87
|
+
"
|
|
88
|
+
:shape="
|
|
89
|
+
(item?.badge && item?.badge?.shape) || propsBadge?.shape
|
|
90
|
+
"
|
|
91
|
+
:numberType="
|
|
92
|
+
(item?.badge && item?.badge?.numberType) ||
|
|
93
|
+
propsBadge?.numberType
|
|
94
|
+
"
|
|
95
|
+
:inverted="
|
|
96
|
+
(item?.badge && item?.badge?.inverted) || propsBadge?.inverted
|
|
97
|
+
"
|
|
58
98
|
:customStyle="{
|
|
59
99
|
marginLeft: '4px',
|
|
60
100
|
}"
|
|
@@ -99,32 +139,38 @@
|
|
|
99
139
|
|
|
100
140
|
<script lang="ts">
|
|
101
141
|
export default {
|
|
102
|
-
name:
|
|
142
|
+
name: "hy-tabs",
|
|
103
143
|
options: {
|
|
104
144
|
addGlobalClass: true,
|
|
105
145
|
virtualHost: true,
|
|
106
|
-
styleIsolation:
|
|
146
|
+
styleIsolation: "shared",
|
|
107
147
|
},
|
|
108
|
-
}
|
|
148
|
+
};
|
|
109
149
|
</script>
|
|
110
150
|
|
|
111
151
|
<script setup lang="ts">
|
|
112
|
-
import {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
152
|
+
import {
|
|
153
|
+
computed,
|
|
154
|
+
ref,
|
|
155
|
+
watch,
|
|
156
|
+
nextTick,
|
|
157
|
+
onMounted,
|
|
158
|
+
getCurrentInstance,
|
|
159
|
+
} from "vue";
|
|
160
|
+
import type { CSSProperties, PropType } from "vue";
|
|
161
|
+
import type { ITabsEmits } from "./typing";
|
|
162
|
+
import type { TabsItemVo } from "./typing";
|
|
163
|
+
import type HyBadgeProps from "../hy-badge/typing";
|
|
164
|
+
import { addUnit, getPx, getRect, sleep } from "../../utils";
|
|
119
165
|
// 组件
|
|
120
|
-
import HyBadge from
|
|
121
|
-
import HyIcon from
|
|
166
|
+
import HyBadge from "../hy-badge/hy-badge.vue";
|
|
167
|
+
import HyIcon from "../hy-icon/hy-icon.vue";
|
|
122
168
|
|
|
123
169
|
/**
|
|
124
170
|
* 该组件是一个tabs标签组件,在标签多的时候,可以配置为左右滑动,标签少的时候,可以禁止滑动。 该组件的一个特点是配置为滚动模式时,激活的tab会自动移动到组件的中间位置。
|
|
125
171
|
* @displayName hy-tabs
|
|
126
172
|
*/
|
|
127
|
-
defineOptions({})
|
|
173
|
+
defineOptions({});
|
|
128
174
|
|
|
129
175
|
// const props = withDefaults(defineProps<IProps>(), defaultProps)
|
|
130
176
|
const props = defineProps({
|
|
@@ -141,7 +187,7 @@ const props = defineProps({
|
|
|
141
187
|
/** 从list元素对象中读取的键名 */
|
|
142
188
|
keyName: {
|
|
143
189
|
type: String,
|
|
144
|
-
default:
|
|
190
|
+
default: "name",
|
|
145
191
|
},
|
|
146
192
|
/** 滑块移动一次所需的时间,单位秒 */
|
|
147
193
|
duration: {
|
|
@@ -173,14 +219,14 @@ const props = defineProps({
|
|
|
173
219
|
/** 滑块背景显示大小,当滑块背景设置为图片时使用 */
|
|
174
220
|
lineBgSize: {
|
|
175
221
|
type: [String, Number],
|
|
176
|
-
default:
|
|
222
|
+
default: "cover",
|
|
177
223
|
},
|
|
178
224
|
/** 菜单item的样式 */
|
|
179
225
|
itemStyle: Object as PropType<CSSProperties>,
|
|
180
226
|
/** 轮播图高度 */
|
|
181
227
|
swiperHeight: {
|
|
182
228
|
type: [String, Number],
|
|
183
|
-
default:
|
|
229
|
+
default: "calc(100vh - 44px)",
|
|
184
230
|
},
|
|
185
231
|
/** 菜单是否可滚动 */
|
|
186
232
|
scrollable: {
|
|
@@ -197,128 +243,134 @@ const props = defineProps({
|
|
|
197
243
|
customStyle: Object as PropType<CSSProperties>,
|
|
198
244
|
/** 自定义外部类名 */
|
|
199
245
|
customClass: String,
|
|
200
|
-
})
|
|
201
|
-
const
|
|
202
|
-
const emit = defineEmits<ITabsEmits>()
|
|
246
|
+
});
|
|
247
|
+
const emit = defineEmits<ITabsEmits>();
|
|
203
248
|
|
|
204
|
-
const instance = getCurrentInstance()
|
|
205
|
-
const firstTime = ref<boolean>(true)
|
|
206
|
-
const scrollLeft = ref<number>(0)
|
|
207
|
-
const scrollViewWidth = ref<number>(0)
|
|
208
|
-
const lineOffsetLeft = ref<number>(0)
|
|
249
|
+
const instance = getCurrentInstance();
|
|
250
|
+
const firstTime = ref<boolean>(true);
|
|
251
|
+
const scrollLeft = ref<number>(0);
|
|
252
|
+
const scrollViewWidth = ref<number>(0);
|
|
253
|
+
const lineOffsetLeft = ref<number>(0);
|
|
209
254
|
const tabsRect = ref<UniApp.NodeInfo>({
|
|
210
255
|
left: 0,
|
|
211
|
-
})
|
|
212
|
-
const innerCurrent = ref<number>(0)
|
|
256
|
+
});
|
|
257
|
+
const innerCurrent = ref<number>(0);
|
|
213
258
|
|
|
214
259
|
watch(
|
|
215
|
-
() => current
|
|
260
|
+
() => props.current,
|
|
216
261
|
(newValue: number) => {
|
|
217
262
|
// 内外部值不相等时,才尝试移动滑块
|
|
218
263
|
if (newValue !== innerCurrent.value) {
|
|
219
|
-
innerCurrent.value = newValue
|
|
264
|
+
innerCurrent.value = newValue;
|
|
220
265
|
nextTick(() => {
|
|
221
|
-
resize()
|
|
222
|
-
})
|
|
266
|
+
resize();
|
|
267
|
+
});
|
|
223
268
|
}
|
|
224
269
|
},
|
|
225
270
|
{ immediate: true },
|
|
226
|
-
)
|
|
271
|
+
);
|
|
227
272
|
watch(
|
|
228
|
-
() => list
|
|
273
|
+
() => props.list,
|
|
229
274
|
() => resize(),
|
|
230
|
-
)
|
|
275
|
+
);
|
|
231
276
|
|
|
232
277
|
const textStyle = computed(() => {
|
|
233
278
|
return (index: number): CSSProperties => {
|
|
234
|
-
const style: CSSProperties = {}
|
|
279
|
+
const style: CSSProperties = {};
|
|
235
280
|
// 取当期是否激活的样式
|
|
236
|
-
const customStyle_1 =
|
|
281
|
+
const customStyle_1 =
|
|
282
|
+
index == innerCurrent.value ? props.activeStyle : props.inactiveStyle;
|
|
237
283
|
// 如果当前菜单被禁用,则加上对应颜色,需要在此做处理,是因为nvue下,无法在style样式中通过!import覆盖标签的内联样式
|
|
238
|
-
if (list
|
|
239
|
-
style.color =
|
|
284
|
+
if (props.list[index]?.disabled) {
|
|
285
|
+
style.color = "#c8c9cc";
|
|
240
286
|
}
|
|
241
|
-
return Object.assign(customStyle_1, style)
|
|
242
|
-
}
|
|
243
|
-
})
|
|
287
|
+
return Object.assign(customStyle_1, style);
|
|
288
|
+
};
|
|
289
|
+
});
|
|
244
290
|
|
|
245
291
|
onMounted(() => {
|
|
246
|
-
resize()
|
|
247
|
-
})
|
|
292
|
+
resize();
|
|
293
|
+
});
|
|
248
294
|
|
|
249
295
|
/**
|
|
250
296
|
* @description 设置线左边距离
|
|
251
297
|
*/
|
|
252
298
|
const setLineLeft = () => {
|
|
253
|
-
const tabItem = list
|
|
299
|
+
const tabItem = props.list[innerCurrent.value];
|
|
254
300
|
if (!tabItem) {
|
|
255
|
-
return
|
|
301
|
+
return;
|
|
256
302
|
}
|
|
257
303
|
// 获取滑块该移动的位置
|
|
258
|
-
let lineOffsetLeft_1 = list
|
|
304
|
+
let lineOffsetLeft_1 = props.list
|
|
259
305
|
.slice(0, innerCurrent.value)
|
|
260
|
-
.reduce((total, curr) => total + curr.rect.width, 0)
|
|
306
|
+
.reduce((total, curr) => total + curr.rect.width, 0);
|
|
261
307
|
// 获取下划线的数值px表示法
|
|
262
|
-
lineOffsetLeft.value =
|
|
308
|
+
lineOffsetLeft.value =
|
|
309
|
+
lineOffsetLeft_1 + (tabItem.rect.width - getPx(props.lineWidth)) / 2;
|
|
263
310
|
|
|
264
311
|
// 如果是第一次执行此方法,让滑块在初始化时,瞬间滑动到第一个tab item的中间
|
|
265
312
|
// 这里需要一个定时器,因为在非nvue下,是直接通过style绑定过渡时间,需要等其过渡完成后,再设置为false(非第一次移动滑块)
|
|
266
313
|
if (firstTime.value) {
|
|
267
314
|
sleep().then(() => {
|
|
268
|
-
firstTime.value = false
|
|
269
|
-
})
|
|
315
|
+
firstTime.value = false;
|
|
316
|
+
});
|
|
270
317
|
}
|
|
271
|
-
}
|
|
318
|
+
};
|
|
272
319
|
// 点击某一个标签
|
|
273
320
|
const clickHandler = (item: TabsItemVo, index: number) => {
|
|
274
321
|
// 因为标签可能为disabled状态,所以click是一定会发出的,但是change事件是需要可用的状态才发出
|
|
275
|
-
emit(
|
|
322
|
+
emit("click", {
|
|
276
323
|
...item,
|
|
277
324
|
index,
|
|
278
|
-
})
|
|
325
|
+
});
|
|
279
326
|
// 如果disabled状态,返回
|
|
280
|
-
if (item.disabled) return
|
|
281
|
-
innerCurrent.value = index
|
|
282
|
-
resize()
|
|
283
|
-
emit(
|
|
284
|
-
emit(
|
|
285
|
-
}
|
|
327
|
+
if (item.disabled) return;
|
|
328
|
+
innerCurrent.value = index;
|
|
329
|
+
resize();
|
|
330
|
+
emit("update:current", index);
|
|
331
|
+
emit("change", item, index);
|
|
332
|
+
};
|
|
286
333
|
// 长按事件
|
|
287
334
|
const longPressHandler = (item: TabsItemVo, index: number) => {
|
|
288
|
-
emit(
|
|
335
|
+
emit("longPress", {
|
|
289
336
|
...item,
|
|
290
337
|
index,
|
|
291
|
-
})
|
|
292
|
-
}
|
|
338
|
+
});
|
|
339
|
+
};
|
|
293
340
|
const setScrollLeft = () => {
|
|
294
341
|
// 当前活动tab的布局信息,有tab菜单的width和left(为元素左边界到父元素左边界的距离)等信息
|
|
295
342
|
if (innerCurrent.value < 0) {
|
|
296
|
-
innerCurrent.value = 0
|
|
343
|
+
innerCurrent.value = 0;
|
|
297
344
|
}
|
|
298
|
-
const tabRect = list
|
|
345
|
+
const tabRect = props.list[innerCurrent.value];
|
|
299
346
|
// 累加得到当前item到左边的距离
|
|
300
|
-
const offsetLeft = list
|
|
301
|
-
|
|
302
|
-
|
|
347
|
+
const offsetLeft = props.list
|
|
348
|
+
.slice(0, innerCurrent.value)
|
|
349
|
+
.reduce((total: number, curr) => {
|
|
350
|
+
return total + curr.rect.width;
|
|
351
|
+
}, 0);
|
|
303
352
|
// 此处为屏幕宽度
|
|
304
|
-
const windowWidth = uni.getWindowInfo().windowWidth
|
|
353
|
+
const windowWidth = uni.getWindowInfo().windowWidth;
|
|
305
354
|
// 将活动的tabs-item移动到屏幕正中间,实际上是对scroll-view的移动
|
|
306
355
|
let scrollLeft_1 =
|
|
307
356
|
offsetLeft -
|
|
308
357
|
((tabsRect.value.width || 0) - tabRect.rect.width) / 2 -
|
|
309
358
|
(windowWidth - (tabsRect.value.right || 0)) / 2 +
|
|
310
|
-
(tabsRect.value.left || 0) / 2
|
|
359
|
+
(tabsRect.value.left || 0) / 2;
|
|
311
360
|
// 这里做一个限制,限制scrollLeft的最大值为整个scroll-view宽度减去tabs组件的宽度
|
|
312
|
-
scrollLeft_1 = Math.min(
|
|
313
|
-
|
|
314
|
-
|
|
361
|
+
scrollLeft_1 = Math.min(
|
|
362
|
+
scrollLeft_1,
|
|
363
|
+
scrollViewWidth.value - (tabsRect.value.width || 0),
|
|
364
|
+
);
|
|
365
|
+
scrollLeft.value = Math.max(0, scrollLeft_1);
|
|
366
|
+
};
|
|
315
367
|
/**
|
|
316
368
|
* @description 获取所有标签的尺寸
|
|
317
369
|
* */
|
|
318
370
|
const resize = () => {
|
|
319
371
|
// 如果不存在list,则不处理
|
|
320
|
-
if (list.
|
|
321
|
-
return
|
|
372
|
+
if (props.list.length === 0) {
|
|
373
|
+
return;
|
|
322
374
|
}
|
|
323
375
|
Promise.all([getTabsRect(), getAllItemRect()]).then(
|
|
324
376
|
([tabsRect_1, itemRect = []]: (UniApp.NodeInfo | any)[]) => {
|
|
@@ -330,57 +382,60 @@ const resize = () => {
|
|
|
330
382
|
tabsRect_1.left > tabsRect_1.width
|
|
331
383
|
) {
|
|
332
384
|
tabsRect_1.right =
|
|
333
|
-
tabsRect_1.right -
|
|
334
|
-
|
|
385
|
+
tabsRect_1.right -
|
|
386
|
+
Math.floor(tabsRect_1.left / tabsRect_1.width) * tabsRect_1.width;
|
|
387
|
+
tabsRect_1.left = tabsRect_1.left % tabsRect_1.width;
|
|
335
388
|
}
|
|
336
389
|
// console.log(tabsRect)
|
|
337
|
-
tabsRect.value = tabsRect_1
|
|
338
|
-
scrollViewWidth.value = 0
|
|
390
|
+
tabsRect.value = tabsRect_1;
|
|
391
|
+
scrollViewWidth.value = 0;
|
|
339
392
|
itemRect.map((item: UniApp.NodeInfo, index: number) => {
|
|
340
393
|
// 计算scroll-view的宽度,这里
|
|
341
|
-
scrollViewWidth.value += item.width || 0
|
|
394
|
+
scrollViewWidth.value += item.width || 0;
|
|
342
395
|
// 另外计算每一个item的中心点X轴坐标
|
|
343
|
-
list
|
|
344
|
-
})
|
|
396
|
+
props.list[index].rect = item;
|
|
397
|
+
});
|
|
345
398
|
// 获取了tabs的尺寸之后,设置滑块的位置
|
|
346
|
-
setLineLeft()
|
|
347
|
-
setScrollLeft()
|
|
399
|
+
setLineLeft();
|
|
400
|
+
setScrollLeft();
|
|
348
401
|
},
|
|
349
|
-
)
|
|
350
|
-
}
|
|
402
|
+
);
|
|
403
|
+
};
|
|
351
404
|
/**
|
|
352
405
|
* @description 获取导航菜单的尺寸
|
|
353
406
|
* */
|
|
354
407
|
const getTabsRect = () => {
|
|
355
408
|
return new Promise((resolve) => {
|
|
356
|
-
getRect(
|
|
357
|
-
|
|
358
|
-
|
|
409
|
+
getRect(".hy-tabs__wrapper__scroll-view", false, instance).then((size) =>
|
|
410
|
+
resolve(size),
|
|
411
|
+
);
|
|
412
|
+
});
|
|
413
|
+
};
|
|
359
414
|
/**
|
|
360
415
|
* @description 获取所有标签的尺寸
|
|
361
416
|
* */
|
|
362
417
|
const getAllItemRect = () => {
|
|
363
418
|
return new Promise((resolve) => {
|
|
364
|
-
const promiseAllArr = list.
|
|
419
|
+
const promiseAllArr = props.list.map((item, index) =>
|
|
365
420
|
getRect(`.hy-tabs__wrapper__nav__item-${index}`, false, instance),
|
|
366
|
-
)
|
|
367
|
-
Promise.all(promiseAllArr).then((sizes) => resolve(sizes))
|
|
368
|
-
})
|
|
369
|
-
}
|
|
421
|
+
);
|
|
422
|
+
Promise.all(promiseAllArr).then((sizes) => resolve(sizes));
|
|
423
|
+
});
|
|
424
|
+
};
|
|
370
425
|
|
|
371
426
|
/**
|
|
372
427
|
* 滑动页面改变当前值
|
|
373
428
|
* */
|
|
374
429
|
const animationFinish = (e: any) => {
|
|
375
430
|
// 轮播图选项值
|
|
376
|
-
innerCurrent.value = e.detail.current
|
|
377
|
-
resize()
|
|
378
|
-
if (e.detail.source ===
|
|
379
|
-
emit(
|
|
431
|
+
innerCurrent.value = e.detail.current;
|
|
432
|
+
resize();
|
|
433
|
+
if (e.detail.source === "touch") {
|
|
434
|
+
emit("change", props.list[props.current], props.current);
|
|
380
435
|
}
|
|
381
|
-
}
|
|
436
|
+
};
|
|
382
437
|
</script>
|
|
383
438
|
|
|
384
439
|
<style lang="scss" scoped>
|
|
385
|
-
@import
|
|
440
|
+
@import "./index.scss";
|
|
386
441
|
</style>
|