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