@ecolovo/uniapp-components 1.0.9 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -51
- package/components/aspect/aspect.vue +24 -15
- package/components/badge/badge.scss +20 -0
- package/components/badge/badge.vue +49 -40
- package/components/button/button.scss +15 -0
- package/components/button/button.vue +125 -181
- package/components/checkbox/checkbox.scss +10 -0
- package/components/checkbox/checkbox.vue +118 -146
- package/components/checkbox-group/checkbox-group.vue +79 -81
- package/components/checkbox-group2/checkbox-group2.vue +111 -107
- package/components/checkbox-group2/checkbox2.vue +104 -0
- package/components/data-list/data-list.scss +9 -0
- package/components/data-list/data-list.vue +70 -79
- package/components/date-picker/date-picker-view.vue +125 -124
- package/components/date-picker/date-picker.vue +145 -146
- package/components/dialog/dialog-content.vue +39 -47
- package/components/dialog/dialog.scss +11 -0
- package/components/dialog/dialog.vue +125 -138
- package/components/dropdown/dropdown.scss +11 -0
- package/components/dropdown/dropdown.vue +55 -97
- package/components/empty/empty.scss +14 -0
- package/components/empty/empty.vue +42 -41
- package/components/flex/flex.vue +45 -54
- package/components/form/form.vue +29 -24
- package/components/form-item/form-item.scss +11 -0
- package/components/form-item/form-item.vue +43 -40
- package/components/icon/icon.vue +70 -85
- package/components/image/image.vue +35 -38
- package/components/input/input.vue +65 -79
- package/components/input/password-input.vue +34 -42
- package/components/list-page/list-page.vue +73 -99
- package/components/load-more/load-more.scss +12 -0
- package/components/load-more/load-more.vue +29 -29
- package/components/loading/animations/loading-animation1.vue +8 -8
- package/components/loading/animations/loading-animation2.vue +8 -9
- package/components/loading/animations/loading-animation3.vue +11 -11
- package/components/loading/animations/loading-animation4.vue +8 -8
- package/components/loading/loading.vue +19 -20
- package/components/message-box/message-box.vue +59 -41
- package/components/number-dialog/number-dialog.scss +9 -0
- package/components/number-dialog/number-dialog.vue +209 -204
- package/components/number-input/number-input.scss +9 -0
- package/components/number-input/number-input.vue +233 -232
- package/components/numpad/numpad.scss +9 -0
- package/components/numpad/numpad.vue +133 -150
- package/components/page/page-body.scss +15 -0
- package/components/page/page-body.vue +137 -119
- package/components/page/page-footer.scss +13 -0
- package/components/page/page-footer.vue +31 -33
- package/components/page/page-header.scss +17 -0
- package/components/page/page-header.vue +89 -94
- package/components/page/page.scss +9 -0
- package/components/page/page.vue +105 -81
- package/components/picker/picker-popup.vue +218 -209
- package/components/picker/picker.vue +99 -104
- package/components/popover/popover-content.vue +54 -63
- package/components/popover/popover-mask.vue +63 -63
- package/components/popover/popover.scss +28 -0
- package/components/popover/popover.vue +49 -47
- package/components/popup/popup-content.vue +49 -53
- package/components/popup/popup.scss +11 -0
- package/components/popup/popup.vue +117 -132
- package/components/price/price.scss +20 -0
- package/components/price/price.vue +31 -42
- package/components/search/search.scss +12 -0
- package/components/search/search.vue +93 -117
- package/components/searching/searching.vue +33 -40
- package/components/selector/selector.vue +43 -48
- package/components/switch/switch.scss +12 -0
- package/components/switch/switch.vue +99 -96
- package/components/tab/tab.scss +19 -0
- package/components/tab/tab.vue +151 -145
- package/components/textarea/textarea.vue +104 -101
- package/composable/component-name.ts +10 -0
- package/configs/index.ts +82 -0
- package/{easyCom.js → easyCom.ts} +1 -1
- package/index.ts +1 -0
- package/init.ts +34 -0
- package/package.json +12 -4
- package/styles/utils/css-var.scss +12 -15
- package/styles/utils/ellipsis.scss +0 -7
- package/styles/utils/z-index.scss +1 -1
- package/styles/var/component.scss +21 -245
- package/utils/{date.js → date.ts} +44 -42
- package/utils/freezeDeep.ts +9 -0
- package/utils/price.ts +57 -0
- package/utils/round.ts +11 -0
- package/utils/{windowInfo.js → windowInfo.ts} +12 -35
- package/components/checkbox-group2/checkbox.vue +0 -109
- package/components/datetime-picker/datetime-picker-view.vue +0 -209
- package/components/datetime-picker/datetime-picker.vue +0 -235
- package/components/form/mixin.js +0 -13
- package/components/list-page/list-page.js +0 -10
- package/components/table/table.vue +0 -112
- package/components/time-picker/time-picker-view.vue +0 -127
- package/components/time-picker/time-picker.vue +0 -140
- package/components/uploader/download.js +0 -81
- package/components/uploader/file-uploader.vue +0 -52
- package/components/uploader/files.js +0 -225
- package/components/uploader/media-uploader.vue +0 -179
- package/components/uploader/mixin.js +0 -171
- package/components/uploader/uni.js +0 -38
- package/components/uploader/upload-button.vue +0 -29
- package/components/uploader/uploader copy.vue +0 -547
- package/components/uploader/uploader.vue +0 -117
- package/configs/index.d.ts +0 -22
- package/configs/index.js +0 -68
- package/init.d.ts +0 -19
- package/init.js +0 -20
- package/mixins/componentName.js +0 -32
- package/mixins/listPage.js +0 -1
- package/mixins/windowInfo.js +0 -1
- package/utils/fileSize.js +0 -39
- package/utils/floor.js +0 -20
- package/utils/freezeDeep.js +0 -19
- package/utils/price.js +0 -32
- package/utils/round.js +0 -22
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view
|
|
3
|
-
:class="[
|
|
3
|
+
:class="[...classNames, $style['NumberInput'], { [$style['NumberInput--step-mode']]: mode === 'step' }]"
|
|
4
4
|
@click.stop.prevent="doNothing"
|
|
5
5
|
>
|
|
6
6
|
<view
|
|
@@ -13,17 +13,17 @@
|
|
|
13
13
|
>
|
|
14
14
|
<icon-cpn
|
|
15
15
|
icon="step-minus"
|
|
16
|
-
@touchstart
|
|
17
|
-
@touchend
|
|
18
|
-
@touchcancel
|
|
16
|
+
@touchstart="handleStepLongTouchStart($event, -step, disabledDecrease)"
|
|
17
|
+
@touchend="handleStepLongTouchEnd(-step)"
|
|
18
|
+
@touchcancel="handleStepLongTouchEnd(-step)"
|
|
19
19
|
/>
|
|
20
20
|
</view>
|
|
21
21
|
<view v-if="isReadonly" :class="[$style['NumberInput--value'], { disabled }]">
|
|
22
|
-
{{
|
|
22
|
+
{{ modelValue }}
|
|
23
23
|
</view>
|
|
24
24
|
<input
|
|
25
25
|
v-else-if="editable || mode !== 'step'"
|
|
26
|
-
|
|
26
|
+
:value="editValue"
|
|
27
27
|
:type="type"
|
|
28
28
|
maxlength="14"
|
|
29
29
|
:class="[$style['NumberInput--input'], mode === 'step' ? $style['NumberInput--step-input'] : '']"
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
@focus="handleFocus"
|
|
35
35
|
@blur="handleInputConfirm"
|
|
36
36
|
/>
|
|
37
|
-
<view v-else :class="$style['NumberInput--input-value']">{{
|
|
37
|
+
<view v-else :class="$style['NumberInput--input-value']">{{ modelValue || 0 }}</view>
|
|
38
38
|
<view
|
|
39
39
|
v-if="mode === 'step' && !isReadonly"
|
|
40
40
|
:class="[
|
|
@@ -45,251 +45,252 @@
|
|
|
45
45
|
>
|
|
46
46
|
<icon-cpn
|
|
47
47
|
icon="step-plus"
|
|
48
|
-
@touchstart
|
|
49
|
-
@touchend
|
|
50
|
-
@touchcancel
|
|
48
|
+
@touchstart="handleStepLongTouchStart($event, step, disabledIncrease)"
|
|
49
|
+
@touchend="handleStepLongTouchEnd(step)"
|
|
50
|
+
@touchcancel="handleStepLongTouchEnd(step)"
|
|
51
51
|
/>
|
|
52
52
|
</view>
|
|
53
53
|
</view>
|
|
54
54
|
</template>
|
|
55
55
|
|
|
56
|
-
<script>
|
|
57
|
-
import
|
|
58
|
-
import
|
|
56
|
+
<script lang="ts" setup>
|
|
57
|
+
import { computed, inject, nextTick, ref, watch } from 'vue';
|
|
58
|
+
import useClassNames from '../../composable/component-name';
|
|
59
59
|
import { round } from '../../utils/round';
|
|
60
60
|
import IconCpn from '../icon/icon.vue';
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
const MAX = 9999999999;
|
|
64
|
-
const numberReg = /^(-?)(\d*)()(-?)$/;
|
|
65
|
-
|
|
66
|
-
export default {
|
|
67
|
-
name: 'NumberInput',
|
|
62
|
+
defineOptions({
|
|
68
63
|
options: {
|
|
69
64
|
virtualHost: true,
|
|
70
65
|
styleIsolation: 'shared',
|
|
71
66
|
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
value: {
|
|
163
|
-
handler(n) {
|
|
164
|
-
this.editValue = n + '';
|
|
165
|
-
},
|
|
166
|
-
immediate: true,
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
methods: {
|
|
170
|
-
doNothing() {},
|
|
171
|
-
/** 聚焦 */
|
|
172
|
-
handleFocus() {
|
|
173
|
-
this._lastValue = this.value;
|
|
174
|
-
this._lastEditValue = this.value;
|
|
175
|
-
},
|
|
176
|
-
handleLongTouchStart(event, step, disabled) {
|
|
177
|
-
if (disabled) return;
|
|
178
|
-
if (event.touches && event.touches.length > 1) return;
|
|
179
|
-
|
|
180
|
-
this._lastValue = this.value;
|
|
181
|
-
this._touchStep = step;
|
|
182
|
-
let interval = 400;
|
|
183
|
-
let times = 0;
|
|
184
|
-
|
|
185
|
-
const longTouch = () => {
|
|
186
|
-
if (!this.handleStep(step * (times >= 30 ? 4 : times >= 12 ? 2 : 1))) return;
|
|
187
|
-
|
|
188
|
-
this._touchTimer = setTimeout(longTouch, interval);
|
|
189
|
-
interval = Math.max(100, interval - 50);
|
|
190
|
-
times++;
|
|
191
|
-
};
|
|
192
|
-
longTouch();
|
|
193
|
-
},
|
|
194
|
-
handleLongTouchEnd(step) {
|
|
195
|
-
if (this._touchStep !== step) return;
|
|
196
|
-
if (this._touchTimer) {
|
|
197
|
-
clearTimeout(this._touchTimer);
|
|
198
|
-
this._touchTimer = null;
|
|
199
|
-
}
|
|
200
|
-
this._touchStep = null;
|
|
201
|
-
this.confirmValue(this.editValue + '', true);
|
|
202
|
-
},
|
|
203
|
-
/** 点击按钮修改数量 */
|
|
204
|
-
handleStep(step) {
|
|
205
|
-
if ((step > 0 && this.disabledIncrease) || (step < 0 && this.disabledDecrease)) {
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
208
|
-
let nextValue = round(+this.value + step, this.precision);
|
|
209
|
-
|
|
210
|
-
this.updateStepValue(nextValue + '');
|
|
211
|
-
return true;
|
|
212
|
-
},
|
|
213
|
-
handleInput(e) {
|
|
214
|
-
let value = e.detail.value.trim();
|
|
215
|
-
|
|
216
|
-
const match = this.inputTestReg.exec(value);
|
|
217
|
-
if (match) {
|
|
218
|
-
// sign: 负号; integer: 整数部分数字; decimal: 小数部分数字; resign: 再次输入负号,取消负号
|
|
219
|
-
let [, sign = '', integer = '', decimal = '', resign = ''] = match;
|
|
220
|
-
sign = !!sign ^ !!resign ? '-' : '';
|
|
221
|
-
integer = integer ? Number(integer) || '0' : decimal ? '0' : '';
|
|
222
|
-
value = sign + integer + decimal;
|
|
223
|
-
|
|
224
|
-
this._lastEditValue = value;
|
|
225
|
-
this.$emit('input', value);
|
|
226
|
-
this.$nextTick(() => {
|
|
227
|
-
this.editValue = value;
|
|
228
|
-
});
|
|
229
|
-
} else {
|
|
230
|
-
this.$nextTick(() => {
|
|
231
|
-
this.editValue = this._lastEditValue;
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
},
|
|
235
|
-
updateStepValue(value) {
|
|
236
|
-
value = this.validateValue(value, true);
|
|
237
|
-
this.$emit('input', value);
|
|
238
|
-
this.editValue = value;
|
|
239
|
-
},
|
|
240
|
-
/** 修改数目输入完毕 */
|
|
241
|
-
handleInputConfirm(e) {
|
|
242
|
-
let value = e.detail.value;
|
|
243
|
-
this.confirmValue(value);
|
|
244
|
-
},
|
|
245
|
-
/** 确认数据
|
|
246
|
-
* @param {string} value
|
|
247
|
-
*/
|
|
248
|
-
confirmValue(value, isStepButton = false) {
|
|
249
|
-
value = this.validateValue(value, isStepButton);
|
|
250
|
-
this.editValue = value + '';
|
|
251
|
-
|
|
252
|
-
this.$emit('input', value);
|
|
253
|
-
this.$emit('change', value);
|
|
254
|
-
},
|
|
255
|
-
/** 确认数据前校验
|
|
256
|
-
* @param {string} value
|
|
257
|
-
*/
|
|
258
|
-
validateValue(value, isStepButton = false) {
|
|
259
|
-
let _nextValue;
|
|
260
|
-
if (isNaN(value)) {
|
|
261
|
-
// 输入不合法,取消此次输入
|
|
262
|
-
_nextValue = isStepButton ? 0 : this._lastValue;
|
|
263
|
-
this.$emit('error', '请输入正确的数值');
|
|
264
|
-
} else if (value === '') {
|
|
265
|
-
// 输入空值
|
|
266
|
-
_nextValue = isStepButton ? 0 : '';
|
|
267
|
-
this.$emit('error', '请输入数值');
|
|
268
|
-
} else if (+value < this.min) {
|
|
269
|
-
// 超过最小输入值
|
|
270
|
-
_nextValue = this.min;
|
|
271
|
-
this.$emit('error', `数值不能小于 ${this.min}`);
|
|
272
|
-
} else if (+value > this.max) {
|
|
273
|
-
// 超过最大输入值
|
|
274
|
-
_nextValue = this.max;
|
|
275
|
-
this.$emit('error', `数值不能大于 ${this.max}`);
|
|
276
|
-
} else {
|
|
277
|
-
_nextValue = round(+value, this.precision);
|
|
278
|
-
}
|
|
279
|
-
return _nextValue;
|
|
280
|
-
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const classNames = useClassNames('number-input');
|
|
70
|
+
|
|
71
|
+
const MIN = 0;
|
|
72
|
+
const MAX = 9999999999;
|
|
73
|
+
const numberReg = /^(-?)(\d*)()(-?)$/;
|
|
74
|
+
|
|
75
|
+
type _Props = {
|
|
76
|
+
/** 绑定值 */
|
|
77
|
+
modelValue?: string | number;
|
|
78
|
+
/** 是否禁用 */
|
|
79
|
+
disabled?: boolean;
|
|
80
|
+
/** 是否可编辑 */
|
|
81
|
+
editable?: boolean;
|
|
82
|
+
/** 是否只读 */
|
|
83
|
+
readonly?: boolean;
|
|
84
|
+
/** 类型: input: 只有输入框 | step: 步进器,即带 + - 按钮 */
|
|
85
|
+
mode?: 'input' | 'step';
|
|
86
|
+
/** 输入模式: number: 只能输入整数 | digit: 小数 | text: 如需输入负数 */
|
|
87
|
+
type?: 'number' | 'digit' | 'text';
|
|
88
|
+
/** 占位提示文本 */
|
|
89
|
+
placeholder?: string;
|
|
90
|
+
/** 小数的精度 */
|
|
91
|
+
precision?: number;
|
|
92
|
+
/** 步进器的步长 */
|
|
93
|
+
step?: number;
|
|
94
|
+
/** 最大值 */
|
|
95
|
+
max?: number;
|
|
96
|
+
/** 最小值 */
|
|
97
|
+
min?: number;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const props = withDefaults(defineProps<_Props>(), {
|
|
101
|
+
modelValue: '',
|
|
102
|
+
disabled: false,
|
|
103
|
+
editable: true,
|
|
104
|
+
readonly: false,
|
|
105
|
+
mode: 'input',
|
|
106
|
+
type: 'number',
|
|
107
|
+
placeholder: '请输入',
|
|
108
|
+
precision: 0,
|
|
109
|
+
step: 1,
|
|
110
|
+
max: MAX,
|
|
111
|
+
min: MIN,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const emit = defineEmits<{
|
|
115
|
+
(e: 'update:modelValue', val: string | number): void;
|
|
116
|
+
(e: 'change', val: string | number): void;
|
|
117
|
+
(e: 'error', msg: string): void;
|
|
118
|
+
}>();
|
|
119
|
+
|
|
120
|
+
/** 表单是否只读 */
|
|
121
|
+
const isFormReadonly = inject(
|
|
122
|
+
'ecolovo/form/readonly',
|
|
123
|
+
computed(() => false)
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
/** 编辑值 */
|
|
127
|
+
const editValue = ref('');
|
|
128
|
+
|
|
129
|
+
/** 是否只读 */
|
|
130
|
+
const isReadonly = computed(() => props.readonly || isFormReadonly.value);
|
|
131
|
+
|
|
132
|
+
/** 输入校验正则 */
|
|
133
|
+
const inputTestReg = computed(() => {
|
|
134
|
+
return props.precision > 0 ? new RegExp('^(-?)(\\d*)(\\.\\d{0,' + props.precision + '})?(-?)$') : numberReg;
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
/** 是否禁用减 */
|
|
138
|
+
const disabledDecrease = computed(() => {
|
|
139
|
+
if (props.disabled) return true;
|
|
140
|
+
const val = Number(props.modelValue);
|
|
141
|
+
if (!Number.isNaN(val) && val <= Number(props.min)) return true;
|
|
142
|
+
return false;
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
/** 是否禁用增 */
|
|
146
|
+
const disabledIncrease = computed(() => {
|
|
147
|
+
if (props.disabled) return true;
|
|
148
|
+
const val = Number(props.modelValue);
|
|
149
|
+
if (!Number.isNaN(val) && val >= Number(props.max)) return true;
|
|
150
|
+
return false;
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
watch(
|
|
154
|
+
() => props.modelValue,
|
|
155
|
+
(n) => {
|
|
156
|
+
editValue.value = (n ?? '') + '';
|
|
281
157
|
},
|
|
158
|
+
{ immediate: true }
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
let _lastValue: string | number = '';
|
|
162
|
+
let _lastEditValue = '';
|
|
163
|
+
let _touchingStep: number | null = null;
|
|
164
|
+
let _touchTimer: ReturnType<typeof setTimeout> | null = null;
|
|
165
|
+
|
|
166
|
+
const doNothing = () => {};
|
|
167
|
+
|
|
168
|
+
/** 聚焦 */
|
|
169
|
+
const handleFocus = () => {
|
|
170
|
+
_lastValue = props.modelValue;
|
|
171
|
+
_lastEditValue = (props.modelValue ?? '') + '';
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/** 长按步进按钮开始处理 */
|
|
175
|
+
const handleStepLongTouchStart = (event: TouchEvent, step: number, disabled: boolean) => {
|
|
176
|
+
if (disabled) return;
|
|
177
|
+
if (event.touches.length > 1) return;
|
|
178
|
+
|
|
179
|
+
_lastValue = props.modelValue;
|
|
180
|
+
_touchingStep = step;
|
|
181
|
+
let interval = 400;
|
|
182
|
+
let times = 0;
|
|
183
|
+
|
|
184
|
+
const longTouch = () => {
|
|
185
|
+
if (!handleOneStep(step * (times >= 30 ? 4 : times >= 12 ? 2 : 1))) return;
|
|
186
|
+
|
|
187
|
+
_touchTimer = setTimeout(longTouch, interval);
|
|
188
|
+
interval = Math.max(100, interval - 50);
|
|
189
|
+
times++;
|
|
190
|
+
};
|
|
191
|
+
longTouch();
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
/** 长按步进按钮结束处理 */
|
|
195
|
+
const handleStepLongTouchEnd = (step: number) => {
|
|
196
|
+
if (_touchingStep !== step) return;
|
|
197
|
+
if (_touchTimer) {
|
|
198
|
+
clearTimeout(_touchTimer);
|
|
199
|
+
_touchTimer = null;
|
|
200
|
+
}
|
|
201
|
+
_touchingStep = null;
|
|
202
|
+
confirmValue(editValue.value + '', true);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
/** 单次步进处理 */
|
|
206
|
+
const handleOneStep = (step: number) => {
|
|
207
|
+
if ((step > 0 && disabledIncrease.value) || (step < 0 && disabledDecrease.value)) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
const nextValue = round(+props.modelValue + step, props.precision);
|
|
211
|
+
|
|
212
|
+
updateStepValue(nextValue + '');
|
|
213
|
+
return true;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/** 每次步进处理 */
|
|
217
|
+
const updateStepValue = (value: string) => {
|
|
218
|
+
const nextValue = validateValue(value, true);
|
|
219
|
+
emit('update:modelValue', nextValue);
|
|
220
|
+
editValue.value = nextValue + '';
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
/** 修改数目输入完毕 */
|
|
224
|
+
const handleInputConfirm = (e: FocusEvent) => {
|
|
225
|
+
const value = e.detail.value;
|
|
226
|
+
confirmValue(value);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
/** 校验数据 */
|
|
230
|
+
const validateValue = (value: string, isStepButton = false) => {
|
|
231
|
+
let nextValue: string | number;
|
|
232
|
+
if (isNaN(+value)) {
|
|
233
|
+
// 输入不合法,取消此次输入
|
|
234
|
+
nextValue = isStepButton ? 0 : _lastValue;
|
|
235
|
+
emit('error', '请输入正确的数值');
|
|
236
|
+
} else if (value === '') {
|
|
237
|
+
// 输入空值
|
|
238
|
+
nextValue = isStepButton ? 0 : '';
|
|
239
|
+
emit('error', '请输入数值');
|
|
240
|
+
} else if (+value < props.min) {
|
|
241
|
+
// 超过最小输入值
|
|
242
|
+
nextValue = props.min;
|
|
243
|
+
emit('error', `数值不能小于 ${props.min}`);
|
|
244
|
+
} else if (+value > props.max) {
|
|
245
|
+
// 超过最大输入值
|
|
246
|
+
nextValue = props.max;
|
|
247
|
+
emit('error', `数值不能大于 ${props.max}`);
|
|
248
|
+
} else {
|
|
249
|
+
nextValue = round(+value, props.precision);
|
|
250
|
+
}
|
|
251
|
+
return nextValue;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const handleInput = (e: InputEvent) => {
|
|
255
|
+
let value = e.detail.value.trim();
|
|
256
|
+
|
|
257
|
+
const match = inputTestReg.value.exec(value);
|
|
258
|
+
if (match) {
|
|
259
|
+
// sign: 负号; integer: 整数部分数字; decimal: 小数部分数字; resign: 再次输入负号,取消负号
|
|
260
|
+
const [, sign = '', integer = '', decimal = '', resign = ''] = match;
|
|
261
|
+
const signVal = (!!sign && !resign) || (!sign && !!resign) ? '-' : '';
|
|
262
|
+
const integerVal = integer ? Number(integer) || '0' : decimal ? '0' : '';
|
|
263
|
+
value = signVal + integerVal + decimal;
|
|
264
|
+
|
|
265
|
+
_lastEditValue = value;
|
|
266
|
+
emit('update:modelValue', value);
|
|
267
|
+
nextTick(() => {
|
|
268
|
+
editValue.value = value;
|
|
269
|
+
});
|
|
270
|
+
} else {
|
|
271
|
+
nextTick(() => {
|
|
272
|
+
editValue.value = _lastEditValue;
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
/** 确认数据 */
|
|
278
|
+
const confirmValue = (value: string, isStepButton = false) => {
|
|
279
|
+
const nextValue = validateValue(value, isStepButton);
|
|
280
|
+
editValue.value = nextValue + '';
|
|
281
|
+
|
|
282
|
+
emit('update:modelValue', nextValue);
|
|
283
|
+
emit('change', nextValue);
|
|
282
284
|
};
|
|
283
285
|
</script>
|
|
284
286
|
|
|
285
287
|
<style lang="scss" module>
|
|
286
|
-
@use '../../styles/
|
|
288
|
+
@use '../../styles/utils' as *;
|
|
289
|
+
@use './number-input' as *;
|
|
287
290
|
|
|
288
291
|
// 定义外部变量
|
|
289
|
-
$component-name: 'number-input';
|
|
290
|
-
$component-vars: $number-input;
|
|
291
292
|
%external-vars {
|
|
292
|
-
@include UTILS__DEFINE_COMPONENT_VARS();
|
|
293
|
+
@include UTILS__DEFINE_COMPONENT_VARS($number-input, 'number-input');
|
|
293
294
|
}
|
|
294
295
|
|
|
295
296
|
.NumberInput {
|