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,533 +1,444 @@
1
1
  <template>
2
- <view :class="['hy-slider', customClass]" :style="[customStyle]">
3
- <template v-if="!useNative || isRange">
4
- <view
5
- ref="hy-slider__inner"
6
- class="hy-slider__inner"
7
- @tap="onClick"
8
- @onTouchStart="onTouchStart2($event, 1)"
9
- @touchmove="onTouchMove2($event, 1)"
10
- @touchend="onTouchEnd2($event, 1)"
11
- @touchcancel="onTouchEnd2($event, 1)"
12
- :class="[disabled ? 'hy-slider__disabled' : '']"
13
- :style="{
14
- height:
15
- isRange && showValue
16
- ? addUnit(getPx(blockSize) + 24)
17
- : addUnit(blockSize),
18
- }"
19
- >
20
- <view
21
- ref="hy-slider__base"
22
- class="hy-slider__base"
23
- :style="[
24
- {
25
- height: addUnit(height),
26
- backgroundColor: inactiveColor,
27
- },
28
- ]"
29
- ></view>
30
- <view
31
- @tap="onClick"
32
- class="hy-slider__gap"
33
- :style="[
34
- barStyle,
35
- {
36
- height: addUnit(height),
37
- marginTop: '-' + addUnit(height),
38
- backgroundColor: activeColor,
39
- },
40
- ]"
41
- ></view>
42
- <view
43
- v-if="isRange"
44
- class="hy-slider__gap hy-slider__gap-0"
45
- :style="[
46
- barStyle0,
47
- {
48
- height: addUnit(height),
49
- marginTop: '-' + addUnit(height),
50
- backgroundColor: inactiveColor,
51
- },
52
- ]"
53
- ></view>
54
- <text
55
- v-if="isRange && showValue"
56
- class="hy-slider__show-range-value"
57
- :style="{
58
- left: blockLeft(barStyle0?.width, blockSize),
59
- }"
60
- >
61
- {{ rangeValue[0] }}
62
- </text>
63
- <text
64
- v-if="isRange && showValue"
65
- class="hy-slider__show-range-value"
66
- :style="{
67
- left: blockLeft(barStyle?.width, blockSize),
68
- }"
69
- >
70
- {{ rangeValue[1] }}
71
- </text>
72
- <template v-if="isRange">
73
- <view
74
- class="hy-slider__button--wrap hy-slider__button--wrap-0"
75
- @touchstart="onTouchStart($event, 0)"
76
- @touchmove="onTouchMove($event, 0)"
77
- @touchend="onTouchEnd($event, 0)"
78
- @touchcancel="onTouchEnd($event, 0)"
79
- :style="{
80
- left: blockLeft(barStyle0?.width, blockSize),
81
- }"
82
- >
83
- <slot name="min" v-if="$slots.min || $slots.$min" />
2
+ <view :class="['hy-slider', customClass]" :style="[customStyle]">
3
+ <template v-if="!useNative || isRange">
84
4
  <view
