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