hy-app 0.3.0 → 0.3.2

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 (108) hide show
  1. package/README.md +6 -3
  2. package/common/shakeService.ts +31 -29
  3. package/components/avatar.zip +0 -0
  4. package/components/hy-action-sheet/hy-action-sheet.vue +71 -46
  5. package/components/hy-address-picker/hy-address-picker.vue +94 -83
  6. package/components/hy-avatar/hy-avatar.vue +84 -85
  7. package/components/hy-back-top/hy-back-top.vue +8 -6
  8. package/components/hy-badge/hy-badge.vue +47 -46
  9. package/components/hy-button/hy-button.vue +117 -93
  10. package/components/hy-calendar/hy-calendar.vue +168 -160
  11. package/components/hy-card/hy-card.vue +50 -43
  12. package/components/hy-card/typing.d.ts +33 -32
  13. package/components/hy-cell/hy-cell.vue +73 -51
  14. package/components/hy-check-button/hy-check-button.vue +54 -47
  15. package/components/hy-checkbox/hy-checkbox.vue +97 -105
  16. package/components/hy-code-input/hy-code-input.vue +80 -89
  17. package/components/hy-config-provider/hy-config-provider.vue +20 -21
  18. package/components/hy-count-down/hy-count-down.vue +66 -67
  19. package/components/hy-count-to/hy-count-to.vue +105 -99
  20. package/components/hy-count-to/typing.d.ts +13 -12
  21. package/components/hy-datetime-picker/hy-datetime-picker.vue +261 -253
  22. package/components/hy-datetime-picker/typing.d.ts +42 -40
  23. package/components/hy-divider/hy-divider.vue +68 -73
  24. package/components/hy-dropdown/hy-dropdown.vue +20 -19
  25. package/components/hy-dropdown-item/hy-dropdown-item.vue +66 -61
  26. package/components/hy-dropdown-item/typing.d.ts +9 -9
  27. package/components/hy-empty/hy-empty.vue +42 -42
  28. package/components/hy-flex/hy-flex.vue +99 -0
  29. package/components/hy-flex/index.scss +8 -0
  30. package/components/hy-flex/typing.d.ts +23 -0
  31. package/components/hy-float-button/hy-float-button.vue +218 -210
  32. package/components/hy-folding-panel/hy-folding-panel.vue +32 -33
  33. package/components/hy-form/hy-form.vue +264 -252
  34. package/components/hy-form/typing.d.ts +4 -0
  35. package/components/hy-form-group/hy-form-group.vue +114 -183
  36. package/components/hy-form-item/hy-form-item.vue +12 -10
  37. package/components/hy-form-item/index.scss +2 -2
  38. package/components/hy-form-item/typing.d.ts +3 -6
  39. package/components/hy-grid/hy-grid.vue +44 -43
  40. package/components/hy-icon/hy-icon.vue +61 -67
  41. package/components/hy-image/hy-image.vue +112 -88
  42. package/components/hy-image/typing.d.ts +27 -23
  43. package/components/hy-input/hy-input.vue +157 -127
  44. package/components/hy-input/typing.d.ts +53 -47
  45. package/components/hy-line/hy-line.vue +26 -26
  46. package/components/hy-line-progress/hy-line-progress.vue +42 -35
  47. package/components/hy-list/hy-list.vue +76 -85
  48. package/components/hy-loading/hy-loading.vue +26 -23
  49. package/components/hy-login/TheUserLogin.vue +1 -1
  50. package/components/hy-menu/hy-menu.vue +48 -43
  51. package/components/hy-menu/typing.d.ts +18 -17
  52. package/components/hy-modal/hy-modal.vue +39 -35
  53. package/components/hy-navbar/hy-navbar.vue +25 -25
  54. package/components/hy-navbar/typing.d.ts +24 -22
  55. package/components/hy-notice-bar/hy-notice-bar.vue +26 -27
  56. package/components/hy-notify/hy-notify.vue +53 -53
  57. package/components/hy-number-step/hy-number-step.vue +134 -146
  58. package/components/hy-number-step/typing.d.ts +35 -35
  59. package/components/hy-overlay/hy-overlay.vue +23 -21
  60. package/components/hy-pagination/hy-pagination.vue +41 -36
  61. package/components/hy-picker/hy-picker.vue +184 -154
  62. package/components/hy-picker/typing.d.ts +39 -39
  63. package/components/hy-popover/hy-popover.vue +97 -77
  64. package/components/hy-popup/hy-popup.vue +107 -98
  65. package/components/hy-price/hy-price.vue +38 -34
  66. package/components/hy-qrcode/hy-qrcode.vue +50 -51
  67. package/components/hy-radio/hy-radio.vue +101 -113
  68. package/components/hy-rate/hy-rate.vue +107 -88
  69. package/components/hy-read-more/hy-read-more.vue +64 -49
  70. package/components/hy-scroll-list/hy-scroll-list.vue +45 -48
  71. package/components/hy-search/hy-search.vue +73 -66
  72. package/components/hy-search/typing.d.ts +36 -35
  73. package/components/hy-signature/hy-signature.vue +282 -240
  74. package/components/hy-slider/hy-slider.vue +195 -153
  75. package/components/hy-slider/typing.d.ts +21 -21
  76. package/components/hy-steps/hy-steps.vue +118 -90
  77. package/components/hy-steps/index.scss +31 -21
  78. package/components/hy-submit-bar/hy-submit-bar.vue +61 -70
  79. package/components/hy-subsection/hy-subsection.vue +99 -102
  80. package/components/hy-subsection/typing.d.ts +19 -19
  81. package/components/hy-swipe-action/hy-swipe-action.vue +131 -118
  82. package/components/hy-swiper/hy-swiper.vue +85 -71
  83. package/components/hy-switch/hy-switch.vue +67 -72
  84. package/components/hy-switch/typing.d.ts +21 -19
  85. package/components/hy-tabs/hy-tabs.vue +168 -113
  86. package/components/hy-tag/hy-tag.vue +90 -86
  87. package/components/hy-tag/typing.d.ts +26 -21
  88. package/components/hy-text/hy-text.vue +119 -111
  89. package/components/hy-textarea/hy-textarea.vue +100 -93
  90. package/components/hy-textarea/typing.d.ts +36 -31
  91. package/components/hy-toast/hy-toast.vue +77 -67
  92. package/components/hy-tooltip/hy-tooltip.vue +109 -91
  93. package/components/hy-transition/hy-transition.vue +62 -66
  94. package/components/hy-upload/hy-upload.vue +294 -152
  95. package/components/hy-upload/typing.d.ts +41 -36
  96. package/components/hy-warn/hy-warn.vue +34 -27
  97. package/components/hy-waterfall/hy-waterfall.vue +83 -74
  98. package/components/hy-watermark/hy-watermark.vue +134 -115
  99. package/components/index.ts +1 -1
  100. package/composables/usePopover.ts +236 -221
  101. package/composables/useQueue.ts +53 -52
  102. package/global.d.ts +1 -0
  103. package/package.json +2 -2
  104. package/store/index.ts +9 -1
  105. package/theme.scss +5 -5
  106. package/typing/index.ts +0 -1
  107. package/typing/modules/common.d.ts +0 -2
  108. package/web-types.json +1 -1