85
- v-else
86
- class="hy-slider__button"
87
- :style="[
88
- blockStyle,
89
- {
90
- height: addUnit(blockSize),
91
- width: addUnit(blockSize),
92
- backgroundColor: blockColor,
93
- },
94
- ]"
95
- ></view>
96
- </view>
5
+ ref="hy-slider__inner"
6
+ class="hy-slider__inner"
7
+ @tap="onClick"
8
+ @onTouchStart="onTouchStart2($event, 1)"
9
+ @touchmove="onTouchMove2($event, 1)"
10
+ @touchend="onTouchEnd2($event, 1)"
11
+ @touchcancel="onTouchEnd2($event, 1)"
12
+ :class="[disabled ? 'hy-slider__disabled' : '']"
13
+ :style="{
14
+ height:
15
+ isRange && showValue ? addUnit(getPx(blockSize) + 24) : addUnit(blockSize)
16
+ }"
17
+ >
18
+ <view
19
+ ref="hy-slider__base"
20
+ class="hy-slider__base"
21
+ :style="[
22
+ {
23
+ height: addUnit(height),
24
+ backgroundColor: inactiveColor
25
+ }
26
+ ]"
27
+ ></view>
28
+ <view
29
+ @tap="onClick"
30
+ class="hy-slider__gap"
31
+ :style="[
32
+ barStyle,
33
+ {
34
+ height: addUnit(height),
35
+ marginTop: '-' + addUnit(height),
36
+ backgroundColor: activeColor
37
+ }
38
+ ]"
39
+ ></view>
40
+ <view
41
+ v-if="isRange"
42
+ class="hy-slider__gap hy-slider__gap-0"
43
+ :style="[
44
+ barStyle0,
45
+ {
46
+ height: addUnit(height),
47
+ marginTop: '-' + addUnit(height),
48
+ backgroundColor: inactiveColor
49
+ }
50
+ ]"
51
+ ></view>
52
+ <text
53
+ v-if="isRange && showValue"
54
+ class="hy-slider__show-range-value"
55
+ :style="{
56
+ left: blockLeft(barStyle0?.width, blockSize)
57
+ }"
58
+ >
59
+ {{ rangeValue[0] }}
60
+ </text>
61
+ <text
62
+ v-if="isRange && showValue"
63
+ class="hy-slider__show-range-value"
64
+ :style="{
65
+ left: blockLeft(barStyle?.width, blockSize)
66
+ }"
67
+ >
68
+ {{ rangeValue[1] }}
69
+ </text>
70
+ <template v-if="isRange">
71
+ <view
72
+ class="hy-slider__button--wrap hy-slider__button--wrap-0"
73
+ @touchstart="onTouchStart($event, 0)"
74
+ @touchmove="onTouchMove($event, 0)"
75
+ @touchend="onTouchEnd($event, 0)"
76
+ @touchcancel="onTouchEnd($event, 0)"
77
+ :style="{
78
+ left: blockLeft(barStyle0?.width, blockSize)
79
+ }"
80
+ >
81
+ <slot name="min" v-if="$slots.min || $slots.$min" />
82
+ <view
83
+ v-else
84
+ class="hy-slider__button"
85
+ :style="[
86
+ blockStyle,
87
+ {
88
+ height: addUnit(blockSize),
89
+ width: addUnit(blockSize),
90
+ backgroundColor: blockColor
91
+ }
92
+ ]"
93
+ ></view>
94
+ </view>
95
+ </template>
96
+ <view
97
+ class="hy-slider__button--wrap"
98
+ @touchstart="onTouchStart"
99
+ @touchmove="onTouchMove"
100
+ @touchend="onTouchEnd"
101
+ @touchcancel="onTouchEnd"
102
+ :style="{
103
+ left: blockLeft(barStyle?.width, blockSize)
104
+ }"
105
+ >
106
+ <slot name="max" v-if="isRange && ($slots.max || $slots.$max)" />
107
+ <slot v-else-if="$slots.default || $slots.$default" />
108
+ <view
109
+ v-else
110
+ class="hy-slider__button"
111
+ :style="[
112
+ blockStyle,
113
+ {
114
+ height: addUnit(blockSize),
115
+ width: addUnit(blockSize),
116
+ backgroundColor: blockColor
117
+ }
118
+ ]"
119
+ ></view>
120
+ </view>
121
+ </view>
122
+ <view class="hy-slider__show-value" v-if="showValue && !isRange">{{ modelValue }}</view>
97
123
  </template>
98
- <view
99
- class="hy-slider__button--wrap"
100
- @touchstart="onTouchStart"
101
- @touchmove="onTouchMove"
102
- @touchend="onTouchEnd"
103
- @touchcancel="onTouchEnd"
104
- :style="{
105
- left: blockLeft(barStyle?.width, blockSize),
106
- }"
107
- >
108
- <slot name="max" v-if="isRange && ($slots.max || $slots.$max)" />
109
- <slot v-else-if="$slots.default || $slots.$default" />
110
- <view
124
+ <slider
125
+ class="hy-slider__native"
111
126
  v-else
