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