@@ -31,31 +31,31 @@
31
31
 
32
32
  <script lang="ts">
33
33
  export default {
34
- name: 'hy-notify',
34
+ name: "hy-notify",
35
35
  options: {
36
36
  addGlobalClass: true,
37
37
  virtualHost: true,
38
- styleIsolation: 'shared',
38
+ styleIsolation: "shared",
39
39
  },
40
- }
40
+ };
41
41
  </script>
42
42
 
43
43
  <script setup lang="ts">
44
- import type IProps from './typing'
45
- import { computed, ref } from 'vue'
46
- import type { CSSProperties, PropType } from 'vue'
47
- import { IconConfig } from '../../config'
48
- import { addUnit } from '../../utils'
44
+ import type IProps from "./typing";
45
+ import { computed, ref } from "vue";
46
+ import type { CSSProperties, PropType } from "vue";
47
+ import { IconConfig } from "../../config";
48
+ import { addUnit } from "../../utils";
49
49
  // 组件
50
- import HyTransition from '../hy-transition/hy-transition.vue'
51
- import HyStatusBar from '../hy-status-bar/hy-status-bar.vue'
52
- import HyIcon from '../hy-icon/hy-icon.vue'
50
+ import HyTransition from "../hy-transition/hy-transition.vue";
51
+ import HyStatusBar from "../hy-status-bar/hy-status-bar.vue";
52
+ import HyIcon from "../hy-icon/hy-icon.vue";
53
53
 
