hy-app 0.1.1

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 (206) hide show
  1. package/README.md +42 -0
  2. package/api/http.ts +138 -0
  3. package/api/index.ts +1 -0
  4. package/common/index.ts +1 -0
  5. package/common/versionControl.ts +102 -0
  6. package/components/dialog/TheDialog.vue +128 -0
  7. package/components/dialog/index.ts +38 -0
  8. package/components/hy-address-picker/hy-address-picker.vue +262 -0
  9. package/components/hy-address-picker/props.ts +27 -0
  10. package/components/hy-address-picker/typing.d.ts +98 -0
  11. package/components/hy-avatar/hy-avatar.vue +217 -0
  12. package/components/hy-avatar/props.ts +20 -0
  13. package/components/hy-avatar/typing.d.ts +64 -0
  14. package/components/hy-back-top/hy-back-top.vue +71 -0
  15. package/components/hy-back-top/props.ts +23 -0
  16. package/components/hy-back-top/typing.d.ts +49 -0
  17. package/components/hy-badge/hy-badge.vue +155 -0
  18. package/components/hy-badge/props.ts +19 -0
  19. package/components/hy-badge/typing.d.ts +60 -0
  20. package/components/hy-button/hy-button.vue +394 -0
  21. package/components/hy-button/props.ts +36 -0
  22. package/components/hy-button/typing.d.ts +125 -0
  23. package/components/hy-card/hy-card.vue +198 -0
  24. package/components/hy-card/props.ts +29 -0
  25. package/components/hy-card/typing.d.ts +112 -0
  26. package/components/hy-cell/hy-cell.vue +268 -0
  27. package/components/hy-cell/props.ts +20 -0
  28. package/components/hy-cell/typing.d.ts +98 -0
  29. package/components/hy-check-button/hy-check-button.vue +71 -0
  30. package/components/hy-check-button/props.ts +20 -0
  31. package/components/hy-check-button/typing.d.ts +79 -0
  32. package/components/hy-checkbox/hy-checkbox.vue +299 -0
  33. package/components/hy-checkbox/props.ts +28 -0
  34. package/components/hy-checkbox/typing.d.ts +77 -0
  35. package/components/hy-datetime-picker/hy-datetime-picker.vue +584 -0
  36. package/components/hy-datetime-picker/props.ts +36 -0
  37. package/components/hy-datetime-picker/typing.d.ts +135 -0
  38. package/components/hy-divider/hy-divider.vue +164 -0
  39. package/components/hy-divider/props.ts +21 -0
  40. package/components/hy-divider/typing.d.ts +64 -0
  41. package/components/hy-empty/hy-empty.vue +122 -0
  42. package/components/hy-empty/props.ts +21 -0
  43. package/components/hy-empty/typing.d.ts +68 -0
  44. package/components/hy-folding-panel/hy-folding-panel.vue +94 -0
  45. package/components/hy-folding-panel/props.ts +17 -0
  46. package/components/hy-folding-panel/typing.d.ts +59 -0
  47. package/components/hy-form/hy-form.vue +372 -0
  48. package/components/hy-form/props.ts +15 -0
  49. package/components/hy-form/typing.d.ts +51 -0
  50. package/components/hy-grid/hy-grid.vue +126 -0
  51. package/components/hy-grid/props.ts +16 -0
  52. package/components/hy-grid/typing.d.ts +62 -0
  53. package/components/hy-icon/hy-icon.vue +207 -0
  54. package/components/hy-icon/props.ts +24 -0
  55. package/components/hy-icon/typing.d.ts +80 -0
  56. package/components/hy-input/hy-input.vue +402 -0
  57. package/components/hy-input/props.ts +41 -0
  58. package/components/hy-input/typing.d.ts +148 -0
  59. package/components/hy-line/hy-line.vue +44 -0
  60. package/components/hy-line/props.ts +12 -0
  61. package/components/hy-line/typing.d.ts +32 -0
  62. package/components/hy-line-progress/hy-line-progress.vue +118 -0
  63. package/components/hy-line-progress/props.ts +12 -0
  64. package/components/hy-line-progress/typing.d.ts +28 -0
  65. package/components/hy-list/hy-list.vue +250 -0
  66. package/components/hy-list/props.ts +18 -0
  67. package/components/hy-list/typing.d.ts +50 -0
  68. package/components/hy-login/ThePhoneLogin.vue +106 -0
  69. package/components/hy-login/TheUserLogin.vue +391 -0
  70. package/components/hy-login/hy-login.vue +283 -0
  71. package/components/hy-login/props.ts +32 -0
  72. package/components/hy-login/typing.d.ts +60 -0
  73. package/components/hy-modal/hy-modal.vue +240 -0
  74. package/components/hy-modal/props.ts +24 -0
  75. package/components/hy-modal/typing.d.ts +70 -0
  76. package/components/hy-navbar/hy-navbar.vue +194 -0
  77. package/components/hy-navbar/props.ts +24 -0
  78. package/components/hy-navbar/typing.d.ts +81 -0
  79. package/components/hy-notice-bar/hy-column-notice.vue +130 -0
  80. package/components/hy-notice-bar/hy-notice-bar.vue +82 -0
  81. package/components/hy-notice-bar/hy-row-notice.vue +182 -0
  82. package/components/hy-notice-bar/props.ts +19 -0
  83. package/components/hy-notice-bar/typing.d.ts +56 -0
  84. package/components/hy-number-step/hy-number-step.vue +428 -0
  85. package/components/hy-number-step/props.ts +29 -0
  86. package/components/hy-number-step/typing.d.ts +104 -0
  87. package/components/hy-overlay/hy-overlay.vue +54 -0
  88. package/components/hy-overlay/props.ts +10 -0
  89. package/components/hy-overlay/typing.d.ts +24 -0
  90. package/components/hy-picker/hy-picker.vue +499 -0
  91. package/components/hy-picker/props.ts +30 -0
  92. package/components/hy-picker/typing.d.ts +115 -0
  93. package/components/hy-popup/hy-popup.vue +269 -0
  94. package/components/hy-popup/props.ts +21 -0
  95. package/components/hy-popup/typing.d.ts +68 -0
  96. package/components/hy-price/hy-price.vue +86 -0
  97. package/components/hy-price/props.ts +13 -0
  98. package/components/hy-price/typing.d.ts +36 -0
  99. package/components/hy-qrcode/hy-qrcode.vue +153 -0
  100. package/components/hy-qrcode/props.ts +20 -0
  101. package/components/hy-qrcode/qrcode.js +1364 -0
  102. package/components/hy-qrcode/typing.d.ts +64 -0
  103. package/components/hy-radio/hy-radio.vue +319 -0
  104. package/components/hy-radio/props.ts +28 -0
  105. package/components/hy-radio/typing.d.ts +85 -0
  106. package/components/hy-rate/hy-rate.vue +261 -0
  107. package/components/hy-rate/props.ts +18 -0
  108. package/components/hy-rate/typing.d.ts +60 -0
  109. package/components/hy-read-more/hy-read-more.vue +134 -0
  110. package/components/hy-read-more/props.ts +20 -0
  111. package/components/hy-read-more/typing.d.ts +44 -0
  112. package/components/hy-safe-bottom/hy-safe-bottom.vue +64 -0
  113. package/components/hy-scroll-list/hy-scroll-list.vue +146 -0
  114. package/components/hy-scroll-list/props.ts +12 -0
  115. package/components/hy-scroll-list/typing.d.ts +28 -0
  116. package/components/hy-search/hy-search.vue +294 -0
  117. package/components/hy-search/props.ts +29 -0
  118. package/components/hy-search/typing.d.ts +109 -0
  119. package/components/hy-slider/hy-slider.vue +511 -0
  120. package/components/hy-slider/props.ts +21 -0
  121. package/components/hy-slider/typing.d.ts +68 -0
  122. package/components/hy-steps/hy-steps.vue +352 -0
  123. package/components/hy-steps/props.ts +15 -0
  124. package/components/hy-steps/typing.d.ts +58 -0
  125. package/components/hy-subsection/hy-subsection.vue +272 -0
  126. package/components/hy-subsection/props.ts +16 -0
  127. package/components/hy-subsection/typing.d.ts +44 -0
  128. package/components/hy-swiper/hy-swiper-indicator.vue +105 -0
  129. package/components/hy-swiper/hy-swiper.vue +242 -0
  130. package/components/hy-swiper/props.ts +30 -0
  131. package/components/hy-swiper/typing.d.ts +107 -0
  132. package/components/hy-switch/hy-switch.vue +168 -0
  133. package/components/hy-switch/props.ts +16 -0
  134. package/components/hy-switch/typing.d.ts +48 -0
  135. package/components/hy-tabs/hy-tabs.vue +416 -0
  136. package/components/hy-tabs/props.ts +26 -0
  137. package/components/hy-tabs/typing.d.ts +86 -0
  138. package/components/hy-tag/hy-tag.vue +374 -0
  139. package/components/hy-tag/props.ts +22 -0
  140. package/components/hy-tag/typing.d.ts +76 -0
  141. package/components/hy-textarea/hy-textarea.vue +229 -0
  142. package/components/hy-textarea/props.ts +26 -0
  143. package/components/hy-textarea/typing.d.ts +27 -0
  144. package/components/hy-tooltip/hy-tooltip.vue +332 -0
  145. package/components/hy-tooltip/props.ts +17 -0
  146. package/components/hy-tooltip/typing.d.ts +52 -0
  147. package/components/hy-transition/hy-transition.vue +150 -0
  148. package/components/hy-transition/index.scss +113 -0
  149. package/components/hy-transition/props.ts +10 -0
  150. package/components/hy-transition/typing.d.ts +36 -0
  151. package/components/hy-upload/hy-upload.vue +557 -0
  152. package/components/hy-upload/props.ts +29 -0
  153. package/components/hy-upload/typing.d.ts +147 -0
  154. package/components/hy-warn/hy-warn.vue +228 -0
  155. package/components/hy-warn/props.ts +14 -0
  156. package/components/hy-warn/typing.d.ts +40 -0
  157. package/components/hy-waterfall/hy-waterfall.vue +51 -0
  158. package/components/hy-waterfall/props.ts +10 -0
  159. package/components/hy-waterfall/typing.d.ts +20 -0
  160. package/components/index.ts +162 -0
  161. package/components/message/TheMessage.vue +169 -0
  162. package/components/message/index.ts +54 -0
  163. package/components/u-form/form.js +22 -0
  164. package/components/u-form/hy-form.vue +324 -0
  165. package/components/u-form/props.js +49 -0
  166. package/components/u-form/schema.js +1451 -0
  167. package/components/u-form/u-form.vue +267 -0
  168. package/components/u-form/utils.js +65 -0
  169. package/components/u-form-item/formItem.js +24 -0
  170. package/components/u-form-item/hy-form-item.vue +360 -0
  171. package/components/u-form-item/props.js +57 -0
  172. package/components/u-form-item/u-form-item.vue +294 -0
  173. package/components/yk-dialog/yk-dialog.vue +129 -0
  174. package/components/yk-tabbar/props.ts +49 -0
  175. package/components/yk-tabbar/yk-tabbar.vue +224 -0
  176. package/config/color.ts +6 -0
  177. package/config/icon.ts +366 -0
  178. package/config/index.ts +2 -0
  179. package/global/index.ts +6 -0
  180. package/global/register-properties.ts +37 -0
  181. package/index.ts +8 -0
  182. package/libs/css/common.scss +0 -0
  183. package/libs/css/iconfont.css +379 -0
  184. package/libs/css/iconfont.ttf +0 -0
  185. package/libs/css/mixin.scss +15 -0
  186. package/package.json +42 -0
  187. package/public/icons/error.png +0 -0
  188. package/public/icons/success.png +0 -0
  189. package/public/icons/warning.png +0 -0
  190. package/store/index.ts +1 -0
  191. package/store/userInfo.ts +25 -0
  192. package/theme.scss +94 -0
  193. package/typing/index.ts +7 -0
  194. package/typing/modules/common.d.ts +50 -0
  195. package/typing/modules/dialog.ts +17 -0
  196. package/typing/modules/enum.ts +67 -0
  197. package/typing/modules/form.ts +161 -0
  198. package/typing/modules/http.ts +68 -0
  199. package/typing/modules/icon.d.ts +366 -0
  200. package/typing/modules/img.ts +15 -0
  201. package/typing/modules/rect.ts +10 -0
  202. package/utils/address.json +5890 -0
  203. package/utils/base64.ts +119 -0
  204. package/utils/index.ts +3 -0
  205. package/utils/inside.ts +310 -0
  206. package/utils/utils.ts +446 -0
