@tagplus/components 1.2.7 → 1.2.8
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/dist/tp.common.js +1 -1
- package/dist/tp.common.js.map +1 -1
- package/dist/tp.css +2 -2
- package/dist/tp.umd.js +1 -1
- package/dist/tp.umd.js.map +1 -1
- package/dist/tp.umd.min.js +1 -1
- package/dist/tp.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Money/Money.vue +2 -22
- package/src/components/Percent/Percent.vue +3 -22
- package/src/mixins/floatFormatter.js +34 -0
- package/src/utils/currency.js +18 -1
package/package.json
CHANGED
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
|
|
31
31
|
<script>
|
|
32
32
|
import Locale from 'tp-ui/mixins/locale'
|
|
33
|
-
import
|
|
33
|
+
import floatFormatterMixin from 'tp-ui/mixins/floatFormatter'
|
|
34
34
|
|
|
35
35
|
export default {
|
|
36
36
|
name: 'TpMoney',
|
|
37
37
|
|
|
38
|
-
mixins: [Locale],
|
|
38
|
+
mixins: [Locale, floatFormatterMixin],
|
|
39
39
|
props: {
|
|
40
40
|
id: {
|
|
41
41
|
type: String,
|
|
@@ -69,26 +69,6 @@ export default {
|
|
|
69
69
|
prepend () {
|
|
70
70
|
return this.t('tp.money.currency')
|
|
71
71
|
}
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
watch: {
|
|
75
|
-
value: {
|
|
76
|
-
immediate: true,
|
|
77
|
-
handler (newValue, oldValue) {
|
|
78
|
-
this.formattedValue = newValue
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
methods: {
|
|
84
|
-
input (evt) {
|
|
85
|
-
this.formattedValue = formatMoney(evt, true)
|
|
86
|
-
this.$emit('input', formatMoney(evt, false))
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
handleChange (evt) {
|
|
90
|
-
this.$emit('change', formatMoney(evt, false))
|
|
91
|
-
}
|
|
92
72
|
}
|
|
93
73
|
}
|
|
94
74
|
</script>
|
|
@@ -26,11 +26,12 @@
|
|
|
26
26
|
|
|
27
27
|
<script>
|
|
28
28
|
import Locale from 'tp-ui/mixins/locale'
|
|
29
|
-
import
|
|
29
|
+
import floatFormatterMixin from 'tp-ui/mixins/floatFormatter'
|
|
30
30
|
|
|
31
31
|
export default {
|
|
32
32
|
name: 'TpPercent',
|
|
33
|
-
|
|
33
|
+
|
|
34
|
+
mixins: [Locale, floatFormatterMixin],
|
|
34
35
|
props: {
|
|
35
36
|
id: {
|
|
36
37
|
type: String,
|
|
@@ -67,26 +68,6 @@ export default {
|
|
|
67
68
|
_id () {
|
|
68
69
|
return this.id || this.$options.name
|
|
69
70
|
}
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
watch: {
|
|
73
|
-
value: {
|
|
74
|
-
immediate: true,
|
|
75
|
-
handler (newValue, oldValue) {
|
|
76
|
-
this.formattedValue = newValue
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
methods: {
|
|
82
|
-
input (evt) {
|
|
83
|
-
this.formattedValue = formatMoney(evt, true)
|
|
84
|
-
this.$emit('input', formatMoney(evt, false))
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
handleChange (evt) {
|
|
88
|
-
this.$emit('change', formatMoney(evt, false))
|
|
89
|
-
}
|
|
90
71
|
}
|
|
91
72
|
}
|
|
92
73
|
</script>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { formatMoney } from 'tp-ui/utils/currency'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Eventos para componentes tp-money e tp-percent mostratem o número formatado com a precisão correta e devolver float sem arredondar
|
|
5
|
+
*/
|
|
6
|
+
export default {
|
|
7
|
+
data () {
|
|
8
|
+
return {
|
|
9
|
+
formattedValue: this.value
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
watch: {
|
|
14
|
+
value: {
|
|
15
|
+
immediate: true,
|
|
16
|
+
handler (newValue, oldValue) {
|
|
17
|
+
this.formattedValue = formatMoney(newValue, true)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
methods: {
|
|
23
|
+
input (evt) {
|
|
24
|
+
this.formattedValue = formatMoney(evt, true)
|
|
25
|
+
const moneyFormatado = formatMoney(evt, false)
|
|
26
|
+
this.$emit('input', moneyFormatado)
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
handleChange (evt) {
|
|
30
|
+
this.$emit('change', formatMoney(evt, false))
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
}
|
package/src/utils/currency.js
CHANGED
|
@@ -25,7 +25,10 @@ function unformat (input, precision = defaults.precision) {
|
|
|
25
25
|
|
|
26
26
|
function formatMoney (input, toString = false, precision = defaults.precision) {
|
|
27
27
|
const negative = ('' + input).indexOf('-') >= 0 ? -1 : 1
|
|
28
|
-
|
|
28
|
+
if (toString) {
|
|
29
|
+
input = completeZeros(('' + input), precision)
|
|
30
|
+
}
|
|
31
|
+
const numbers = onlyNumbers(input, precision)
|
|
29
32
|
const currency = numbersToCurrency(numbers, precision)
|
|
30
33
|
if (toString) {
|
|
31
34
|
return negative === -1 ? '-' + currency : '' + currency
|
|
@@ -34,6 +37,19 @@ function formatMoney (input, toString = false, precision = defaults.precision) {
|
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
39
|
|
|
40
|
+
function completeZeros (input, precision = defaults.precision) {
|
|
41
|
+
const i = input.indexOf('.')
|
|
42
|
+
const qntDecimais = i ? input.length - i - 1 : 0
|
|
43
|
+
|
|
44
|
+
// correção para decimal quebrado
|
|
45
|
+
if (i === -1) {
|
|
46
|
+
input = input + '.' + '0'.repeat(precision)
|
|
47
|
+
} else if (i && qntDecimais < precision) {
|
|
48
|
+
input = input + '0'.repeat(precision - qntDecimais)
|
|
49
|
+
}
|
|
50
|
+
return input
|
|
51
|
+
}
|
|
52
|
+
|
|
37
53
|
function onlyNumbers (input) {
|
|
38
54
|
return toStr(input).replace(/\D+/g, '') || '0'
|
|
39
55
|
}
|
|
@@ -90,5 +106,6 @@ export {
|
|
|
90
106
|
format,
|
|
91
107
|
unformat,
|
|
92
108
|
setCursor,
|
|
109
|
+
completeZeros,
|
|
93
110
|
event
|
|
94
111
|
}
|