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