@@ -0,0 +1,511 @@
1
+ <template>
2
+ <view class="hy-slider" :style="[customStyle]">
3
+ <template v-if="!useNative || isRange">
4
+ <view
5
+ ref="hy-slider-inner"
6
+ class="hy-slider-inner"
7
+ @click="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(Number(blockSize) + 24)
17
+ : addUnit(blockSize)
18
+ }"
19
+ >
20
+ <view
21
+ ref="hy-slider__base"
22
+ class="hy-slider__base"
23
+ :style="[
24
+ {
25
+ height: height,
26
+ backgroundColor: inactiveColor
27
+ }
28
+ ]"
29
+ >
30
+ </view>
31
+ <view
32
+ @click="onClick"
33
+ class="hy-slider__gap"
34
+ :style="[
35
+ barStyle,
36
+ {
37
+ height: height,
38
+ marginTop: '-' + height,
39
+ backgroundColor: activeColor
40
+ }
41
+ ]"
42
+ >
43
+ </view>
44
+ <view
45
+ v-if="isRange"
46
+ class="hy-slider__gap hy-slider__gap-0"
47
+ :style="[
48
+ barStyle0,
49
+ {
50
+ height: height,
51
+ marginTop: '-' + height,
52
+ backgroundColor: inactiveColor
53
+ }
54
+ ]"
55
+ >
56
+ </view>
57
+ <text
58
+ v-if="isRange && showValue"
59
+ class="hy-slider__show-range-value"
60
+ :style="{
61
+ left: blockLeft(barStyle?.width, blockSize)
62
+ }"
63
+ >
64
+ {{ rangeValue[0] }}
65
+ </text>
66
+ <text
67
+ v-if="isRange && showValue"
68
+ class="hy-slider__show-range-value"
69
+ :style="{
70
+ left: blockLeft(barStyle?.width, blockSize)
71
+ }"
72
+ >
73
+ {{ rangeValue[1] }}
74
+ </text>
75
+ <template v-if="isRange">
76
+ <view
77
+ class="hy-slider__button-wrap hy-slider__button-wrap-0"
78
+ @touchstart="onTouchStart($event, 0)"
79
+ @touchmove="onTouchMove($event, 0)"
80
+ @touchend="onTouchEnd($event, 0)"
81
+ @touchcancel="onTouchEnd($event, 0)"
82
+ :style="{
83
+ left: blockLeft(barStyle?.width, blockSize)
84
+ }"
85
+ >
86
+ <slot name="min" v-if="$slots.min || $slots.$min" />
87
+ <view
88
+ v-else
89
+ class="hy-slider__button"
90
+ :style="[
91
+ blockStyle,
92
+ {
93
+ height: addUnit(blockSize),
94
+ width: addUnit(blockSize),
95
+ backgroundColor: blockColor
96
+ }
97
+ ]"
98
+ ></view>
99
+ </view>
100
+ </template>
101
+ <view
102
+ class="hy-slider__button-wrap"
103
+ @touchstart="onTouchStart"
104
+ @touchmove="onTouchMove"
105
+ @touchend="onTouchEnd"
106
+ @touchcancel="onTouchEnd"
107
+ :style="{
108
+ left: blockLeft(barStyle?.width, blockSize)
109
+ }"
110
+ >
111
+ <slot name="max" v-if="isRange && ($slots.max || $slots.$max)" />
112
+ <slot v-else-if="$slots.default || $slots.$default" />
113
+ <view
114
+ v-else
115
+ class="hy-slider__button"
116
+ :style="[
117
+ blockStyle,
118
+ {
119
+ height: addUnit(blockSize),
120
+ width: addUnit(blockSize),
121
+ backgroundColor: blockColor
122
+ }
123
+ ]"
124
+ ></view>
125
+ </view>
126
+ </view>
127
+ <view class="hy-slider__show-value" v-if="showValue && !isRange">{{
128
+ modelValue
129
+ }}</view>
130
+ </template>
131
+ <slider
132
+ class="hy-slider__native"
133
+ v-else
134
+ :min="min"
135
+ :max="max"
136
+ :step="step"
137
+ :value="modelValue"
138
+ :activeColor="activeColor"
139
+ :backgroundColor="inactiveColor"
140
+ :blockSize="addUnit(blockSize)"
141
+ :blockColor="blockColor"
142
+ :showValue="showValue"
143
+ :disabled="disabled"
144
+ @changing="changingHandler"
145
+ @change="changeHandler"
146
+ ></slider>
147
+ </view>
148
+ </template>
149
+
150
+ <script setup lang="ts">
151
+ import {
152
+ computed,
153
+ type CSSProperties,
154
+ onMounted,
155
+ ref,
156
+ toRefs,
157
+ watch
158
+ } from "vue";
159
+ import defaultProps from "./props";
160
+ import IProps from "./typing";
161
+ import { addUnit, error, getRect, sleep } from "../../utils";
162
+ import NodeInfo = UniNamespace.NodeInfo;
163
+
164
+ const props = withDefaults(defineProps<IProps>(), defaultProps);
165
+ const { modelValue, rangeValue, useNative, isRange, disabled, step, min, max } =
166
+ toRefs(props);
167
+ const emit = defineEmits(["start", "changing", "change", "update:modelValue"]);
168
+
169
+ const startX = ref(0);
170
+ const status = ref("end");
171
+ const newValue = ref(0);
172
+ const distanceX = ref(0);
173
+ const startValue0 = ref(0);
174
+ const startValue = ref(0);
175
+ const barStyle0 = ref<CSSProperties>();
176
+ const barStyle = ref<CSSProperties>();
177
+ const sliderRect = ref<NodeInfo>({
178
+ left: 0,
179
+ width: 0
180
+ });
181
+
182
+ const blockLeft = computed(() => {
183
+ return (
184
+ slideWidth: string | number | undefined,
185
+ blockWidth: string | number
186
+ ): string => {
187
+ if (slideWidth) {
188
+ return addUnit(
189
+ parseInt(slideWidth.toString().replace("px", "")) +
190
+ Number(blockWidth) / 2
191
+ );
192
+ }
193
+ return "0px";
194
+ };
195
+ });
196
+
197
+ watch(
198
+ () => modelValue.value,
199
+ (newValue) => {
200
+ // 只有在非滑动状态时,才可以通过value更新滑块值,这里监听,是为了让用户触发
201
+ if (status.value === "end") updateValue(newValue, false);
202
+ }
203
+ );
204
+
205
+ watch(
206
+ () => rangeValue.value,
207
+ (newValue) => {
208
+ if (status.value === "end") {
209
+ updateValue(newValue[0], false, 0);
210
+ updateValue(newValue[1], false, 1);
211
+ }
212
+ },
213
+ { deep: true }
214
+ );
215
+
216
+ onMounted(async () => {
217
+ // 获取滑块条的尺寸信息
218
+ if (!useNative.value) {
219
+ // #ifndef APP-NVUE
220
+ sliderRect.value = (await getRect(".hy-slider__base")) as NodeInfo;
221
+ // console.log('sliderRect', sliderRect.value)
222
+ if (sliderRect.value.width == 0) {
223
+ error("如在弹窗等元素中使用,请使用v-if来显示滑块,否则无法计算长度。");
224
+ }
225
+ init();
226
+ // #endif
227
+ }
228
+ });
229
+
230
+ const init = () => {
231
+ if (isRange.value) {
232
+ updateValue(rangeValue.value[0], false, 0);
233
+ updateValue(rangeValue.value[1], false, 1);
234
+ } else {
235
+ updateValue(modelValue.value, false);
236
+ }
237
+ };
238
+ // native拖动过程中触发
239
+ const changingHandler = (e: MouseEvent) => {
240
+ const { value } = e.detail;
241
+ // 更新v-model的值
242
+ emit("update:modelValue", value);
243
+ // 触发事件
244
+ emit("changing", value);
245
+ };
246
+ // native滑动结束时触发
247
+ const changeHandler = (e: TouchEvent) => {
248
+ const { value } = e.detail;
249
+ // 更新v-model的值
250
+ emit("update:modelValue", value);
251
+ // 触发事件
252
+ emit("change", value);
253
+ };
254
+ const onTouchStart = (event: TouchEvent, index = 1) => {
255
+ if (disabled.value) return;
256
+ startX.value = 0;
257
+ // 触摸点集
258
+ let touches = event.touches[0];
259
+ // 触摸点到屏幕左边的距离
260
+ startX.value = touches.clientX;
261
+ // 此处的this.modelValue虽为props值,但是通过$emit('update:modelValue')进行了修改
262
+ if (isRange.value) {
263
+ startValue0.value = format(rangeValue.value[0], 0);
264
+ startValue.value = format(rangeValue.value[1], 1);
265
+ } else {
266
+ startValue.value = format(modelValue.value);
267
+ }
268
+ // 标示当前的状态为开始触摸滑动
269
+ status.value = "start";
270
+
271
+ let clientX = 0;
272
+ // #ifndef APP-NVUE
273
+ clientX = touches.clientX;
274
+ // #endif
275
+ // #ifdef APP-NVUE
276
+ clientX = touches.screenX;
277
+ // #endif
278
+ distanceX.value = clientX - sliderRect.value.left!;
279
+ // 获得移动距离对整个滑块的值,此为带有多位小数的值,不能用此更新视图
280
+ // 否则造成通信阻塞,需要每改变一个step值时修改一次视图
281
+ newValue.value =
282
+ (distanceX.value / sliderRect.value.width!) * (max.value - min.value) +
283
+ min.value;
284
+ status.value = "moving";
285
+ // 发出moving事件
286
+ let $crtFmtValue = updateValue(newValue.value, true, index);
287
+ emit("changing", $crtFmtValue);
288
+ };
289
+ const onTouchMove = (event: TouchEvent, index = 1) => {
290
+ if (disabled.value) return;
291
+ // 连续触摸的过程会一直触发本方法,但只有手指触发且移动了才被认为是拖动了,才发出事件
292
+ // 触摸后第一次移动已经将status设置为moving状态,故触摸第二次移动不会触发本事件
293
+ if (status.value == "start") emit("start");
294
+ let touches = event.touches[0];
295
+ // console.log('touchs', touches)
296
+ // 滑块的左边不一定跟屏幕左边接壤,所以需要减去最外层父元素的左边值
297
+ let clientX = 0;
298
+ // #ifndef APP-NVUE
299
+ clientX = touches.clientX;
300
+ // #endif
301
+ // #ifdef APP-NVUE
302
+ clientX = touches.screenX;
303
+ // #endif
304
+ distanceX.value = clientX - sliderRect.value.left!;
305
+ // 获得移动距离对整个滑块的值,此为带有多位小数的值,不能用此更新视图
306
+ // 否则造成通信阻塞,需要每改变一个step值时修改一次视图
307
+ newValue.value =
308
+ (distanceX.value / sliderRect.value.width!) * (max.value - min.value) +
309
+ min.value;
310
+ status.value = "moving";
311
+ // 发出moving事件
312
+ let $crtFmtValue = updateValue(newValue.value, true, index);
313
+ emit("changing", $crtFmtValue);
314
+ };
315
+ const onTouchEnd = (event: TouchEvent, index = 1) => {
316
+ if (disabled.value) return;
317
+ if (status.value === "moving") {
318
+ let $crtFmtValue = updateValue(newValue.value, false, index);
319
+ emit("change", $crtFmtValue);
320
+ }
321
+ status.value = "end";
322
+ };
323
+ const onTouchStart2 = (event: TouchEvent, index = 1) => {
324
+ if (!isRange.value) {
325
+ // this.onChangeStart(event, index);
326
+ }
327
+ };
328
+ const onTouchMove2 = (event: TouchEvent, index = 1) => {
329
+ if (!isRange.value) {
330
+ // this.onTouchMove(event, index);
331
+ }
332
+ };
333
+ const onTouchEnd2 = (event: TouchEvent, index = 1) => {
334
+ if (!isRange.value) {
335
+ // this.onTouchEnd(event, index);
336
+ }
337
+ };
338
+ const onClick = (event: Event) => {
339
+ // if (isRange.value) return;
340
+ if (disabled.value) return;
341
+ // 直接点击滑块的情况,计算方式与onTouchMove方法相同
342
+ // console.log('click', event)
343
+ // #ifndef APP-NVUE
344
+ // nvue下暂时无法获取坐标
345
+ let clientX = event.detail.x - sliderRect.value.left!;
346
+ newValue.value =
347
+ (clientX / sliderRect.value.width!) * (max.value - min.value) + min.value;
348
+ updateValue(newValue.value, false, 1);
349
+ // #endif
350
+ };
351
+ const updateValue = (value: number, drag: boolean, index: number = 1) => {
352
+ // 去掉小数部分,同时也是对step步进的处理
353
+ let valueFormat = format(value, index);
354
+ // 不允许滑动的值超过max最大值
355
+ if (valueFormat > max.value) {
356
+ valueFormat = max.value;
357
+ }
358
+ // 设置移动的距离,不能用百分比,因为NVUE不支持。
359
+ let width = Math.min(
360
+ ((valueFormat - min.value) / (max.value - min.value)) *
361
+ sliderRect.value.width!,
362
+ sliderRect.value.width!
363
+ );
364
+ let barStyle_1: CSSProperties = {
365
+ width: width + "px"
366
+ };
367
+ // 移动期间无需过渡动画
368
+ if (drag == true) {
369
+ barStyle_1.transition = "none";
370
+ } else {
371
+ // 非移动期间,删掉对过渡为空的声明,让css中的声明起效
372
+ delete barStyle_1.transition;
373
+ }
374
+ // 修改value值
375
+ if (isRange.value) {
376
+ rangeValue.value[index] = valueFormat;
377
+ emit("update:modelValue", rangeValue.value);
378
+ } else {
379
+ emit("update:modelValue", valueFormat);
380
+ }
381
+
382
+ switch (index) {
383
+ case 0:
384
+ barStyle0.value = barStyle_1;
385
+ break;
386
+ case 1:
387
+ barStyle.value = barStyle_1;
388
+ break;
389
+ default:
390
+ break;
391
+ }
392
+ if (isRange.value) {
393
+ return rangeValue.value;
394
+ } else {
395
+ return valueFormat;
396
+ }
397
+ };
398
+ const format = (value: number, index = 1): number => {
399
+ // 将小数变成整数,为了减少对视图的更新,造成视图层与逻辑层的阻塞
400
+ if (isRange.value) {
401
+ switch (index) {
402
+ case 0:
403
+ return (
404
+ Math.round(
405
+ Math.max(
406
+ min.value,
407
+ Math.min(value, rangeValue.value[1] - step.value, max.value)
408
+ ) / step.value
409
+ ) * step.value
410
+ );
411
+ case 1:
412
+ return (
413
+ Math.round(
414
+ Math.max(
415
+ min.value,
416
+ rangeValue.value[0] + step.value,
417
+ Math.min(value, max.value)
418
+ ) / step.value
419
+ ) * step.value
420
+ );
421
+ default:
422
+ return 0;
423
+ }
424
+ } else {
425
+ return (
426
+ Math.round(Math.max(min.value, Math.min(value, max.value)) / step.value) *
427
+ step.value
428
+ );
429
+ }
430
+ };
431
+ </script>
432
+
433
+ <style lang="scss" scoped>
434
+ @import "../../libs/css/mixin.scss";
435
+ .hy-slider {
436
+ position: relative;
437
+ display: flex;
438
+ flex-direction: row;
439
+ align-items: center;
440
+
441
+ &__native {
442
+ flex: 1;
443
+ }
444
+
445
+ &-inner {
446
+ flex: 1;
447
+ display: flex;
448
+ flex-direction: column;
449
+ position: relative;
450
+ border-radius: 999px;
451
+ padding: 10px 18px;
452
+ justify-content: center;
453
+ }
454
+
455
+ &__show-value {
456
+ margin: 10px 18px 10px 0px;
457
+ }
458
+
459
+ &__show-range-value {
460
+ padding-top: 2px;
461
+ font-size: 12px;
462
+ line-height: 12px;
463
+ position: absolute;
464
+ bottom: 0;
465
+ }
466
+
467
+ &__base {
468
+ background-color: #ebedf0;
469
+ }
470
+
471
+ /* #ifndef APP-NVUE */
472
+ &-inner:before {
473
+ position: absolute;
474
+ right: 0;
475
+ left: 0;
476
+ content: "";
477
+ top: -8px;
478
+ bottom: -8px;
479
+ z-index: -1;
480
+ }
481
+ /* #endif */
482
+
483
+ &__gap {
484
+ position: relative;
485
+ border-radius: 999px;
486
+ transition: width 0.2s;
487
+ background-color: #1989fa;
488
+ }
489
+
490
+ &__button {
491
+ width: 24px;
492
+ height: 24px;
493
+ border-radius: 50%;
494
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
495
+ background-color: #fff;
496
+ transform: scale(0.9);
497
+ /* #ifdef H5 */
498
+ cursor: pointer;
499
+ /* #endif */
500
+ }
501
+
502
+ &__button-wrap {
503
+ position: absolute;
504
+ // transform: translate3d(50%, -50%, 0);
505
+ }
506
+
507
+ &--disabled {
508
+ opacity: 0.5;
509
+ }
510
+ }
511
+ </style>
@@ -0,0 +1,21 @@
1
+ import IProps from "./typing";
2
+ import { ColorConfig } from "../../config";
3
+
4
+ const defaultProps: IProps = {
5
+ modelValue: 0,
6
+ blockSize: 18,
7
+ min: 0,
8
+ max: 100,
9
+ step: 1,
10
+ activeColor: ColorConfig.primary,
11
+ inactiveColor: "#c0c4cc",
12
+ blockColor: "#ffffff",
13
+ showValue: false,
14
+ disabled: false,
15
+ useNative: false,
16
+ height: "2px",
17
+ rangeValue: [0, 0],
18
+ isRange: false
19
+ };
20
+
21
+ export default defaultProps;
@@ -0,0 +1,68 @@
1
+ import type { CSSProperties } from "vue";
2
+
3
+ export default interface IProps {
4
+ /**
5
+ * @description 滑块默认值(默认0)
6
+ * */
7
+ modelValue?: number;
8
+ /**
9
+ * @description 滑块的大小,取值范围为 12 - 28
10
+ * */
11
+ blockSize?: number | string;
12
+ /**
13
+ * @description 最小值(默认0)
14
+ * */
15
+ min?: number;
16
+ /**
17
+ * @description 最大值(默认100)
18
+ * */
19
+ max?: number;
20
+ /**
21
+ * @description 步长(默认1)
22
+ * */
23
+ step?: number;
24
+ /**
25
+ * @description 底部选择部分的背景颜色(默认#2979ff)
26
+ * */
27
+ activeColor?: string;
28
+ /**
29
+ * @description 底部条背景颜色(默认#c0c4cc)
30
+ * */
31
+ inactiveColor?: string;
32
+ /**
33
+ * @description 滑块颜色(默认#ffffff)
34
+ * */
35
+ blockColor?: string;
36
+ /**
37
+ * @description 是否显示当前的选择值
38
+ * */
39
+ showValue?: boolean;
40
+ /**
41
+ * @description 是否禁用滑块(默认为false)
42
+ * */
43
+ disabled?: boolean;
44
+ /**
45
+ * @description 给滑块自定义样式,对象形式
46
+ * */
47
+ blockStyle?: CSSProperties;
48
+ /**
49
+ * @description 是否渲染uni-app框架内置组件(默认false)
50
+ * */
51
+ useNative?: boolean;
52
+ /**
53
+ * @description 滑块条高度,单位rpx(默认6)
54
+ * */
55
+ height?: string | number;
56
+ /**
57
+ * @description 双滑块时值
58
+ * */
59
+ rangeValue?: number[];
60
+ /**
61
+ * @description 是否区间的模式
62
+ * */
63
+ isRange?: boolean;
64
+ /**
65
+ * @description 自定义样式
66
+ * */
67
+ customStyle?: CSSProperties;
68
+ }