54
54
  /**
55
55
  * 一般用于页面顶部向下滑出一个提示,尔后自动收起的场景。
56
56
  * @displayName hy-notify
57
57
  */
58
- defineOptions({})
58
+ defineOptions({});
59
59
 
60
60
  // const props = withDefaults(defineProps<IProps>(), defaultProps)
61
61
  const props = defineProps({
@@ -70,12 +70,12 @@ const props = defineProps({
70
70
  * */
71
71
  type: {
72
72
  type: String,
73
- default: 'primary',
73
+ default: "primary",
74
74
  },
75
75
  /** 字体颜色 */
76
76
  color: {
77
77
  type: String,
78
- default: '#FFFFFF',
78
+ default: "#FFFFFF",
79
79
  },
80
80
  /** 背景颜色 */
81
81
  bgColor: String,
@@ -104,7 +104,7 @@ const props = defineProps({
104
104
  },
105
105
  /** 自定义外部类名 */
106
106
  customClass: String,
107
- })
107
+ });
108
108
 
109
109
  const config = ref<IProps>({
110
110
  // 到顶部的距离
@@ -123,99 +123,99 @@ const config = ref<IProps>({
123
123
  fontSize: props.fontSize,
124
124
  // 是否留出顶部安全距离(状态栏高度)
125
125
  safeAreaInsetTop: props.safeAreaInsetTop,
126
- })
127
- const tmpConfig = ref<IProps>({})
128
- const open = ref(false)
129
- let timer: ReturnType<typeof setTimeout>
126
+ });
127
+ const tmpConfig = ref<IProps>({});
128
+ const open = ref(false);
129
+ let timer: ReturnType<typeof setTimeout>;
130
130
 
131
131
  /**
132
132
  * @description 容器样式
133
133
  * */
134
134
  const containerStyle = computed(() => {
135
- let top = 0
135
+ let top = 0;
136
136
  if (tmpConfig.value.top === 0) {
137
137
  // #ifdef H5
138
138
  // H5端,导航栏为普通元素,需要将组件移动到导航栏的下边沿
139
139
  // H5的导航栏高度为44px
140
- top = 44
140
+ top = 44;
141
141
  // #endif
142
142
  }
143
143
  const style: CSSProperties = {
144
144
  top: addUnit(tmpConfig.value.top === 0 ? top : tmpConfig.value.top),
145
145
  // 因为组件底层为hy-transition组件,必须将其设置为fixed定位
146
146
  // 让其出现在导航栏底部
147
- position: 'fixed',
147
+ position: "fixed",
148
148
  left: 0,
149
149
  right: 0,
150
150
  zIndex: 10076,
151
- }
152
- return style
153
- })
151
+ };
152
+ return style;
153
+ });
154
154
  /**
155
155
  * @description 组件背景颜色
156
156
  */
157
157
  const backgroundColor = computed(() => {
158
- const style: CSSProperties = {}
158
+ const style: CSSProperties = {};
159
159
  if (tmpConfig.value.bgColor) {
160
- style.backgroundColor = tmpConfig.value.bgColor
160
+ style.backgroundColor = tmpConfig.value.bgColor;
161
161
  }
162
- return style
163
- })
162
+ return style;
163
+ });
164
164
 
165
165
  /**
166
166
  * @description 默认主题下的图标
167
167
  * */
168
168
  const icon = computed(() => {
169
- let icon
170
169
  switch (tmpConfig.value.type) {
171
- case 'success':
172
- return IconConfig.SUCCESS
173
- case 'error':
174
- return IconConfig.CLOSE_CIRCLE
175
- case 'warning':
176
- return IconConfig.NOTICE
170
+ case "success":
171
+ return IconConfig.SUCCESS;
172
+ case "error":
173
+ return IconConfig.CLOSE_CIRCLE;
174
+ case "warning":
175
+ return IconConfig.NOTICE;
177
176
  default:
178
- return icon
177
+ return "";
179
178
  }
180
- })
179
+ });
181
180
 
