@tagplus/components 1.2.2 → 1.2.5
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 +10 -6
- package/src/components/Percent/Percent.vue +9 -5
- package/src/utils/currency.js +14 -2
- package/src/utils/filters.js +20 -5
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<el-input
|
|
3
3
|
:id="`${_id}`"
|
|
4
4
|
class="tp-money"
|
|
5
|
-
:value="value |
|
|
5
|
+
:value="value | formatM"
|
|
6
6
|
v-bind="$attrs"
|
|
7
7
|
:maxlength="maxlength"
|
|
8
8
|
@input="input"
|
|
@@ -30,12 +30,16 @@
|
|
|
30
30
|
|
|
31
31
|
<script>
|
|
32
32
|
import Locale from 'tp-ui/mixins/locale'
|
|
33
|
-
import {
|
|
34
|
-
import { unformat } from 'tp-ui/utils/currency'
|
|
33
|
+
import { formatMoney } from 'tp-ui/utils/currency'
|
|
35
34
|
|
|
36
35
|
export default {
|
|
37
36
|
name: 'TpMoney',
|
|
38
|
-
filters: {
|
|
37
|
+
filters: {
|
|
38
|
+
formatM: (val) => {
|
|
39
|
+
return formatMoney(val, true)
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
|
|
39
43
|
mixins: [Locale],
|
|
40
44
|
props: {
|
|
41
45
|
id: {
|
|
@@ -74,11 +78,11 @@ export default {
|
|
|
74
78
|
|
|
75
79
|
methods: {
|
|
76
80
|
input (evt) {
|
|
77
|
-
this.$emit('input',
|
|
81
|
+
this.$emit('input', formatMoney(evt, false))
|
|
78
82
|
},
|
|
79
83
|
|
|
80
84
|
handleChange (evt) {
|
|
81
|
-
this.$emit('change',
|
|
85
|
+
this.$emit('change', formatMoney(evt, false))
|
|
82
86
|
}
|
|
83
87
|
}
|
|
84
88
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<el-input
|
|
3
3
|
:id="`${_id}`"
|
|
4
4
|
class="tp-percent"
|
|
5
|
-
:value="value |
|
|
5
|
+
:value="value | formatM"
|
|
6
6
|
v-bind="$attrs"
|
|
7
7
|
:maxlength="maxlength"
|
|
8
8
|
@input="input"
|
|
@@ -26,12 +26,16 @@
|
|
|
26
26
|
|
|
27
27
|
<script>
|
|
28
28
|
import Locale from 'tp-ui/mixins/locale'
|
|
29
|
-
import {
|
|
29
|
+
import { formatMoney } from 'tp-ui/utils/filters'
|
|
30
30
|
import { unformat } from 'tp-ui/utils/currency'
|
|
31
31
|
|
|
32
32
|
export default {
|
|
33
33
|
name: 'TpPercent',
|
|
34
|
-
filters: {
|
|
34
|
+
filters: {
|
|
35
|
+
formatM: (val) => {
|
|
36
|
+
return formatMoney(val, true)
|
|
37
|
+
}
|
|
38
|
+
},
|
|
35
39
|
mixins: [Locale],
|
|
36
40
|
props: {
|
|
37
41
|
id: {
|
|
@@ -73,11 +77,11 @@ export default {
|
|
|
73
77
|
|
|
74
78
|
methods: {
|
|
75
79
|
input (evt) {
|
|
76
|
-
this.$emit('input',
|
|
80
|
+
this.$emit('input', formatMoney(evt))
|
|
77
81
|
},
|
|
78
82
|
|
|
79
83
|
handleChange (evt) {
|
|
80
|
-
this.$emit('change',
|
|
84
|
+
this.$emit('change', formatMoney(evt))
|
|
81
85
|
}
|
|
82
86
|
}
|
|
83
87
|
}
|
package/src/utils/currency.js
CHANGED
|
@@ -17,10 +17,21 @@ function format (input, opt = defaults) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
function unformat (input, precision = defaults.precision) {
|
|
20
|
-
const negative = input.indexOf('-') >= 0 ? -1 : 1
|
|
20
|
+
const negative = ('' + input).indexOf('-') >= 0 ? -1 : 1
|
|
21
21
|
const numbers = onlyNumbers(input)
|
|
22
22
|
const currency = numbersToCurrency(numbers, precision)
|
|
23
|
-
return
|
|
23
|
+
return currency * negative
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function formatMoney (input, toString = false, precision = defaults.precision) {
|
|
27
|
+
const negative = ('' + input).indexOf('-') >= 0 ? -1 : 1
|
|
28
|
+
const numbers = onlyNumbers(input)
|
|
29
|
+
const currency = numbersToCurrency(numbers, precision)
|
|
30
|
+
if (toString) {
|
|
31
|
+
return negative === -1 ? '-' + currency : '' + currency
|
|
32
|
+
} else {
|
|
33
|
+
return currency * negative
|
|
34
|
+
}
|
|
24
35
|
}
|
|
25
36
|
|
|
26
37
|
function onlyNumbers (input) {
|
|
@@ -75,6 +86,7 @@ function event (name) {
|
|
|
75
86
|
}
|
|
76
87
|
|
|
77
88
|
export {
|
|
89
|
+
formatMoney,
|
|
78
90
|
format,
|
|
79
91
|
unformat,
|
|
80
92
|
setCursor,
|
package/src/utils/filters.js
CHANGED
|
@@ -17,15 +17,30 @@ import { t } from 'tp-ui/locale'
|
|
|
17
17
|
/**
|
|
18
18
|
* Transforma valor em String para exibição conforme localidade
|
|
19
19
|
* @param {Number} val
|
|
20
|
+
* @param {String} locale
|
|
20
21
|
*/
|
|
21
|
-
export const toCurrency = (val) => {
|
|
22
|
+
export const toCurrency = (val, locale = false) => {
|
|
22
23
|
if (val === '') {
|
|
23
24
|
return val
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
if (!locale) {
|
|
29
|
+
locale = t('locale.prefix')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let with2Decimals = val.toString().match(/^-?\d+(?:\.\d{0,2})?/)[0]
|
|
33
|
+
with2Decimals = Number(with2Decimals).toLocaleString(locale, {
|
|
34
|
+
minimumFractionDigits: 2,
|
|
35
|
+
maximumFractionDigits: 2
|
|
36
|
+
})
|
|
37
|
+
return with2Decimals
|
|
38
|
+
} catch (Exception) {
|
|
39
|
+
return val.toLocaleString(locale, {
|
|
40
|
+
minimumFractionDigits: 2,
|
|
41
|
+
maximumFractionDigits: 2
|
|
42
|
+
})
|
|
43
|
+
}
|
|
29
44
|
}
|
|
30
45
|
|
|
31
46
|
/**
|