@tagplus/components 1.2.7 → 1.2.12
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 +3 -3
- 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 +2 -1
- package/src/components/Money/Money.vue +2 -22
- package/src/components/Multisuggest/Multisuggest.vue +25 -19
- 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
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"email": "bruno@tagplus.com.br"
|
|
9
9
|
}
|
|
10
10
|
],
|
|
11
|
-
"version": "1.2.
|
|
11
|
+
"version": "1.2.12",
|
|
12
12
|
"main": "./dist/tp.common.js",
|
|
13
13
|
"directories": {
|
|
14
14
|
"lib": "src/lib"
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"scripts": {
|
|
29
29
|
"build": "NODE_ENV=production && vue-cli-service build --target lib --name tp ./src/main.js",
|
|
30
|
+
"build:dev": "NODE_ENV=development && vue-cli-service build --mode development --target lib --name tp ./src/main.js",
|
|
30
31
|
"doc": "yarn docs",
|
|
31
32
|
"docs": "nodemon --exec \"vuese gen && vuese serve\" --watch ./src -e js,vue,scss",
|
|
32
33
|
"docs:gen": "vuese gen",
|
|
@@ -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>
|
|
@@ -448,6 +448,10 @@ export default {
|
|
|
448
448
|
return item[this.labelKey]
|
|
449
449
|
})
|
|
450
450
|
.join(', ')
|
|
451
|
+
},
|
|
452
|
+
|
|
453
|
+
suggestionsList(_newValue, _oldValue){
|
|
454
|
+
this.setSelectedLabel()
|
|
451
455
|
}
|
|
452
456
|
},
|
|
453
457
|
|
|
@@ -473,25 +477,7 @@ export default {
|
|
|
473
477
|
}
|
|
474
478
|
})
|
|
475
479
|
|
|
476
|
-
|
|
477
|
-
this.value.forEach((item, key) => {
|
|
478
|
-
if (item[this.valueKey]) {
|
|
479
|
-
this.value[key] = item[this.valueKey]
|
|
480
|
-
if (item[this.labelKey]) {
|
|
481
|
-
this.selectedLabelsArray.push(item)
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
})
|
|
485
|
-
} else if (process.env.DEBUG === 'true') {
|
|
486
|
-
console.log(`'${this.$options.name}' recebeu valor em formato inválido.`)
|
|
487
|
-
console.log(this.value)
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
this.selectedLabels = this.selectedLabelsArray
|
|
491
|
-
.map(item => {
|
|
492
|
-
return item[this.labelKey]
|
|
493
|
-
})
|
|
494
|
-
.join(', ')
|
|
480
|
+
this.setSelectedLabel()
|
|
495
481
|
},
|
|
496
482
|
|
|
497
483
|
beforeMount () {
|
|
@@ -516,6 +502,26 @@ export default {
|
|
|
516
502
|
}
|
|
517
503
|
},
|
|
518
504
|
|
|
505
|
+
setSelectedLabel () {
|
|
506
|
+
if (Array.isArray(this.value)) {
|
|
507
|
+
this.value.forEach((item, key) => {
|
|
508
|
+
this.suggestionsList.forEach(suggestion => {
|
|
509
|
+
if (suggestion[this.valueKey] === item) {
|
|
510
|
+
this.selectedLabelsArray.push(suggestion)
|
|
511
|
+
}
|
|
512
|
+
})
|
|
513
|
+
})
|
|
514
|
+
} else if (process.env.DEBUG === 'true') {
|
|
515
|
+
console.log(`'${this.$options.name}' recebeu valor em formato inválido.`)
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
this.selectedLabels = this.selectedLabelsArray
|
|
519
|
+
.map(item => {
|
|
520
|
+
return item[this.labelKey]
|
|
521
|
+
})
|
|
522
|
+
.join(', ')
|
|
523
|
+
},
|
|
524
|
+
|
|
519
525
|
// eslint-disable-next-line no-unused-vars
|
|
520
526
|
clearTags (event) {
|
|
521
527
|
// Faz uma requisição limpa
|
|
@@ -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
|
}
|