182
181
  const show = (options: IProps) => {
183
182
  // 不将结果合并到this.config变量,避免多次调用hy-toast,前后的配置造成混乱
184
- tmpConfig.value = Object.assign(config.value, options)
183
+ tmpConfig.value = Object.assign(config.value, options);
185
184
  // 任何定时器初始化之前,都要执行清除操作,否则可能会造成混乱
186
- clearTimer()
187
- open.value = true
185
+ clearTimer();
186
+ open.value = true;
188
187
  if (tmpConfig.value.duration && tmpConfig.value.duration! > 0) {
189
188
  timer = setTimeout(() => {
190
- open.value = false
189
+ open.value = false;
191
190
  // 倒计时结束,清除定时器,隐藏toast组件
192
- clearTimer()
191
+ clearTimer();
193
192
  // 判断是否存在callback方法,如果存在就执行
194
- typeof tmpConfig.value.complete === 'function' && tmpConfig.value.complete()
195
- }, tmpConfig.value.duration)
193
+ typeof tmpConfig.value.complete === "function" &&
194
+ tmpConfig.value.complete();
195
+ }, tmpConfig.value.duration);
196
196
  }
197
- }
197
+ };
198
198
  /**
199
199
  * @description 关闭notify
200
200
  * */
201
201
  const close = () => {
202
- clearTimer()
203
- }
202
+ clearTimer();
203
+ };
204
204
  /**
205
205
  * @description 清除定时任务
206
206
  * */
207
207
  const clearTimer = () => {
208
- open.value = false
208
+ open.value = false;
209
209
  // 清除定时器
210
- clearTimeout(timer)
211
- }
210
+ clearTimeout(timer);
211
+ };
212
212
 
213
213
  defineExpose({
214
214
  show,
215
215
  close,
216
- })
216
+ });
217
217
  </script>
218
218
 
219
219
  <style scoped lang="scss">
220
- @import './index.scss';
220
+ @import "./index.scss";
221
221
  </style>
@@ -127,36 +127,43 @@
127
127
 
128
128
  <script lang="ts">
129
129
  export default {
130
- name: 'hy-number-step',
130
+ name: "hy-number-step",
131
131
  options: {
132
132
  addGlobalClass: true,
133
133
  virtualHost: true,
134
- styleIsolation: 'shared',
134
+ styleIsolation: "shared",
135
135
  },
136
- }
136
+ };
137
137
  </script>
138
138
 
139
139
  <script setup lang="ts">
140
- import { computed, toRefs, ref, watch, onMounted, nextTick } from 'vue'
141
- import type { CSSProperties, PropType } from 'vue'
142
- import { addUnit } from '../../utils'
143
- import { IconConfig } from '../../config'
144
- import type HyIconProps from '../hy-icon/typing'
145
- import type { INumberStepEmits } from './typing'
140
+ import { computed, ref, watch, onMounted, nextTick } from "vue";
141
+ import type { CSSProperties, PropType } from "vue";
142
+ import { addUnit } from "../../utils";
143
+ import { IconConfig } from "../../config";
144
+ import type HyIconProps from "../hy-icon/typing";
145
+ import type { INumberStepEmits } from "./typing";
146
146
  // 组件
147
- import HyIcon from '../hy-icon/hy-icon.vue'
147
+ import HyIcon from "../hy-icon/hy-icon.vue";
148
+ import type {
149
+ InputOnBlurEvent,
150
+ InputOnFocusEvent,
151
+ InputOnInputEvent,
152
+ } from "@uni-helper/uni-types";
148
153
 
149
154
  /**
150
155
  * 一般用于商城购物选择物品数量的场景
151
156
  * @displayName hy-number-step
152
157
  */
153
- defineOptions({})
158
+ defineOptions({});
154
159
 
155
160
  // const props = withDefaults(defineProps<IProps>(), defaultProps)
