@tagplus/components 4.8.5 → 4.9.1
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 +5 -5
- 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/Autosuggest/Autosuggest.vue +4 -2
- package/src/components/Loader/Loader.vue +9 -1
- package/src/components/Money/Money.vue +13 -3
- package/src/components/Multisuggest/Multisuggest.vue +19 -0
- package/src/components/Percent/Percent.vue +1 -1
- package/src/mixins/floatFormatter.js +78 -6
package/package.json
CHANGED
|
@@ -538,10 +538,12 @@ export default {
|
|
|
538
538
|
|
|
539
539
|
if (option) return option
|
|
540
540
|
|
|
541
|
-
const
|
|
541
|
+
const possuiValor = !isObject && !isNull && !isUndefined
|
|
542
|
+
const label = value
|
|
543
|
+
|
|
542
544
|
const newOption = {
|
|
543
545
|
value,
|
|
544
|
-
currentLabel: this.modifiedLabel || label
|
|
546
|
+
currentLabel: possuiValor ? this.modifiedLabel || label : ''
|
|
545
547
|
}
|
|
546
548
|
|
|
547
549
|
if (this.multiple) {
|
|
@@ -183,6 +183,13 @@ $numIcons: 8;
|
|
|
183
183
|
right: 0;
|
|
184
184
|
bottom: 0;
|
|
185
185
|
z-index: 5000;
|
|
186
|
+
transition: all ease-in-out 300ms;
|
|
187
|
+
|
|
188
|
+
&.hidden {
|
|
189
|
+
opacity: 0;
|
|
190
|
+
z-index: -10;
|
|
191
|
+
display: none;
|
|
192
|
+
}
|
|
186
193
|
|
|
187
194
|
> .overlay {
|
|
188
195
|
position: absolute;
|
|
@@ -193,7 +200,8 @@ $numIcons: 8;
|
|
|
193
200
|
left: 0;
|
|
194
201
|
right: 0;
|
|
195
202
|
background-color: #fff;
|
|
196
|
-
|
|
203
|
+
border-radius: 8px 0 0 8px;
|
|
204
|
+
opacity: 0.5;
|
|
197
205
|
}
|
|
198
206
|
.wrapper {
|
|
199
207
|
text-align: center;
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
<el-input
|
|
3
3
|
:id="`${_id}`"
|
|
4
4
|
class="tp-money"
|
|
5
|
-
:value="formattedValue"
|
|
5
|
+
:value="isTyping ? rawValue : formattedValue"
|
|
6
6
|
v-bind="$attrs"
|
|
7
7
|
:maxlength="maxlength"
|
|
8
|
-
@input="
|
|
8
|
+
@input="handleInputMoney"
|
|
9
9
|
@change="handleChange"
|
|
10
|
-
@focus="
|
|
10
|
+
@focus="handleFocus"
|
|
11
|
+
@blur="handleBlur"
|
|
11
12
|
>
|
|
12
13
|
<template
|
|
13
14
|
v-if="!removePrepend"
|
|
@@ -25,6 +26,14 @@
|
|
|
25
26
|
v-bind="scope"
|
|
26
27
|
/>
|
|
27
28
|
</template>
|
|
29
|
+
|
|
30
|
+
<template
|
|
31
|
+
slot="append"
|
|
32
|
+
>
|
|
33
|
+
<slot
|
|
34
|
+
name="append"
|
|
35
|
+
/>
|
|
36
|
+
</template>
|
|
28
37
|
</el-input>
|
|
29
38
|
</template>
|
|
30
39
|
|
|
@@ -36,6 +45,7 @@ export default {
|
|
|
36
45
|
name: 'TpMoney',
|
|
37
46
|
|
|
38
47
|
mixins: [Locale, floatFormatterMixin],
|
|
48
|
+
|
|
39
49
|
props: {
|
|
40
50
|
id: {
|
|
41
51
|
type: String,
|
|
@@ -731,6 +731,25 @@ export default {
|
|
|
731
731
|
}
|
|
732
732
|
},
|
|
733
733
|
|
|
734
|
+
/**
|
|
735
|
+
* Sobrescreve função do select para apagar a query após a seleção de um item
|
|
736
|
+
* Link para a função original: https://github.com/ElemeFE/element/blob/c345bb453bf11badb4831a6a3f600c9372b3a336/packages/select/src/select.vue#L685
|
|
737
|
+
* Manipula a seleção de uma opção em Multisuggest.
|
|
738
|
+
* @param {Object} option - A opção selecionada.
|
|
739
|
+
* @param {boolean} byClick - Indica se a seleção foi feita por clique.
|
|
740
|
+
* Se o componente permite múltiplas seleções (this.multiple):
|
|
741
|
+
* - Clona o valor atual (this.value) e obtém o index da opção selecionada.
|
|
742
|
+
* - Se a opção já estiver selecionada, a remove das opções selecionadas.
|
|
743
|
+
* - Se a opção não estiver selecionada e o limite de múltiplas seleções não foi atingido, adiciona a opções selecionadas.
|
|
744
|
+
* - Emite o evento 'input' com o novo valor e chama emitChange.
|
|
745
|
+
* - Limpa a query e, se a opção foi criada, redefine a query e o comprimento do input.
|
|
746
|
+
* - Se o componente for filtrável, foca no input.
|
|
747
|
+
* Se o componente não permite múltiplas seleções:
|
|
748
|
+
* - Emite o evento 'input' com o valor da opção e chama emitChange.
|
|
749
|
+
* - Define a visibilidade como falsa.
|
|
750
|
+
* Define isSilentBlur com base no parâmetro byClick e chama setSoftFocus.
|
|
751
|
+
* Se o componente não estiver visível, rola até a opção selecionada no próximo tick.
|
|
752
|
+
*/
|
|
734
753
|
handleOptionSelect (option, byClick) {
|
|
735
754
|
if (this.multiple) {
|
|
736
755
|
const value = (this.value || []).slice()
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { formatMoney } from 'tp-ui/utils/currency'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Mixin para formatar valores float.
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
7
7
|
data () {
|
|
8
8
|
return {
|
|
9
|
-
formattedValue: this.value
|
|
9
|
+
formattedValue: this.value,
|
|
10
|
+
isTyping: false,
|
|
11
|
+
rawValue: ''
|
|
10
12
|
}
|
|
11
13
|
},
|
|
12
14
|
|
|
@@ -15,7 +17,6 @@ export default {
|
|
|
15
17
|
type: Boolean,
|
|
16
18
|
default: false
|
|
17
19
|
},
|
|
18
|
-
|
|
19
20
|
customPrecision: {
|
|
20
21
|
default: false
|
|
21
22
|
}
|
|
@@ -38,16 +39,87 @@ export default {
|
|
|
38
39
|
},
|
|
39
40
|
|
|
40
41
|
methods: {
|
|
41
|
-
|
|
42
|
+
inputPercent (evt) {
|
|
42
43
|
this.formattedValue = formatMoney(evt, true, this.locale, this.customPrecision)
|
|
43
44
|
const moneyFormatado = formatMoney(evt, false, this.locale, this.customPrecision)
|
|
44
45
|
|
|
45
46
|
this.$emit('input', moneyFormatado)
|
|
46
47
|
},
|
|
47
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Converte o valor de entrada para float.
|
|
51
|
+
* @param {string} value - O valor de entrada.
|
|
52
|
+
* @returns {number} O valor float convertido.
|
|
53
|
+
*/
|
|
54
|
+
parseValue (value) {
|
|
55
|
+
if (!value) return 0
|
|
56
|
+
const parts = value.split(',')
|
|
57
|
+
if (parts.length > 1) {
|
|
58
|
+
const precision = this.customPrecision !== false ? this.customPrecision : 2
|
|
59
|
+
parts[1] = parts[1].slice(0, precision)
|
|
60
|
+
}
|
|
61
|
+
return parseFloat(parts.join('.')) || 0
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Manipula o valor de entrada sanitizando-o, limitando a precisão decimal e emitindo o número analisado.
|
|
66
|
+
*
|
|
67
|
+
* Esta função executa os seguintes passos:
|
|
68
|
+
* 1. Remove todos os caracteres do valor de entrada que não são dígitos ou a primeira vírgula.
|
|
69
|
+
* 2. Garante que há no máximo uma vírgula no valor sanitizado.
|
|
70
|
+
* 3. Divide o valor sanitizado em partes inteiras e fracionárias com base na vírgula.
|
|
71
|
+
* 4. Limita a parte fracionária a uma precisão especificada (o padrão é 2 se `customPrecision` não estiver definido).
|
|
72
|
+
* 5. Junta as partes inteiras e fracionárias novamente e atualiza `rawValue`.
|
|
73
|
+
* 6. Converte o `rawValue` para um número float e o emite usando o evento `input`.
|
|
74
|
+
*
|
|
75
|
+
* @param {string} value - O valor de entrada a ser manipulado.
|
|
76
|
+
* @emits input - Emite o valor numérico analisado.
|
|
77
|
+
*/
|
|
78
|
+
handleInputMoney (value) {
|
|
79
|
+
// remove todos os caracteres que não são números ou a primeira vírgula
|
|
80
|
+
const sanitized = value.replace(/[^\d,]/g, '')
|
|
81
|
+
const commaCount = (sanitized.match(/,/g) || []).length
|
|
82
|
+
|
|
83
|
+
if (commaCount > 1) return
|
|
84
|
+
|
|
85
|
+
const parts = sanitized.split(',')
|
|
86
|
+
if (parts.length > 1) {
|
|
87
|
+
const precision = this.customPrecision !== false ? this.customPrecision : 2
|
|
88
|
+
parts[1] = parts[1].slice(0, precision)
|
|
89
|
+
this.rawValue = parts.join(',')
|
|
90
|
+
} else {
|
|
91
|
+
this.rawValue = sanitized
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const numberValue = this.parseValue(this.rawValue)
|
|
95
|
+
this.$emit('input', numberValue)
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Ao focar o input, o valor existente é selecionado e
|
|
100
|
+
* caso o usuário comece a digitar, o valor é substituído.
|
|
101
|
+
* @param {Event} event - O evento de foco.
|
|
102
|
+
*/
|
|
103
|
+
handleFocus (event) {
|
|
104
|
+
this.isTyping = true
|
|
105
|
+
this.rawValue = this.formattedValue
|
|
106
|
+
event.target.select()
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Função responsável por formatar o valor de acordo com a locale
|
|
111
|
+
* e emitir o valor convertido, após o usuário sair do input.
|
|
112
|
+
*/
|
|
113
|
+
handleBlur () {
|
|
114
|
+
this.isTyping = false
|
|
115
|
+
const value = this.parseValue(this.rawValue)
|
|
116
|
+
this.formattedValue = formatMoney(value, true, this.locale, this.customPrecision)
|
|
117
|
+
this.$emit('input', value)
|
|
118
|
+
},
|
|
119
|
+
|
|
48
120
|
handleChange (evt) {
|
|
49
|
-
|
|
121
|
+
const value = this.parseValue(evt)
|
|
122
|
+
this.$emit('change', value)
|
|
50
123
|
}
|
|
51
124
|
}
|
|
52
|
-
|
|
53
125
|
}
|