112
- class="hy-slider__button"
113
- :style="[
114
- blockStyle,
115
- {
116
- height: addUnit(blockSize),
117
- width: addUnit(blockSize),
118
- backgroundColor: blockColor,
119
- },
120
- ]"
121
- ></view>
122
- </view>
123
- </view>
124
- <view class="hy-slider__show-value" v-if="showValue && !isRange">{{
125
- modelValue
126
- }}</view>
127
- </template>
128
- <slider
129
- class="hy-slider__native"
130
- v-else
131
- :min="min"
132
- :max="max"
133
- :step="step"
134
- :value="modelValue"
135
- :activeColor="activeColor"
136
- :backgroundColor="inactiveColor"
137
- :blockSize="blockSize"
138
- :blockColor="blockColor"
139
- :showValue="showValue"
140
- :disabled="disabled"
141
- @changing="changingHandler"
142
- @change="changeHandler"
143
- ></slider>
144
- </view>
127
+ :min="min"
128
+ :max="max"
129
+ :step="step"
130
+ :value="modelValue"
131
+ :activeColor="activeColor"
132
+ :backgroundColor="inactiveColor"
133
+ :blockSize="blockSize"
134
+ :blockColor="blockColor"
135
+ :showValue="showValue"
136
+ :disabled="disabled"
137
+ @changing="changingHandler"
138
+ @change="changeHandler"
139
+ ></slider>
140
+ </view>
145
141
  </template>
146
142
 
147
143
  <script lang="ts">
148
144
  export default {
149
- name: "hy-slider",
150
- options: {
151
- addGlobalClass: true,
152
- virtualHost: true,
153
- styleIsolation: "shared",
154
- },
155
- };
145
+ name: 'hy-slider',
146
+ options: {
147
+ addGlobalClass: true,
148
+ virtualHost: true,
149
+ styleIsolation: 'shared'
150
+ }
151
+ }
156
152
  </script>
157
153
 
158
154
  <script setup lang="ts">
159
- import { computed, getCurrentInstance, onMounted, ref, watch } from "vue";
160
- import type { CSSProperties, PropType } from "vue";
161
- import { addUnit, error, getRect, getPx } from "../../libs";
162
- import type { ISliderEmits } from "./typing";
163
- import type { SliderOnChangingEvent } from "@uni-helper/uni-types";
155
+ import { computed, getCurrentInstance, onMounted, ref, watch } from 'vue'
156
+ import type { CSSProperties } from 'vue'
157
+ import { addUnit, error, getRect, getPx } from '../../libs'
158
+ import type { ISliderEmits } from './typing'
159
+ import type { SliderOnChangingEvent } from '@uni-helper/uni-types'
160
+ import sliderProps from './props'
164
161
 
165
162
  /**
166
163
  * 一般用于表单中,手动选择一个区间范围的场景。
167
164
  * @displayName hy-slider
168
165
  */
169
- defineOptions({});
166
+ defineOptions({})
170
167
 
171
- // const props = withDefaults(defineProps<IProps>(), defaultProps);
172
- const props = defineProps({
173
- /** 滑块默认值 */
174
- modelValue: {
175
- type: Number,
176
- default: 0,
177
- },
178
- /** 滑块的大小,取值范围为 12 - 28 */
179
- blockSize: {
180
- type: [String, Number],
181
- default: 18,
182
- },
183
- /** 最小值 */
184
- min: {
185
- type: Number,
186
- default: 0,
187
- },
188
- /** 最大值 */
189
- max: {
190
- type: Number,
191
- default: 100,
192
- },
193
- /** 步长 */
194
- step: {
195
- type: Number,
196
- default: 1,
197
- },
198
- /** 底部选择部分的背景颜色 */
199
- activeColor: String,
200
- /** 底部条背景颜色 */
201
- inactiveColor: String,
202
- /** 滑块颜色 */
203
- blockColor: String,
204
- /** 是否显示当前的选择值 */
205
- showValue: {
206
- type: Boolean,
207
- default: false,
208
- },
209
- /** 是否禁用滑块 */
210
- disabled: {
211
- type: Boolean,
212
- default: false,
213
- },
214
- /** 是否渲染uni-app框架内置组件 */
215
- useNative: {
216
- type: Boolean,
217
- default: false,
218
- },
219
- /** 滑块条高度,单位rpx */
220
- height: {
221
- type: [String, Number],
222
- default: 2,
223
- },
224
- /** 双滑块时值 */
225
- rangeValue: {
226
- type: Array as unknown as PropType<number[]>,
227
- default: [0, 0],
228
- },
229
- /** 是否区间的模式 */
230
- isRange: {
231
- type: Boolean,
232
- default: false,
233
- },
234
- /** 给滑块自定义样式,对象形式 */
235
- blockStyle: {
236
- type: Object as PropType<CSSProperties>,
237
- },
238
- /** 定义需要用到的外部样式 */
239
- customStyle: {
240
- type: Object as PropType<CSSProperties>,
241
- },
242
- /** 自定义外部类名 */
243
- customClass: String,
244
- });
245
- const emit = defineEmits<ISliderEmits>();
168
+ const props = defineProps(sliderProps)
169
+ const emit = defineEmits<ISliderEmits>()
246
170
 