156
161
  const props = defineProps({
157
162
  /** 用于双向绑定的值,初始化时设置设为默认min值(最小值) */
158
163
  modelValue: {
159
164
  type: Number,
165
+ default: 0,
166
+ required: true,
160
167
  },
161
168
  /** 最小值 */
162
169
  min: {
@@ -257,237 +264,218 @@ const props = defineProps({
257
264
  type: Boolean,
258
265
  default: false,
259
266
  },
260
- })
261
- const {
262
- modelValue,
263
- miniMode,
264
- cursorSpacing,
265
- inputBgColor,
266
- inputWidth,
267
- buttonSize,
268
- buttonWidth,
269
- bgColor,
270
- color,
271
- buttonRadius,
272
- disabledInput,
273
- disabled,
274
- integer,
275
- max,
276
- min,
277
- decimalLength,
278
- disablePlus,
279
- disableMinus,
280
- longPress,
281
- asyncChange,
282
- step,
283
- } = toRefs(props)
284
- const emit = defineEmits<INumberStepEmits>()
285
- type StepType = 'plus' | 'minus'
267
+ });
268
+ const emit = defineEmits<INumberStepEmits>();
269
+ type StepType = "plus" | "minus";
286
270
 
287
271
  // 输入框实际操作的值
288
- const currentValue = ref<number>(0)
272
+ const currentValue = ref<number>(0);
289
273
  // 定时器
290
- const longPressTimer = ref<null | number | NodeJS.Timeout>(null)
274
+ let longPressTimer: ReturnType<typeof setTimeout> | null = null;
291
275
 
292
- const stepType = ref<StepType>('plus')
276
+ const stepType = ref<StepType>("plus");
293
277
 
294
278
  /**
295
279
  * @description 格式化整理数据,限制范围
296
280
  * @param value 处理值
297
281
  * */
298
- const format = (value: number): number => {
282
+ const format = (value: number | string): number => {
299
283
  // 如果为空字符串,那么设置为0,同时将值转为Number类型
300
- value = !value ? 0 : +value
284
+ value = !value ? 0 : +value;
301
285
  // 对比最大最小值,取在min和max之间的值
302
- value = Math.max(Math.min(max.value, value), min.value)
286
+ value = Math.max(Math.min(props.max, value), props.min);
303
287
  // 如果设定了最大的小数位数,使用toFixed去进行格式化
304
- if (decimalLength.value !== null) {
305
- value = parseFloat(value.toFixed(decimalLength.value))
288
+ if (props.decimalLength !== null) {
289
+ value = parseFloat(value.toFixed(props.decimalLength));
306
290
  }
307
- return value
308
- }
291
+ return value;
292
+ };
309
293
 
310
294
  // 用于监听多个值发生变化
311
295
  const watchChange = computed(() => {
312
- return [integer.value, decimalLength.value, min.value, max.value]
313
- })
296
+ return [props.integer, props.decimalLength, props.min, props.max];
297
+ });
314
298
 
315
299
  watch(
316
300
  () => watchChange.value,
317
301
  () => check(),
318
- )
302
+ );
319
303
  watch(
320
- () => modelValue.value,
304
+ () => props.modelValue,
321
305
  (newValue: number) => {
322
306
  if (newValue !== currentValue.value) {
323
- currentValue.value = format(modelValue.value)
307
+ currentValue.value = format(props.modelValue);
324
308
  }
325
309
  },
326
310
  { immediate: true },
327
- )
311
+ );
328
312
 
329
313
  const hideMinus = computed(() => {
330
- return currentValue.value == 0 && miniMode.value
331
- })
314
+ return currentValue.value == 0 && props.miniMode;
315
+ });
332
316
  const getCursorSpacing = computed(() => {
333
317
  // 判断传入的单位,如果为px单位,需要转成px
334
- return cursorSpacing.value
335
- })
318
+ return props.cursorSpacing;
319
+ });
336
320
  // 按钮的样式
337
321
  const buttonStyle = computed(() => {
338
322
  return (type: string) => {
339
323
  const style: CSSProperties = {
340
- backgroundColor: bgColor.value,
341
- width: addUnit(buttonWidth.value),
342
- height: addUnit(buttonSize.value),
343
- color: color.value,
344
- borderRadius: buttonRadius.value,
345
- }
346
- return style
347
- }
348
- })
324
+ backgroundColor: props.bgColor,
325
+ width: addUnit(props.buttonWidth),
326
+ height: addUnit(props.buttonSize),
327
+ color: props.color,
328
+ borderRadius: props.buttonRadius,
329
+ };
330
+ return style;
331
+ };
332
+ });
349
333
  // 输入框的样式
