hy-app 0.6.9 → 0.7.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.
- package/attributes.json +1 -1
- package/components/hy-avatar/hy-avatar.vue +12 -5
- package/components/hy-avatar/props.ts +4 -2
- package/components/hy-avatar/typing.d.ts +8 -1
- package/components/hy-calendar/hy-calendar.vue +3 -2
- package/components/hy-calendar/month.vue +25 -5
- package/components/hy-calendar/props.ts +1 -1
- package/components/hy-calendar/typing.d.ts +9 -0
- package/components/hy-cascader/hy-cascader.vue +503 -0
- package/components/hy-cascader/index.scss +84 -0
- package/components/hy-cascader/props.ts +88 -0
- package/components/hy-cascader/typing.d.ts +34 -0
- package/components/hy-check-button/typing.d.ts +12 -7
- package/components/hy-code-input/hy-code-input.vue +33 -11
- package/components/hy-code-input/typing.d.ts +4 -0
- package/components/hy-config-provider/hy-config-provider.vue +58 -53
- package/components/hy-count-down/hy-count-down.vue +8 -8
- package/components/hy-count-down/typing.d.ts +16 -0
- package/components/hy-count-to/hy-count-to.vue +7 -7
- package/components/hy-count-to/typing.d.ts +24 -0
- package/components/hy-datetime-picker/props.ts +1 -1
- package/components/hy-datetime-picker/typing.d.ts +1 -1
- package/components/hy-dropdown/typing.d.ts +5 -0
- package/components/hy-dropdown-item/hy-dropdown-item.vue +1 -1
- package/components/hy-folding-panel/hy-folding-panel.vue +3 -3
- package/components/hy-folding-panel/typing.d.ts +23 -0
- package/components/hy-folding-panel-item/hy-folding-panel-item.vue +2 -2
- package/components/hy-folding-panel-item/typing.d.ts +21 -0
- package/components/hy-form/hy-form.vue +2 -2
- package/components/hy-form/typing.d.ts +37 -0
- package/components/hy-form-item/typing.d.ts +1 -1
- package/components/hy-grid/hy-grid.vue +12 -12
- package/components/hy-grid/index.scss +1 -2
- package/components/hy-grid/props.ts +7 -2
- package/components/hy-grid/typing.d.ts +1 -1
- package/components/hy-icon/typing.d.ts +52 -9
- package/components/hy-keyboard/constants.ts +83 -0
- package/components/hy-keyboard/hy-keyboard.vue +375 -0
- package/components/hy-keyboard/index.scss +73 -0
- package/components/hy-keyboard/key/index.scss +79 -0
- package/components/hy-keyboard/key/index.vue +91 -0
- package/components/hy-keyboard/key/types.ts +1 -0
- package/components/hy-keyboard/props.ts +108 -0
- package/components/hy-keyboard/typing.d.ts +18 -0
- package/components/hy-list/hy-list.vue +15 -13
- package/components/hy-list/props.ts +1 -1
- package/components/hy-modal/typing.d.ts +2 -2
- package/components/hy-notice-bar/hy-column-notice.vue +54 -94
- package/components/hy-notice-bar/hy-notice-bar.vue +128 -96
- package/components/hy-notice-bar/hy-row-notice.vue +89 -121
- package/components/hy-notice-bar/props.ts +86 -85
- package/components/hy-notify/hy-notify.vue +10 -10
- package/components/hy-notify/typing.d.ts +35 -0
- package/components/hy-number-step/hy-number-step.vue +370 -367
- package/components/hy-number-step/index.scss +1 -0
- package/components/hy-number-step/props.ts +1 -1
- package/components/hy-picker/hy-picker.vue +126 -149
- package/components/hy-picker/props.ts +4 -1
- package/components/hy-picker/typing.d.ts +22 -0
- package/components/hy-popover/hy-popover.vue +2 -2
- package/components/hy-popover/typing.d.ts +1 -1
- package/components/hy-popup/hy-popup.vue +1 -1
- package/components/hy-popup/index.scss +1 -0
- package/components/hy-price/hy-price.vue +52 -23
- package/components/hy-price/props.ts +54 -54
- package/components/hy-radio/props.ts +1 -1
- package/components/hy-radio/typing.d.ts +5 -1
- package/components/hy-rolling-num/typing.d.ts +1 -0
- package/components/hy-signature/hy-signature.vue +17 -17
- package/components/hy-signature/typing.d.ts +1 -1
- package/components/hy-skeleton/index.scss +17 -0
- package/components/hy-steps/hy-steps.vue +1 -1
- package/components/hy-submit-bar/typing.d.ts +3 -3
- package/components/hy-swipe-action/hy-swipe-action.vue +34 -15
- package/components/hy-swipe-action/index.scss +0 -1
- package/components/hy-switch/typing.d.ts +4 -0
- package/components/hy-tabbar/props.ts +2 -1
- package/components/hy-tabbar/typing.d.ts +5 -4
- package/components/hy-tabs/hy-tabs.vue +338 -336
- package/components/hy-tabs/index.scss +6 -6
- package/components/hy-tabs/typing.d.ts +41 -33
- package/components/hy-textarea/hy-textarea.vue +2 -2
- package/components/hy-textarea/typing.d.ts +4 -0
- package/components/hy-toast/hy-toast.vue +17 -9
- package/components/hy-toast/index.scss +1 -1
- package/components/hy-toast/typing.d.ts +56 -37
- package/components/hy-tooltip/hy-tooltip.vue +1 -1
- package/components/hy-tooltip/index.scss +1 -0
- package/components/hy-tooltip/props.ts +1 -1
- package/components/hy-upload/hy-upload.vue +16 -1
- package/components/hy-upload/index.scss +149 -144
- package/components/index.ts +6 -0
- package/global.d.ts +2 -0
- package/libs/api/http.ts +122 -119
- package/libs/config/icon.ts +442 -430
- package/libs/css/_function.scss +7 -13
- package/libs/css/iconfont.css +445 -441
- package/libs/css/theme.scss +3 -1
- package/libs/locale/lang/en-US.ts +4 -0
- package/libs/locale/lang/zh-CN.ts +4 -0
- package/libs/typing/index.ts +80 -0
- package/package.json +5 -2
- package/tags.json +1 -1
- package/web-types.json +1 -1
- package/components/hy-folding-panel/hy-folding-panel-group.vue +0 -163
- package/components/hy-qrcode/qrcode.js.bak +0 -1434
|
@@ -1,367 +1,370 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view class="hy-number-box">
|
|
3
|
-
<!-- 减号 -->
|
|
4
|
-
<view
|
|
5
|
-
v-if="showMinus && !hideMinus && $slots.minus"
|
|
6
|
-
class="hy-number-box__slot cursor-pointer"
|
|
7
|
-
@tap.stop="clickHandler('minus')"
|
|
8
|
-
@touchstart="onTouchStart('minus')"
|
|
9
|
-
@touchend.stop="onClearTimeout"
|
|
10
|
-
>
|
|
11
|
-
<slot name="minus" />
|
|
12
|
-
</view>
|
|
13
|
-
<view
|
|
14
|
-
v-else-if="showMinus && !hideMinus"
|
|
15
|
-
@tap.stop="clickHandler('minus')"
|
|
16
|
-
@touchstart="onTouchStart('minus')"
|
|
17
|
-
@touchend.stop="onClearTimeout"
|
|
18
|
-
hover-class="hy-number-box__minus--hover"
|
|
19
|
-
hover-stay-time="150"
|
|
20
|
-
:class="[
|
|
21
|
-
{ 'hy-number-box__minus--disabled': isDisabled('minus') },
|
|
22
|
-
'hy-number-box__minus',
|
|
23
|
-
'cursor-pointer'
|
|
24
|
-
]"
|
|
25
|
-
:style="buttonStyle('minus')"
|
|
26
|
-
>
|
|
27
|
-
<hy-icon
|
|
28
|
-
:name="minusIcon?.name || IconConfig.MINUS"
|
|
29
|
-
:color="isDisabled('minus') ? '#c8c9cc' : minusIcon?.color"
|
|
30
|
-
:size="minusIcon?.size"
|
|
31
|
-
:bold="minusIcon?.bold"
|
|
32
|
-
:customPrefix="minusIcon?.customPrefix"
|
|
33
|
-
:imgMode="minusIcon?.imgMode"
|
|
34
|
-
:width="minusIcon?.width"
|
|
35
|
-
:height="minusIcon?.height"
|
|
36
|
-
:top="minusIcon?.top"
|
|
37
|
-
:stop="minusIcon?.stop"
|
|
38
|
-
:round="minusIcon?.round"
|
|
39
|
-
:customStyle="minusIcon?.customStyle"
|
|
40
|
-
></hy-icon>
|
|
41
|
-
</view>
|
|
42
|
-
<!-- 减号 -->
|
|
43
|
-
|
|
44
|
-
<template v-if="!hideMinus">
|
|
45
|
-
<!-- 中间输入框组件 -->
|
|
46
|
-
<slot v-if="$slots.input" name="input" :record="currentValue"></slot>
|
|
47
|
-
<template v-else>
|
|
48
|
-
<!-- #ifdef MP-WEIXIN -->
|
|
49
|
-
<input
|
|
50
|
-
:disabled="disabledInput || disabled"
|
|
51
|
-
:cursor-spacing="getCursorSpacing"
|
|
52
|
-
:class="[
|
|
53
|
-
{
|
|
54
|
-
'hy-number-box__input--disabled': disabled || disabledInput
|
|
55
|
-
},
|
|
56
|
-
'hy-number-box__input'
|
|
57
|
-
]"
|
|
58
|
-
:value="currentValue"
|
|
59
|
-
@blur="onBlur"
|
|
60
|
-
@focus="onFocus"
|
|
61
|
-
@input="onInput"
|
|
62
|
-
type="number"
|
|
63
|
-
:style="[inputStyle]"
|
|
64
|
-
/>
|
|
65
|
-
<!-- #endif -->
|
|
66
|
-
<!-- #ifndef MP-WEIXIN -->
|
|
67
|
-
<input
|
|
68
|
-
:disabled="disabledInput || disabled"
|
|
69
|
-
:cursor-spacing="getCursorSpacing"
|
|
70
|
-
:class="[
|
|
71
|
-
{
|
|
72
|
-
'hy-number-box__input--disabled': disabled || disabledInput
|
|
73
|
-
},
|
|
74
|
-
'hy-number-box__input'
|
|
75
|
-
]"
|
|
76
|
-
v-model="currentValue"
|
|
77
|
-
@blur="onBlur"
|
|
78
|
-
@focus="onFocus"
|
|
79
|
-
@input="onInput"
|
|
80
|
-
type="number"
|
|
81
|
-
:style="[inputStyle]"
|
|
82
|
-
/>
|
|
83
|
-
<!-- #endif -->
|
|
84
|
-
</template>
|
|
85
|
-
</template>
|
|
86
|
-
|
|
87
|
-
<!-- 加号 -->
|
|
88
|
-
<view
|
|
89
|
-
class="hy-number-box__slot cursor-pointer"
|
|
90
|
-
@tap.stop="clickHandler('plus')"
|
|
91
|
-
@touchstart="onTouchStart('plus')"
|
|
92
|
-
v-if="showPlus && $slots.plus"
|
|
93
|
-
@touchend.stop="onClearTimeout"
|
|
94
|
-
>
|
|
95
|
-
<slot name="plus" />
|
|
96
|
-
</view>
|
|
97
|
-
<view
|
|
98
|
-
v-else-if="showPlus"
|
|
99
|
-
@tap.stop="clickHandler('plus')"
|
|
100
|
-
@touchstart="onTouchStart('plus')"
|
|
101
|
-
@touchend.stop="onClearTimeout"
|
|
102
|
-
hover-class="hy-number-box__plus--hover"
|
|
103
|
-
hover-stay-time="150"
|
|
104
|
-
:class="[
|
|
105
|
-
{ 'hy-number-box__plus--disabled': isDisabled('plus') },
|
|
106
|
-
'hy-number-box__plus',
|
|
107
|
-
'cursor-pointer'
|
|
108
|
-
]"
|
|
109
|
-
:style="[buttonStyle('plus')]"
|
|
110
|
-
>
|
|
111
|
-
<hy-icon
|
|
112
|
-
:name="plusIcon?.name || IconConfig.PLUS"
|
|
113
|
-
:color="isDisabled('plus') ? '#c8c9cc' : plusIcon?.color"
|
|
114
|
-
:size="plusIcon?.size"
|
|
115
|
-
:bold="plusIcon?.bold"
|
|
116
|
-
:customPrefix="plusIcon?.customPrefix"
|
|
117
|
-
:imgMode="plusIcon?.imgMode"
|
|
118
|
-
:width="plusIcon?.width"
|
|
119
|
-
:height="plusIcon?.height"
|
|
120
|
-
:top="plusIcon?.top"
|
|
121
|
-
:stop="plusIcon?.stop"
|
|
122
|
-
:round="plusIcon?.round"
|
|
123
|
-
:customStyle="plusIcon?.customStyle"
|
|
124
|
-
></hy-icon>
|
|
125
|
-
</view>
|
|
126
|
-
<!-- 加号 -->
|
|
127
|
-
</view>
|
|
128
|
-
</template>
|
|
129
|
-
|
|
130
|
-
<script lang="ts">
|
|
131
|
-
export default {
|
|
132
|
-
name: 'hy-number-step',
|
|
133
|
-
options: {
|
|
134
|
-
addGlobalClass: true,
|
|
135
|
-
virtualHost: true,
|
|
136
|
-
styleIsolation: 'shared'
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
</script>
|
|
140
|
-
|
|
141
|
-
<script setup lang="ts">
|
|
142
|
-
import { computed, ref, watch, onMounted, nextTick } from 'vue'
|
|
143
|
-
import type { CSSProperties } from 'vue'
|
|
144
|
-
import { addUnit, IconConfig } from '../../libs'
|
|
145
|
-
import type { INumberStepEmits } from './typing'
|
|
146
|
-
import type { InputOnBlurEvent, InputOnFocusEvent, InputOnInputEvent } from '@uni-helper/uni-types'
|
|
147
|
-
import numberStepProps from './props'
|
|
148
|
-
// 组件
|
|
149
|
-
import HyIcon from '../hy-icon/hy-icon.vue'
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* 一般用于商城购物选择物品数量的场景
|
|
153
|
-
* @displayName hy-number-step
|
|
154
|
-
*/
|
|
155
|
-
defineOptions({})
|
|
156
|
-
|
|
157
|
-
const props = defineProps(numberStepProps)
|
|
158
|
-
const emit = defineEmits<INumberStepEmits>()
|
|
159
|
-
type StepType = 'plus' | 'minus'
|
|
160
|
-
|
|
161
|
-
// 输入框实际操作的值
|
|
162
|
-
const currentValue = ref<number>(0)
|
|
163
|
-
// 定时器
|
|
164
|
-
let longPressTimer: ReturnType<typeof setTimeout> | null = null
|
|
165
|
-
|
|
166
|
-
const stepType = ref<StepType>('plus')
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* @description 格式化整理数据,限制范围
|
|
170
|
-
* @param value 处理值
|
|
171
|
-
* */
|
|
172
|
-
const format = (value: number | string): number => {
|
|
173
|
-
// 如果为空字符串,那么设置为0,同时将值转为Number类型
|
|
174
|
-
value = !value ? 0 : +value
|
|
175
|
-
// 对比最大最小值,取在min和max之间的值
|
|
176
|
-
value = Math.max(Math.min(props.max, value), props.min)
|
|
177
|
-
// 如果设定了最大的小数位数,使用toFixed去进行格式化
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
() =>
|
|
192
|
-
)
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
(
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
//
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
*
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<view class="hy-number-box">
|
|
3
|
+
<!-- 减号 -->
|
|
4
|
+
<view
|
|
5
|
+
v-if="showMinus && !hideMinus && $slots.minus"
|
|
6
|
+
class="hy-number-box__slot cursor-pointer"
|
|
7
|
+
@tap.stop="clickHandler('minus')"
|
|
8
|
+
@touchstart="onTouchStart('minus')"
|
|
9
|
+
@touchend.stop="onClearTimeout"
|
|
10
|
+
>
|
|
11
|
+
<slot name="minus" />
|
|
12
|
+
</view>
|
|
13
|
+
<view
|
|
14
|
+
v-else-if="showMinus && !hideMinus"
|
|
15
|
+
@tap.stop="clickHandler('minus')"
|
|
16
|
+
@touchstart="onTouchStart('minus')"
|
|
17
|
+
@touchend.stop="onClearTimeout"
|
|
18
|
+
hover-class="hy-number-box__minus--hover"
|
|
19
|
+
hover-stay-time="150"
|
|
20
|
+
:class="[
|
|
21
|
+
{ 'hy-number-box__minus--disabled': isDisabled('minus') },
|
|
22
|
+
'hy-number-box__minus',
|
|
23
|
+
'cursor-pointer'
|
|
24
|
+
]"
|
|
25
|
+
:style="buttonStyle('minus')"
|
|
26
|
+
>
|
|
27
|
+
<hy-icon
|
|
28
|
+
:name="minusIcon?.name || IconConfig.MINUS"
|
|
29
|
+
:color="isDisabled('minus') ? '#c8c9cc' : minusIcon?.color"
|
|
30
|
+
:size="minusIcon?.size"
|
|
31
|
+
:bold="minusIcon?.bold"
|
|
32
|
+
:customPrefix="minusIcon?.customPrefix"
|
|
33
|
+
:imgMode="minusIcon?.imgMode"
|
|
34
|
+
:width="minusIcon?.width"
|
|
35
|
+
:height="minusIcon?.height"
|
|
36
|
+
:top="minusIcon?.top"
|
|
37
|
+
:stop="minusIcon?.stop"
|
|
38
|
+
:round="minusIcon?.round"
|
|
39
|
+
:customStyle="minusIcon?.customStyle"
|
|
40
|
+
></hy-icon>
|
|
41
|
+
</view>
|
|
42
|
+
<!-- 减号 -->
|
|
43
|
+
|
|
44
|
+
<template v-if="!hideMinus">
|
|
45
|
+
<!-- 中间输入框组件 -->
|
|
46
|
+
<slot v-if="$slots.input" name="input" :record="currentValue"></slot>
|
|
47
|
+
<template v-else>
|
|
48
|
+
<!-- #ifdef MP-WEIXIN -->
|
|
49
|
+
<input
|
|
50
|
+
:disabled="disabledInput || disabled"
|
|
51
|
+
:cursor-spacing="getCursorSpacing"
|
|
52
|
+
:class="[
|
|
53
|
+
{
|
|
54
|
+
'hy-number-box__input--disabled': disabled || disabledInput
|
|
55
|
+
},
|
|
56
|
+
'hy-number-box__input'
|
|
57
|
+
]"
|
|
58
|
+
:value="currentValue"
|
|
59
|
+
@blur="onBlur"
|
|
60
|
+
@focus="onFocus"
|
|
61
|
+
@input="onInput"
|
|
62
|
+
type="number"
|
|
63
|
+
:style="[inputStyle]"
|
|
64
|
+
/>
|
|
65
|
+
<!-- #endif -->
|
|
66
|
+
<!-- #ifndef MP-WEIXIN -->
|
|
67
|
+
<input
|
|
68
|
+
:disabled="disabledInput || disabled"
|
|
69
|
+
:cursor-spacing="getCursorSpacing"
|
|
70
|
+
:class="[
|
|
71
|
+
{
|
|
72
|
+
'hy-number-box__input--disabled': disabled || disabledInput
|
|
73
|
+
},
|
|
74
|
+
'hy-number-box__input'
|
|
75
|
+
]"
|
|
76
|
+
v-model="currentValue"
|
|
77
|
+
@blur="onBlur"
|
|
78
|
+
@focus="onFocus"
|
|
79
|
+
@input="onInput"
|
|
80
|
+
type="number"
|
|
81
|
+
:style="[inputStyle]"
|
|
82
|
+
/>
|
|
83
|
+
<!-- #endif -->
|
|
84
|
+
</template>
|
|
85
|
+
</template>
|
|
86
|
+
|
|
87
|
+
<!-- 加号 -->
|
|
88
|
+
<view
|
|
89
|
+
class="hy-number-box__slot cursor-pointer"
|
|
90
|
+
@tap.stop="clickHandler('plus')"
|
|
91
|
+
@touchstart="onTouchStart('plus')"
|
|
92
|
+
v-if="showPlus && $slots.plus"
|
|
93
|
+
@touchend.stop="onClearTimeout"
|
|
94
|
+
>
|
|
95
|
+
<slot name="plus" />
|
|
96
|
+
</view>
|
|
97
|
+
<view
|
|
98
|
+
v-else-if="showPlus"
|
|
99
|
+
@tap.stop="clickHandler('plus')"
|
|
100
|
+
@touchstart="onTouchStart('plus')"
|
|
101
|
+
@touchend.stop="onClearTimeout"
|
|
102
|
+
hover-class="hy-number-box__plus--hover"
|
|
103
|
+
hover-stay-time="150"
|
|
104
|
+
:class="[
|
|
105
|
+
{ 'hy-number-box__plus--disabled': isDisabled('plus') },
|
|
106
|
+
'hy-number-box__plus',
|
|
107
|
+
'cursor-pointer'
|
|
108
|
+
]"
|
|
109
|
+
:style="[buttonStyle('plus')]"
|
|
110
|
+
>
|
|
111
|
+
<hy-icon
|
|
112
|
+
:name="plusIcon?.name || IconConfig.PLUS"
|
|
113
|
+
:color="isDisabled('plus') ? '#c8c9cc' : plusIcon?.color"
|
|
114
|
+
:size="plusIcon?.size"
|
|
115
|
+
:bold="plusIcon?.bold"
|
|
116
|
+
:customPrefix="plusIcon?.customPrefix"
|
|
117
|
+
:imgMode="plusIcon?.imgMode"
|
|
118
|
+
:width="plusIcon?.width"
|
|
119
|
+
:height="plusIcon?.height"
|
|
120
|
+
:top="plusIcon?.top"
|
|
121
|
+
:stop="plusIcon?.stop"
|
|
122
|
+
:round="plusIcon?.round"
|
|
123
|
+
:customStyle="plusIcon?.customStyle"
|
|
124
|
+
></hy-icon>
|
|
125
|
+
</view>
|
|
126
|
+
<!-- 加号 -->
|
|
127
|
+
</view>
|
|
128
|
+
</template>
|
|
129
|
+
|
|
130
|
+
<script lang="ts">
|
|
131
|
+
export default {
|
|
132
|
+
name: 'hy-number-step',
|
|
133
|
+
options: {
|
|
134
|
+
addGlobalClass: true,
|
|
135
|
+
virtualHost: true,
|
|
136
|
+
styleIsolation: 'shared'
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
</script>
|
|
140
|
+
|
|
141
|
+
<script setup lang="ts">
|
|
142
|
+
import { computed, ref, watch, onMounted, nextTick } from 'vue'
|
|
143
|
+
import type { CSSProperties } from 'vue'
|
|
144
|
+
import { addUnit, IconConfig } from '../../libs'
|
|
145
|
+
import type { INumberStepEmits } from './typing'
|
|
146
|
+
import type { InputOnBlurEvent, InputOnFocusEvent, InputOnInputEvent } from '@uni-helper/uni-types'
|
|
147
|
+
import numberStepProps from './props'
|
|
148
|
+
// 组件
|
|
149
|
+
import HyIcon from '../hy-icon/hy-icon.vue'
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* 一般用于商城购物选择物品数量的场景
|
|
153
|
+
* @displayName hy-number-step
|
|
154
|
+
*/
|
|
155
|
+
defineOptions({})
|
|
156
|
+
|
|
157
|
+
const props = defineProps(numberStepProps)
|
|
158
|
+
const emit = defineEmits<INumberStepEmits>()
|
|
159
|
+
type StepType = 'plus' | 'minus'
|
|
160
|
+
|
|
161
|
+
// 输入框实际操作的值
|
|
162
|
+
const currentValue = ref<number>(0)
|
|
163
|
+
// 定时器
|
|
164
|
+
let longPressTimer: ReturnType<typeof setTimeout> | null = null
|
|
165
|
+
|
|
166
|
+
const stepType = ref<StepType>('plus')
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @description 格式化整理数据,限制范围
|
|
170
|
+
* @param value 处理值
|
|
171
|
+
* */
|
|
172
|
+
const format = (value: number | string): number => {
|
|
173
|
+
// 如果为空字符串,那么设置为0,同时将值转为Number类型
|
|
174
|
+
value = !value ? 0 : +value
|
|
175
|
+
// 对比最大最小值,取在min和max之间的值
|
|
176
|
+
value = Math.max(Math.min(props.max, value), props.min)
|
|
177
|
+
// 如果设定了最大的小数位数,使用toFixed去进行格式化
|
|
178
|
+
console.log(value, 111)
|
|
179
|
+
if (props.decimalLength !== null) {
|
|
180
|
+
value = parseFloat(value.toFixed(props.decimalLength))
|
|
181
|
+
}
|
|
182
|
+
return value
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// 用于监听多个值发生变化
|
|
186
|
+
const watchChange = computed(() => {
|
|
187
|
+
return [props.integer, props.decimalLength, props.min, props.max]
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
watch(
|
|
191
|
+
() => watchChange.value,
|
|
192
|
+
() => check()
|
|
193
|
+
)
|
|
194
|
+
watch(
|
|
195
|
+
() => props.modelValue,
|
|
196
|
+
(newValue: number) => {
|
|
197
|
+
if (newValue !== currentValue.value) {
|
|
198
|
+
currentValue.value = format(props.modelValue)
|
|
199
|
+
}
|
|
200
|
+
console.log(currentValue.value)
|
|
201
|
+
},
|
|
202
|
+
{ immediate: true }
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
const hideMinus = computed(() => {
|
|
206
|
+
return currentValue.value == 0 && props.miniMode
|
|
207
|
+
})
|
|
208
|
+
const getCursorSpacing = computed(() => {
|
|
209
|
+
// 判断传入的单位,如果为px单位,需要转成px
|
|
210
|
+
return props.cursorSpacing
|
|
211
|
+
})
|
|
212
|
+
// 按钮的样式
|
|
213
|
+
const buttonStyle = computed(() => {
|
|
214
|
+
return (type: string) => {
|
|
215
|
+
const style: CSSProperties = {
|
|
216
|
+
backgroundColor: props.bgColor,
|
|
217
|
+
width: addUnit(props.buttonWidth),
|
|
218
|
+
height: addUnit(props.buttonSize),
|
|
219
|
+
color: props.color,
|
|
220
|
+
borderRadius: props.buttonRadius
|
|
221
|
+
}
|
|
222
|
+
return style
|
|
223
|
+
}
|
|
224
|
+
})
|
|
225
|
+
// 输入框的样式
|
|
226
|
+
const inputStyle = computed<CSSProperties>(() => {
|
|
227
|
+
// const disabled_1 = props.disabled || disabledInput.value;
|
|
228
|
+
return {
|
|
229
|
+
color: props.color,
|
|
230
|
+
backgroundColor: props.inputBgColor || props.bgColor,
|
|
231
|
+
height: addUnit(props.buttonSize),
|
|
232
|
+
width: addUnit(props.inputWidth)
|
|
233
|
+
}
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
const isDisabled = computed(() => {
|
|
237
|
+
return (type: string) => {
|
|
238
|
+
if (type === 'plus') {
|
|
239
|
+
// 在点击增加按钮情况下,判断整体的disabled,是否单独禁用增加按钮,以及当前值是否大于最大的允许值
|
|
240
|
+
return props.disabled || props.disablePlus || currentValue.value >= props.max
|
|
241
|
+
}
|
|
242
|
+
// 点击减少按钮同理
|
|
243
|
+
return props.disabled || props.disableMinus || currentValue.value <= props.min
|
|
244
|
+
}
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
onMounted(() => {
|
|
248
|
+
init()
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
const init = () => {
|
|
252
|
+
console.log(format(props.modelValue), '===')
|
|
253
|
+
currentValue.value = format(props.modelValue)
|
|
254
|
+
}
|
|
255
|
+
const check = () => {
|
|
256
|
+
// 格式化了之后,如果前后的值不相等,那么设置为格式化后的值
|
|
257
|
+
const val = format(currentValue.value)
|
|
258
|
+
if (val != currentValue.value) {
|
|
259
|
+
currentValue.value = val
|
|
260
|
+
emitChange(val)
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* @description 输入框活动焦点
|
|
266
|
+
*/
|
|
267
|
+
const onFocus = (event: InputOnFocusEvent) => {
|
|
268
|
+
emit('focus', event.detail.value)
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* @description 输入框失去焦点
|
|
272
|
+
*/
|
|
273
|
+
const onBlur = (event: InputOnBlurEvent) => {
|
|
274
|
+
// 对输入值进行格式化
|
|
275
|
+
format(Number(event.detail.value))
|
|
276
|
+
// 发出blur事件
|
|
277
|
+
emit('blur', event.detail.value)
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* @description 输入框值发生变化
|
|
281
|
+
*/
|
|
282
|
+
const onInput = (e: InputOnInputEvent) => {
|
|
283
|
+
const { value = '' } = e.detail || {}
|
|
284
|
+
// 为空返回
|
|
285
|
+
if (value === '') return
|
|
286
|
+
let formatted = value
|
|
287
|
+
// https://github.com/ijry/uview-plus/issues/613
|
|
288
|
+
emitChange(value)
|
|
289
|
+
// 最大允许的小数长度
|
|
290
|
+
if (props.decimalLength !== null && formatted.indexOf('.') !== -1) {
|
|
291
|
+
const pair = formatted.split('.')
|
|
292
|
+
formatted = `${pair[0]}.${pair[1].slice(0, props.decimalLength)}`
|
|
293
|
+
}
|
|
294
|
+
formatted = format(formatted).toString()
|
|
295
|
+
emitChange(formatted)
|
|
296
|
+
// #ifdef MP-WEIXIN
|
|
297
|
+
return formatted
|
|
298
|
+
// #endif
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* @description 发出change事件
|
|
302
|
+
* @param value 值
|
|
303
|
+
*/
|
|
304
|
+
const emitChange = (value: number | string) => {
|
|
305
|
+
// 如果开启了异步变更值,则不修改内部的值,需要用户手动在外部通过v-model变更
|
|
306
|
+
if (!props.asyncChange) {
|
|
307
|
+
nextTick(() => {
|
|
308
|
+
emit('update:modelValue', value)
|
|
309
|
+
currentValue.value = Number(value)
|
|
310
|
+
// this.$forceUpdate()
|
|
311
|
+
})
|
|
312
|
+
}
|
|
313
|
+
emit('change', value)
|
|
314
|
+
}
|
|
315
|
+
const onChange = () => {
|
|
316
|
+
if (isDisabled.value(stepType.value)) {
|
|
317
|
+
return emit('overLimit', stepType.value)
|
|
318
|
+
}
|
|
319
|
+
const diff = stepType.value === 'minus' ? -props.step : +props.step
|
|
320
|
+
const value = format(add(+currentValue.value, diff))
|
|
321
|
+
emitChange(value)
|
|
322
|
+
emit(stepType.value, value)
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* @description 对值扩大后进行四舍五入,再除以扩大因子,避免出现浮点数操作的精度问题
|
|
326
|
+
* @param num1
|
|
327
|
+
* @param num2
|
|
328
|
+
* */
|
|
329
|
+
const add = (num1: number, num2: number) => {
|
|
330
|
+
const cardinal = Math.pow(10, 10)
|
|
331
|
+
return Math.round((num1 + num2) * cardinal) / cardinal
|
|
332
|
+
}
|
|
333
|
+
// 点击加减按钮
|
|
334
|
+
const clickHandler = (type: StepType) => {
|
|
335
|
+
stepType.value = type
|
|
336
|
+
onChange()
|
|
337
|
+
}
|
|
338
|
+
const longPressStep = () => {
|
|
339
|
+
// 每隔一段时间,重新调用longPressStep方法,实现长按加减
|
|
340
|
+
onClearTimeout()
|
|
341
|
+
longPressTimer = setTimeout(() => {
|
|
342
|
+
onChange()
|
|
343
|
+
longPressStep()
|
|
344
|
+
}, 250)
|
|
345
|
+
}
|
|
346
|
+
const onTouchStart = (type: StepType) => {
|
|
347
|
+
if (!props.longPress) return
|
|
348
|
+
onClearTimeout()
|
|
349
|
+
stepType.value = type
|
|
350
|
+
// 一定时间后,默认达到长按状态
|
|
351
|
+
longPressTimer = setTimeout(() => {
|
|
352
|
+
onChange()
|
|
353
|
+
longPressStep()
|
|
354
|
+
}, 600)
|
|
355
|
+
}
|
|
356
|
+
// 触摸结束,清除定时器,停止长按加减
|
|
357
|
+
const onTouchEnd = () => {
|
|
358
|
+
if (!props.longPress) return
|
|
359
|
+
onClearTimeout()
|
|
360
|
+
}
|
|
361
|
+
// 清除定时器
|
|
362
|
+
const onClearTimeout = () => {
|
|
363
|
+
clearTimeout(longPressTimer as number)
|
|
364
|
+
longPressTimer = null
|
|
365
|
+
}
|
|
366
|
+
</script>
|
|
367
|
+
|
|
368
|
+
<style lang="scss" scoped>
|
|
369
|
+
@import './index.scss';
|
|
370
|
+
</style>
|