247
- const startX = ref(0);
248
- const status = ref("end");
249
- const newValue = ref(0);
250
- const distanceX = ref(0);
251
- const startValue0 = ref(0);
252
- const startValue = ref(0);
253
- const barStyle0 = ref<CSSProperties>();
254
- const barStyle = ref<CSSProperties>();
171
+ const startX = ref(0)
172
+ const status = ref('end')
173
+ const newValue = ref(0)
174
+ const distanceX = ref(0)
175
+ const startValue0 = ref(0)
176
+ const startValue = ref(0)
177
+ const barStyle0 = ref<CSSProperties>()
178
+ const barStyle = ref<CSSProperties>()
255
179
  const sliderRect = ref<UniNamespace.NodeInfo>({
256
- left: 0,
257
- width: 0,
258
- });
259
- const instance = getCurrentInstance();
180
+ left: 0,
181
+ width: 0
182
+ })
183
+ const instance = getCurrentInstance()
260
184
 
261
185
  const blockLeft = computed(() => {
262
- return (
263
- slideWidth: string | number | undefined,
264
- blockWidth: string | number,
265
- ): string => {
266
- if (slideWidth) {
267
- return addUnit(getPx(slideWidth) + getPx(blockWidth) / 2);
186
+ return (slideWidth: string | number | undefined, blockWidth: string | number): string => {
187
+ if (slideWidth) {
188
+ return addUnit(getPx(slideWidth) + getPx(blockWidth) / 2)
189
+ }
190
+ return '0px'
268
191
  }
269
- return "0px";
270
- };
271
- });
192
+ })
272
193
 
273
194
  watch(
274
- () => props.modelValue,
275
- (newValue) => {
276
- // 只有在非滑动状态时,才可以通过value更新滑块值,这里监听,是为了让用户触发
277
- if (status.value === "end") updateValue(newValue, false);
278
- },
279
- );
195
+ () => props.modelValue,
196
+ (newValue) => {
197
+ // 只有在非滑动状态时,才可以通过value更新滑块值,这里监听,是为了让用户触发
198
+ if (status.value === 'end') updateValue(newValue, false)
199
+ }
200
+ )
280
201
 
281
202
  watch(
282
- () => props.rangeValue,
283
- (newValue) => {
284
- if (status.value === "end") {
285
- updateValue(newValue[0], false, 0);
286
- updateValue(newValue[1], false, 1);
287
- }
288
- },
289
- { deep: true },
290
- );
203
+ () => props.rangeValue,
204
+ (newValue) => {
205
+ if (status.value === 'end') {
206
+ updateValue(newValue[0], false, 0)
207
+ updateValue(newValue[1], false, 1)
208
+ }
209
+ },
210
+ { deep: true }
211
+ )
291
212
 