350
334
  const inputStyle = computed<CSSProperties>(() => {
351
- // const disabled_1 = disabled.value || disabledInput.value;
335
+ // const disabled_1 = props.disabled || disabledInput.value;
352
336
  return {
353
- color: color.value,
354
- backgroundColor: inputBgColor.value || bgColor.value,
355
- height: addUnit(buttonSize.value),
356
- width: addUnit(inputWidth.value),
357
- }
358
- })
337
+ color: props.color,
338
+ backgroundColor: props.inputBgColor || props.bgColor,
339
+ height: addUnit(props.buttonSize),
340
+ width: addUnit(props.inputWidth),
341
+ };
342
+ });
359
343
 
360
344
  const isDisabled = computed(() => {
361
345
  return (type: string) => {
362
- if (type === 'plus') {
346
+ if (type === "plus") {
363
347
  // 在点击增加按钮情况下,判断整体的disabled,是否单独禁用增加按钮,以及当前值是否大于最大的允许值
364
- return disabled.value || disablePlus.value || currentValue.value >= max.value
348
+ return (
349
+ props.disabled || props.disablePlus || currentValue.value >= props.max
350
+ );
365
351
  }
366
352
  // 点击减少按钮同理
367
- return disabled.value || disableMinus.value || currentValue.value <= min.value
368
- }
369
- })
353
+ return (
354
+ props.disabled || props.disableMinus || currentValue.value <= props.min
355
+ );
356
+ };
357
+ });
370
358
 
371
359
  onMounted(() => {
372
- init()
373
- })
360
+ init();
361
+ });
374
362
 
375
363
  const init = () => {
376
- currentValue.value = format(modelValue.value)
377
- }
364
+ currentValue.value = format(props.modelValue);
365
+ };
378
366
  const check = () => {
379
367
  // 格式化了之后,如果前后的值不相等,那么设置为格式化后的值
380
- const val = format(currentValue.value)
381
- if (val !== currentValue.value) {
382
- currentValue.value = val
383
- emitChange(val)
368
+ const val = format(currentValue.value);
369
+ if (val != currentValue.value) {
370
+ currentValue.value = val;
371
+ emitChange(val);
384
372
  }
385
- }
373
+ };
386
374
 
387
375
  /**
388
376
  * @description 输入框活动焦点
389
377
  */
390
- const onFocus = (event: Event) => {
391
- emit('focus', event.detail.value)
392
- }
378
+ const onFocus = (event: InputOnFocusEvent) => {
379
+ emit("focus", event.detail.value);
380
+ };
393
381
  /**
394
382
  * @description 输入框失去焦点
395
383
  */
396
- const onBlur = (event: Event) => {
384
+ const onBlur = (event: InputOnBlurEvent) => {
397
385
  // 对输入值进行格式化
398
- format(event.detail.value)
386
+ format(Number(event.detail.value));
399
387
  // 发出blur事件
400
- emit('blur', event.detail.value)
401
- }
388
+ emit("blur", event.detail.value);
389
+ };
402
390
  /**
403
391
  * @description 输入框值发生变化
404
392
  */
