@veritree/ui 0.78.0-0 → 0.78.0-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.
package/package.json
CHANGED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<input
|
|
3
|
+
v-model="valueFormatted"
|
|
4
|
+
:class="classComputed"
|
|
5
|
+
:disabled="disabled"
|
|
6
|
+
@input="onInput"
|
|
7
|
+
@change="onChange"
|
|
8
|
+
@blur="onBlur"
|
|
9
|
+
/>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script>
|
|
13
|
+
import {
|
|
14
|
+
formControlMixin,
|
|
15
|
+
formControlStyleMixin,
|
|
16
|
+
} from '../../../mixins/form-control';
|
|
17
|
+
|
|
18
|
+
export default {
|
|
19
|
+
name: 'VTInputNumber',
|
|
20
|
+
|
|
21
|
+
mixins: [formControlMixin, formControlStyleMixin],
|
|
22
|
+
|
|
23
|
+
model: {
|
|
24
|
+
prop: 'value',
|
|
25
|
+
event: 'input',
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
props: {
|
|
29
|
+
value: {
|
|
30
|
+
type: [String, Number, Object, Array, Date],
|
|
31
|
+
default: null,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
computed: {
|
|
36
|
+
valueComputed: {
|
|
37
|
+
get() {
|
|
38
|
+
if (this.value === null || this.value === undefined) {
|
|
39
|
+
return '';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return this.value;
|
|
43
|
+
},
|
|
44
|
+
set(value) {
|
|
45
|
+
this.$emit('input', this.unformatNumber(value));
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
valueFormatted: {
|
|
50
|
+
get() {
|
|
51
|
+
return Number(this.value).toLocaleString();
|
|
52
|
+
},
|
|
53
|
+
set(value) {
|
|
54
|
+
this.valueComputed = value;
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
methods: {
|
|
60
|
+
/**
|
|
61
|
+
* Unformats a formatted number string by removing commas and converting it to an integer.
|
|
62
|
+
*
|
|
63
|
+
* @param {string} formattedNumber - The formatted number string.
|
|
64
|
+
* @returns {number|null} - Returns the unformatted number as an integer, or null if the input is invalid.
|
|
65
|
+
*/
|
|
66
|
+
unformatNumber(number) {
|
|
67
|
+
if (!this.isValidNumber(number)) {
|
|
68
|
+
return null; // or any other appropriate value or behavior
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return parseInt(number.replace(/,/g, ''), 10);
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Checks if the input is a valid number.
|
|
76
|
+
*
|
|
77
|
+
* @param {string} input - The input string to check.
|
|
78
|
+
* @returns {boolean} - Returns true if the input is a valid number, otherwise false.
|
|
79
|
+
*/
|
|
80
|
+
isValidNumber(input) {
|
|
81
|
+
return (
|
|
82
|
+
input !== null &&
|
|
83
|
+
input !== undefined &&
|
|
84
|
+
input !== '' &&
|
|
85
|
+
!isNaN(Number(input.replace(/,/g, '')))
|
|
86
|
+
);
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
onChange(e) {
|
|
90
|
+
this.$emit('change', this.unformatNumber(e.target.value));
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
onInput(e) {
|
|
94
|
+
this.valueComputed = e.target.value;
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
onBlur() {
|
|
98
|
+
this.$emit('blur');
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
</script>
|