292
213
  onMounted(async () => {
293
- // 获取滑块条的尺寸信息
294
- if (!props.useNative) {
295
- // #ifndef APP-NVUE
296
- sliderRect.value = (await getRect(
297
- ".hy-slider__base",
298
- false,
299
- instance,
300
- )) as UniNamespace.NodeInfo;
301
- // console.log('sliderRect', sliderRect.value)
302
- if (sliderRect.value.width == 0) {
303
- error("如在弹窗等元素中使用,请使用v-if来显示滑块,否则无法计算长度。");
214
+ // 获取滑块条的尺寸信息
215
+ if (!props.useNative) {
216
+ // #ifndef APP-NVUE
217
+ sliderRect.value = (await getRect(
218
+ '.hy-slider__base',
219
+ false,
220
+ instance
221
+ )) as UniNamespace.NodeInfo
222
+ // console.log('sliderRect', sliderRect.value)
223
+ if (sliderRect.value.width == 0) {
224
+ error('如在弹窗等元素中使用,请使用v-if来显示滑块,否则无法计算长度。')
225
+ }
226
+ init()
227
+ // #endif
304
228
  }
305
- init();
306
- // #endif
307
- }
308
- });
229
+ })
309
230
 
310
231
  const init = () => {
311
- if (props.isRange) {
312
- updateValue(props.rangeValue[0], false, 0);
313
- updateValue(props.rangeValue[1], false, 1);
314
- } else {
315
- updateValue(props.modelValue, false);
316
- }
317
- };
232
+ if (props.isRange) {
233
+ updateValue(props.rangeValue[0], false, 0)
234
+ updateValue(props.rangeValue[1], false, 1)
235
+ } else {
236
+ updateValue(props.modelValue, false)
237
+ }
238
+ }
318
239
 
319
240
  // native拖动过程中触发
320
241
  const changingHandler = (e: SliderOnChangingEvent) => {
321
- const { value } = e.detail;
322
- // 更新v-model的值
323
- emit("update:modelValue", value);
324
- // 触发事件
325
- emit("changing", value);
326
- };
242
+ const { value } = e.detail
243
+ // 更新v-model的值
244
+ emit('update:modelValue', value)
245
+ // 触发事件
246
+ emit('changing', value)
247
+ }
327
248
 
328
249
  // native滑动结束时触发
329
250
  const changeHandler = (e: SliderOnChangingEvent) => {
330
- const { value } = e.detail;
331
- // 更新v-model的值
332
- emit("update:modelValue", value);
333
- // 触发事件
334
- emit("change", value);
335
- };
251
+ const { value } = e.detail
252
+ // 更新v-model的值
253
+ emit('update:modelValue', value)
254
+ // 触发事件
255
+ emit('change', value)
256
+ }
336
257
 