405
- const onInput = (e: Event) => {
406
- const { value = '' } = e.detail || {}
393
+ const onInput = (e: InputOnInputEvent) => {
394
+ const { value = "" } = e.detail || {};
407
395
  // 为空返回
408
- if (value === '') return
409
- let formatted = value
396
+ if (value === "") return;
397
+ let formatted = value;
410
398
  // https://github.com/ijry/uview-plus/issues/613
411
- emitChange(value)
399
+ emitChange(value);
412
400
  // 最大允许的小数长度
413
- if (decimalLength.value !== null && formatted.indexOf('.') !== -1) {
414
- const pair = formatted.split('.')
415
- formatted = `${pair[0]}.${pair[1].slice(0, decimalLength.value)}`
401
+ if (props.decimalLength !== null && formatted.indexOf(".") !== -1) {
402
+ const pair = formatted.split(".");
403
+ formatted = `${pair[0]}.${pair[1].slice(0, props.decimalLength)}`;
416
404
  }
417
- formatted = format(formatted)
418
- emitChange(formatted)
405
+ formatted = format(formatted).toString();
406
+ emitChange(formatted);
419
407
  // #ifdef MP-WEIXIN
420
- return formatted
408
+ return formatted;
421
409
  // #endif
422
- }
410
+ };
423
411
  /**
424
412
  * @description 发出change事件
425
413
  * @param value 值
426
414
  */
427
- const emitChange = (value: number) => {
415
+ const emitChange = (value: number | string) => {
428
416
  // 如果开启了异步变更值,则不修改内部的值,需要用户手动在外部通过v-model变更
429
- if (!asyncChange.value) {
417
+ if (!props.asyncChange) {
430
418
  nextTick(() => {
431
- emit('update:modelValue', value)
432
- currentValue.value = value
419
+ emit("update:modelValue", value);
420
+ currentValue.value = Number(value);
433
421
  // this.$forceUpdate()
434
- })
422
+ });
435
423
  }
436
- emit('change', value)
437
- }
424
+ emit("change", value);
425
+ };
438
426
  const onChange = () => {
439
427
  if (isDisabled.value(stepType.value)) {
440
- return emit('overLimit', stepType.value)
428
+ return emit("overLimit", stepType.value);
441
429
  }
442
- const diff = stepType.value === 'minus' ? -step.value : +step.value
443
- const value = format(add(+currentValue.value, diff))
444
- emitChange(value)
445
- emit(stepType.value, value)
446
- }
430
+ const diff = stepType.value === "minus" ? -props.step : +props.step;
431
+ const value = format(add(+currentValue.value, diff));
432
+ emitChange(value);
433
+ emit(stepType.value, value);
434
+ };
447
435
  /**
448
436
  * @description 对值扩大后进行四舍五入,再除以扩大因子,避免出现浮点数操作的精度问题
449
437
  * @param num1
450
438
  * @param num2
451
439
  * */
452
440
  const add = (num1: number, num2: number) => {
453
- const cardinal = Math.pow(10, 10)
454
- return Math.round((num1 + num2) * cardinal) / cardinal
455
- }
441
+ const cardinal = Math.pow(10, 10);
442
+ return Math.round((num1 + num2) * cardinal) / cardinal;
443
+ };
456
444
  // 点击加减按钮
457
445
  const clickHandler = (type: StepType) => {
458
- stepType.value = type
459
- onChange()
460
- }
446
+ stepType.value = type;
447
+ onChange();
448
+ };
461
449
  const longPressStep = () => {
462
450
  // 每隔一段时间,重新调用longPressStep方法,实现长按加减
463
- onClearTimeout()
464
- longPressTimer.value = setTimeout(() => {
465
- onChange()
466
- longPressStep()
467
- }, 250) as NodeJS.Timeout
468
- }
451
+ onClearTimeout();
452
+ longPressTimer = setTimeout(() => {
453
+ onChange();
454
+ longPressStep();
455
+ }, 250);
456
+ };
469
457
  const onTouchStart = (type: StepType) => {
470
- if (!longPress.value) return
471
- onClearTimeout()
472
- stepType.value = type
458
+ if (!props.longPress) return;
459
+ onClearTimeout();
460
+ stepType.value = type;
473
461
  // 一定时间后,默认达到长按状态
474
- longPressTimer.value = setTimeout(() => {
475
- onChange()
476
- longPressStep()
477
- }, 600)
478
- }
462
+ longPressTimer = setTimeout(() => {
463
+ onChange();
464
+ longPressStep();
465
+ }, 600);
466
+ };
479
467
  // 触摸结束,清除定时器,停止长按加减
480
468
  const onTouchEnd = () => {
481
- if (!longPress.value) return
482
- onClearTimeout()
483
- }
469
+ if (!props.longPress) return;
470
+ onClearTimeout();
471
+ };
484
472
  // 清除定时器
485
473
  const onClearTimeout = () => {
486
- clearTimeout(longPressTimer.value as number)
487
- longPressTimer.value = null
488
- }
474
+ clearTimeout(longPressTimer as number);
475
+ longPressTimer = null;
476
+ };
489
477
  </script>
490
478
 
491
479
  <style lang="scss" scoped>
492
- @import './index.scss';
480
+ @import "./index.scss";
493
481
  </style>