337
258
  const onTouchStart = (e: TouchEvent, index = 1) => {
338
- if (props.disabled) return;
339
- startX.value = 0;
340
- // 触摸点集
341
- let touches = e.touches[0];
342
- // 触摸点到屏幕左边的距离
343
- startX.value = touches.clientX;
344
- // 此处的this.modelValue虽为props值,但是通过$emit('update:modelValue')进行了修改
345
- if (props.isRange) {
346
- startValue0.value = format(props.rangeValue[0], 0);
347
- startValue.value = format(props.rangeValue[1], 1);
348
- } else {
349
- startValue.value = format(props.modelValue);
350
- }
351
- // 标示当前的状态为开始触摸滑动
352
- status.value = "start";
259
+ if (props.disabled) return
260
+ startX.value = 0
261
+ // 触摸点集
262
+ let touches = e.touches[0]
263
+ // 触摸点到屏幕左边的距离
264
+ startX.value = touches.clientX
265
+ // 此处的this.modelValue虽为props值,但是通过$emit('update:modelValue')进行了修改
266
+ if (props.isRange) {
267
+ startValue0.value = format(props.rangeValue[0], 0)
268
+ startValue.value = format(props.rangeValue[1], 1)
269
+ } else {
270
+ startValue.value = format(props.modelValue)
271
+ }
272
+ // 标示当前的状态为开始触摸滑动
273
+ status.value = 'start'
353
274
 
354
- let clientX = 0;
355
- // #ifndef APP-NVUE
356
- clientX = touches.clientX;
357
- // #endif
358
- // #ifdef APP-NVUE
359
- clientX = touches.screenX;
360
- // #endif
361
- distanceX.value = clientX - sliderRect.value.left!;
362
- // 获得移动距离对整个滑块的值,此为带有多位小数的值,不能用此更新视图
363
- // 否则造成通信阻塞,需要每改变一个step值时修改一次视图
364
- newValue.value =
365
- (distanceX.value / sliderRect.value.width!) * (props.max - props.min) +
366
- props.min;
367
- status.value = "moving";
368
- // 发出moving事件
369
- let $crtFmtValue = updateValue(newValue.value, true, index);
370
- emit("changing", $crtFmtValue);
371
- };
275
+ let clientX = 0
276
+ // #ifndef APP-NVUE
277
+ clientX = touches.clientX
278
+ // #endif
279
+ // #ifdef APP-NVUE
280
+ clientX = touches.screenX
281
+ // #endif
282
+ distanceX.value = clientX - sliderRect.value.left!
283
+ // 获得移动距离对整个滑块的值,此为带有多位小数的值,不能用此更新视图
284
+ // 否则造成通信阻塞,需要每改变一个step值时修改一次视图
285
+ newValue.value =
286
+ (distanceX.value / sliderRect.value.width!) * (props.max - props.min) + props.min
287
+ status.value = 'moving'
288
+ // 发出moving事件
289
+ let $crtFmtValue = updateValue(newValue.value, true, index)
290
+ emit('changing', $crtFmtValue)
291
+ }
372
292
  const onTouchMove = (e: TouchEvent, index = 1) => {
373
- if (props.disabled) return;
374
- // 连续触摸的过程会一直触发本方法,但只有手指触发且移动了才被认为是拖动了,才发出事件
375
- // 触摸后第一次移动已经将status设置为moving状态,故触摸第二次移动不会触发本事件
376
- if (status.value == "start") emit("start");
377
- let touches = e.touches[0];
378
- // console.log('touchs', touches)
379
- // 滑块的左边不一定跟屏幕左边接壤,所以需要减去最外层父元素的左边值
380
- let clientX = 0;
381
- // #ifndef APP-NVUE
382
- clientX = touches.clientX;
383
- // #endif
384
- // #ifdef APP-NVUE
385
- clientX = touches.screenX;
386
- // #endif
387
- distanceX.value = clientX - sliderRect.value.left!;
388
- // 获得移动距离对整个滑块的值,此为带有多位小数的值,不能用此更新视图
389
- // 否则造成通信阻塞,需要每改变一个step值时修改一次视图
390
- newValue.value =
391
- (distanceX.value / sliderRect.value.width!) * (props.max - props.min) +
392
- props.min;
393
- status.value = "moving";
394
- // 发出moving事件
395
- let $crtFmtValue = updateValue(newValue.value, true, index);
396
- emit("changing", $crtFmtValue);
397
- };
293
+ if (props.disabled) return
294
+ // 连续触摸的过程会一直触发本方法,但只有手指触发且移动了才被认为是拖动了,才发出事件
295
+ // 触摸后第一次移动已经将status设置为moving状态,故触摸第二次移动不会触发本事件
296
+ if (status.value == 'start') emit('start')
297
+ let touches = e.touches[0]
298
+ // console.log('touchs', touches)
299
+ // 滑块的左边不一定跟屏幕左边接壤,所以需要减去最外层父元素的左边值
300
+ let clientX = 0
301
+ // #ifndef APP-NVUE
302
+ clientX = touches.clientX
303
+ // #endif
304
+ // #ifdef APP-NVUE
305
+ clientX = touches.screenX
306
+ // #endif
307
+ distanceX.value = clientX - sliderRect.value.left!
308
+ // 获得移动距离对整个滑块的值,此为带有多位小数的值,不能用此更新视图
309
+ // 否则造成通信阻塞,需要每改变一个step值时修改一次视图
310
+ newValue.value =
311
+ (distanceX.value / sliderRect.value.width!) * (props.max - props.min) + props.min
312
+ status.value = 'moving'
313
+ // 发出moving事件
314
+ let $crtFmtValue = updateValue(newValue.value, true, index)
315
+ emit('changing', $crtFmtValue)
316
+ }
398
317
  const onTouchEnd = (e: TouchEvent, index = 1) => {
399
- if (props.disabled) return;
400
- if (status.value === "moving") {
401
- let $crtFmtValue = updateValue(newValue.value, false, index);
402
- emit("change", $crtFmtValue);
403
- }
404
- status.value = "end";
405
- };
318
+ if (props.disabled) return
319
+ if (status.value === 'moving') {
320
+ let $crtFmtValue = updateValue(newValue.value, false, index)
321
+ emit('change', $crtFmtValue)
322
+ }
323
+ status.value = 'end'
324
+ }
406
325
  const onTouchStart2 = (e: TouchEvent, index = 1) => {
407
- if (!props.isRange) {
408
- // this.onChangeStart(event, index);
409
- }
410
- };
326
+ if (!props.isRange) {
327
+ // this.onChangeStart(event, index);
328
+ }
329
+ }
411
330
  const onTouchMove2 = (e: TouchEvent, index = 1) => {
412
- if (!props.isRange) {
413
- // this.onTouchMove(event, index);
414
- }
415
- };
331
+ if (!props.isRange) {
332
+ // this.onTouchMove(event, index);
333
+ }
334
+ }
416
335
  const onTouchEnd2 = (e: TouchEvent, index = 1) => {
417
- if (!props.isRange) {
418
- // this.onTouchEnd(event, index);
419
- }
420
- };
336
+ if (!props.isRange) {
337
+ // this.onTouchEnd(event, index);
338
+ }
339
+ }
421
340
  const onClick = (e: TouchEvent) => {
422
- if (props.disabled) return;
423
- // 直接点击滑块的情况,计算方式与onTouchMove方法相同
424
- // #ifndef APP-NVUE
341
+ if (props.disabled) return
342
+ // 直接点击滑块的情况,计算方式与onTouchMove方法相同
343
+ // #ifndef APP-NVUE
425
344
 
426
- let x;
427
- // #ifdef MP-ALIPAY
428
- x = e.detail.clientX;
429
- // #endif
430
- // #ifndef MP-ALIPAY
431
- x = e.detail.x;
432
- // #endif
345
+ let x
346
+ // #ifdef MP-ALIPAY
347
+ x = e.detail.clientX
348
+ // #endif
349
+ // #ifndef MP-ALIPAY
350
+ x = e.detail.x
351
+ // #endif
433
352
 
434
- const clientX = x - sliderRect.value.left!;
435
- newValue.value =
436
- (clientX / sliderRect.value.width!) * (props.max - props.min) + props.min;
437
- updateValue(newValue.value, false, 1);
438
- // #endif
439
- };
440
- const updateValue = (
441
- value: number,
442
- drag: boolean,
443
- index: number = 1,
444
- ): number | number[] => {
445
- // 去掉小数部分,同时也是对step步进的处理
446
- let valueFormat = format(value, index);
447
- // 不允许滑动的值超过max最大值
448
- if (valueFormat > props.max) {
449
- valueFormat = props.max;
450
- }
451
- // 设置移动的距离,不能用百分比,因为NVUE不支持。
452
- const width = Math.min(
453
- ((valueFormat - props.min) / (props.max - props.min)) *
454
- sliderRect.value.width!,
455
- sliderRect.value.width!,
456
- );
457
- const barStyle_1: CSSProperties = {
458
- width: width + "px",
459
- };
460
- // 移动期间无需过渡动画
461
- if (drag) {
462
- barStyle_1.transition = "none";
463
- } else {
464
- // 非移动期间,删掉对过渡为空的声明,让css中的声明起效
465
- delete barStyle_1.transition;
466
- }
467
- // 修改value值
468
- if (props.isRange) {
469
- props.rangeValue[index] = valueFormat;
470
- emit("update:modelValue", props.rangeValue);
471
- } else {
472
- emit("update:modelValue", valueFormat);
473
- }
353
+ const clientX = x - sliderRect.value.left!
354
+ newValue.value = (clientX / sliderRect.value.width!) * (props.max - props.min) + props.min
355
+ updateValue(newValue.value, false, 1)
356
+ // #endif
357
+ }
358
+ const updateValue = (value: number, drag: boolean, index: number = 1): number | number[] => {
359
+ // 去掉小数部分,同时也是对step步进的处理
360
+ let valueFormat = format(value, index)
361
+ // 不允许滑动的值超过max最大值
362
+ if (valueFormat > props.max) {
363
+ valueFormat = props.max
364
+ }
365
+ // 设置移动的距离,不能用百分比,因为NVUE不支持。
366
+ const width = Math.min(
367
+ ((valueFormat - props.min) / (props.max - props.min)) * sliderRect.value.width!,
368
+ sliderRect.value.width!
369
+ )
370
+ const barStyle_1: CSSProperties = {
371
+ width: width + 'px'
372
+ }
373
+ // 移动期间无需过渡动画
374
+ if (drag) {
375
+ barStyle_1.transition = 'none'
376
+ } else {
377
+ // 非移动期间,删掉对过渡为空的声明,让css中的声明起效
378
+ delete barStyle_1.transition
379
+ }
380
+ // 修改value值
381
+ if (props.isRange) {
382
+ props.rangeValue[index] = valueFormat
383
+ emit('update:modelValue', props.rangeValue)
384
+ } else {
385
+ emit('update:modelValue', valueFormat)
386
+ }
474
387
 
475
- switch (index) {
476
- case 0:
477
- barStyle0.value = barStyle_1;
478
- break;
479
- case 1:
480
- barStyle.value = barStyle_1;
481
- break;
482
- default:
483
- break;
484
- }
485
- if (props.isRange) {
486
- return props.rangeValue;
487
- } else {
488
- return valueFormat;
489
- }
490
- };
491
- const format = (value: number, index = 1): number => {
492
- // 将小数变成整数,为了减少对视图的更新,造成视图层与逻辑层的阻塞
493
- if (props.isRange) {
494
388
  switch (index) {
495
- case 0:
496
- return (
497
- Math.round(
498
- Math.max(
499
- props.min,
500
- Math.min(value, props.rangeValue[1] - props.step, props.max),
501
- ) / props.step,
502
- ) * props.step
503
- );
504
- case 1:
389
+ case 0:
390
+ barStyle0.value = barStyle_1
391
+ break
392
+ case 1:
393
+ barStyle.value = barStyle_1
394
+ break
395
+ default:
396
+ break
397
+ }
398
+ if (props.isRange) {
399
+ return props.rangeValue
400
+ } else {
401
+ return valueFormat
402
+ }
403
+ }
404
+ const format = (value: number, index = 1): number => {
405
+ // 将小数变成整数,为了减少对视图的更新,造成视图层与逻辑层的阻塞
406
+ if (props.isRange) {
407
+ switch (index) {
408
+ case 0:
409
+ return (
410
+ Math.round(
411
+ Math.max(
412
+ props.min,
413
+ Math.min(value, props.rangeValue[1] - props.step, props.max)
414
+ ) / props.step
415
+ ) * props.step
416
+ )
417
+ case 1:
418
+ return (
419
+ Math.round(
420
+ Math.max(
421
+ props.min,
422
+ props.rangeValue[0] + props.step,
423
+ Math.min(value, props.max)
424
+ ) / props.step
425
+ ) * props.step
426
+ )
427
+ default:
428
+ return 0
429
+ }
430
+ } else {
431
+ // 解决精度丢失
505
432
  return (
506
- Math.round(
507
- Math.max(
508
- props.min,
509
- props.rangeValue[0] + props.step,
510
- Math.min(value, props.max),
511
- ) / props.step,
512
- ) * props.step
513
- );
514
- default:
515
- return 0;
433
+ (Math.round(Math.max(props.min, Math.min(value, props.max)) / props.step) *
434
+ 1000 *
435
+ props.step) /
436
+ 1000
437
+ )
516
438
  }
517
- } else {
518
- // 解决精度丢失
519
- return (
520
- (Math.round(
521
- Math.max(props.min, Math.min(value, props.max)) / props.step,
522
- ) *
523
- 1000 *
524
- props.step) /
525
- 1000
526
- );
527
- }
528
- };
439
+ }
529
440
  </script>
530
441
 
531
442
  <style lang="scss" scoped>
532
- @import "./index.scss";
443
+ @import './index.scss';
533
444
  </style>