@tagplus/components 4.7.12 → 5.1.0
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 +2 -1
- package/dist/tp.common.js.LICENSE.txt +9 -0
- package/dist/tp.common.js.map +1 -1
- package/dist/tp.common.lang-tp-en-js.js +2 -0
- package/dist/tp.common.lang-tp-en-js.js.map +1 -0
- package/dist/tp.css +11 -167
- package/dist/tp.umd.js +2 -1
- package/dist/tp.umd.js.LICENSE.txt +9 -0
- package/dist/tp.umd.js.map +1 -1
- package/dist/tp.umd.lang-tp-en-js.js +2 -0
- package/dist/tp.umd.lang-tp-en-js.js.map +1 -0
- package/dist/tp.umd.min.js +2 -1
- package/dist/tp.umd.min.js.LICENSE.txt +9 -0
- package/dist/tp.umd.min.js.map +1 -1
- package/dist/tp.umd.min.lang-tp-en-js.js +2 -0
- package/dist/tp.umd.min.lang-tp-en-js.js.map +1 -0
- package/package.json +51 -50
- package/src/assets/scss/_fonts.scss +24 -23
- package/src/assets/scss/_helpers.scss +4 -0
- package/src/assets/scss/_mixins.scss +2 -2
- package/src/assets/scss/_overrides.scss +5 -52
- package/src/assets/scss/_resass.scss +21 -12
- package/src/assets/scss/_variables.scss +0 -1
- package/src/assets/scss/index.scss +1 -4
- package/src/components/Autosuggest/Autosuggest.vue +340 -767
- package/src/components/Autosuggest/Multisuggest.vue +22 -0
- package/src/components/Autosuggest/autosuggest-props.js +210 -0
- package/src/components/Autosuggest/autosuggest-style.scss +127 -0
- package/src/components/Autosuggest/core.js +63 -0
- package/src/components/Autosuggest/index.js +2 -0
- package/src/components/Autosuggest/multisuggest-props.js +9 -0
- package/src/components/Autosuggest/option.vue +136 -0
- package/src/components/Autosuggest/select-dropdown.vue +64 -0
- package/src/components/Autosuggest/useOption.js +120 -0
- package/src/components/Autosuggest/useSelect.js +1133 -0
- package/src/components/AutosuggestTest.vue +56 -0
- package/src/components/CardExemplo.vue +49 -0
- package/src/components/CodeSample.vue +78 -0
- package/src/components/Inline/Inline.vue +24 -32
- package/src/components/InputNumber/InputNumber.vue +329 -378
- package/src/components/InputNumber/input-number.js +135 -0
- package/src/components/Loader/Loader.vue +42 -53
- package/src/components/Loader/animations.scss +13 -0
- package/src/components/Money/Money.vue +11 -20
- package/src/components/Multisuggest/index.js +2 -3
- package/src/components/MultisuggestTest.vue +56 -0
- package/src/components/OptionsList/OptionsList.vue +7 -6
- package/src/components/OptionsListItem/OptionsListItem.vue +46 -42
- package/src/components/Percent/Percent.vue +8 -14
- package/src/components/Skeleton/Skeleton.vue +16 -11
- package/src/components/Step/Step.vue +42 -35
- package/src/components/Steps/Steps.vue +4 -7
- package/src/components/TesteToCurrency.vue +171 -0
- package/src/components/Tip/Tip.vue +45 -30
- package/src/components/ValueSelector.vue +60 -0
- package/src/components/autosuggestMixin.js +301 -0
- package/src/components/index.js +4 -1
- package/src/locale/i18n.js +162 -0
- package/src/locale/lang/en.js +3 -2
- package/src/locale/lang/pt-br.js +3 -2
- package/src/main.js +8 -14
- package/src/mixins/floatFormatter.js +12 -16
- package/src/plugins/currency.js +100 -0
- package/src/utils/browser.js +6 -0
- package/src/utils/constants.js +3 -0
- package/src/utils/error.js +22 -0
- package/src/utils/filters.js +1 -14
- package/src/utils/helpers.js +41 -0
- package/src/utils/i18n.js +2 -0
- package/src/utils/icon.js +35 -0
- package/src/utils/index.js +20 -0
- package/src/utils/objects.js +17 -0
- package/src/utils/runtime.js +86 -0
- package/src/utils/scroll.js +100 -0
- package/src/utils/strings.js +17 -0
- package/src/utils/style.js +80 -0
- package/src/utils/types.js +39 -0
- package/src/utils/use-derived-namespace.js +112 -0
- package/src/utils/use-form-common-props.js +41 -0
- package/src/utils/use-form-item.js +80 -0
- package/src/utils/use-id.js +40 -0
- package/src/utils/use-input.js +33 -0
- package/src/components/Dialog/Dialog.vue +0 -253
- package/src/components/Dialog/index.js +0 -3
- package/src/components/Multisuggest/Multisuggest.vue +0 -858
- package/src/locale/index.js +0 -78
- package/src/mixins/locale.js +0 -9
- package/src/utils/currency.js +0 -180
|
@@ -1,46 +1,60 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div
|
|
3
3
|
:class="[
|
|
4
|
-
|
|
5
|
-
inputNumberSize
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
ns.b(),
|
|
5
|
+
ns.m(inputNumberSize),
|
|
6
|
+
ns.is('disabled', inputNumberDisabled),
|
|
7
|
+
ns.is('without-controls', !controls),
|
|
8
|
+
ns.is('controls-right', controlsAtRight),
|
|
9
9
|
]"
|
|
10
10
|
@dragstart.prevent
|
|
11
11
|
>
|
|
12
12
|
<span
|
|
13
13
|
v-if="controls"
|
|
14
14
|
v-repeat-click="decrease"
|
|
15
|
-
class="el-input-number__decrease"
|
|
16
15
|
role="button"
|
|
17
|
-
:
|
|
16
|
+
:aria-label="t('el.inputNumber.decrease')"
|
|
17
|
+
:class="[ns.e('decrease'), ns.is('disabled', minDisabled)]"
|
|
18
18
|
@keydown.enter="decrease"
|
|
19
19
|
>
|
|
20
|
-
<
|
|
20
|
+
<el-icon>
|
|
21
|
+
<arrow-down v-if="controlsAtRight" />
|
|
22
|
+
<minus v-else />
|
|
23
|
+
</el-icon>
|
|
21
24
|
</span>
|
|
22
25
|
<span
|
|
23
26
|
v-if="controls"
|
|
24
27
|
v-repeat-click="increase"
|
|
25
|
-
class="el-input-number__increase"
|
|
26
28
|
role="button"
|
|
27
|
-
:
|
|
29
|
+
:aria-label="t('el.inputNumber.increase')"
|
|
30
|
+
:class="[ns.e('increase'), ns.is('disabled', maxDisabled)]"
|
|
28
31
|
@keydown.enter="increase"
|
|
29
32
|
>
|
|
30
|
-
<
|
|
33
|
+
<el-icon>
|
|
34
|
+
<arrow-up v-if="controlsAtRight" />
|
|
35
|
+
<plus v-else />
|
|
36
|
+
</el-icon>
|
|
31
37
|
</span>
|
|
32
38
|
<el-input
|
|
39
|
+
:id="id"
|
|
33
40
|
ref="input"
|
|
34
|
-
:
|
|
41
|
+
:key="key"
|
|
42
|
+
:step="step"
|
|
43
|
+
:model-value="displayValue"
|
|
44
|
+
:formatter="displayFormatter"
|
|
45
|
+
:parser="inputParser"
|
|
35
46
|
:placeholder="placeholder"
|
|
47
|
+
:readonly="readonly"
|
|
36
48
|
:disabled="inputNumberDisabled"
|
|
37
49
|
:size="inputNumberSize"
|
|
38
50
|
:max="max"
|
|
39
51
|
:min="min"
|
|
40
52
|
:name="name"
|
|
41
53
|
:label="label"
|
|
42
|
-
|
|
43
|
-
@
|
|
54
|
+
:validate-event="false"
|
|
55
|
+
@wheel.prevent
|
|
56
|
+
@keydown.up.prevent="increase"
|
|
57
|
+
@keydown.down.prevent="decrease"
|
|
44
58
|
@blur="handleBlur"
|
|
45
59
|
@focus="handleFocus"
|
|
46
60
|
@input="handleInput"
|
|
@@ -48,383 +62,320 @@
|
|
|
48
62
|
/>
|
|
49
63
|
</div>
|
|
50
64
|
</template>
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
import
|
|
54
|
-
import
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
65
|
+
<script setup>
|
|
66
|
+
import { computed, onMounted, onUpdated, reactive, ref, watch, getCurrentInstance } from 'vue'
|
|
67
|
+
import { isNil } from 'lodash-unified'
|
|
68
|
+
import {
|
|
69
|
+
useFormDisabled,
|
|
70
|
+
useFormItem,
|
|
71
|
+
useFormSize,
|
|
72
|
+
debugWarn,
|
|
73
|
+
isNumber,
|
|
74
|
+
isString,
|
|
75
|
+
isUndefined,
|
|
76
|
+
throwError,
|
|
77
|
+
} from '@/utils'
|
|
78
|
+
import { vRepeatClick } from 'element-plus'
|
|
79
|
+
import { useLocale, useNamespace } from 'element-plus/es/hooks/index'
|
|
80
|
+
import { ArrowDown, ArrowUp, Minus, Plus } from '@element-plus/icons-vue'
|
|
81
|
+
import { inputNumberEmits, inputNumberProps } from '@/components/InputNumber/input-number'
|
|
82
|
+
const props = defineProps(inputNumberProps)
|
|
83
|
+
const emit = defineEmits(inputNumberEmits)
|
|
84
|
+
const UPDATE_MODEL_EVENT = 'update:modelValue'
|
|
85
|
+
const CHANGE_EVENT = 'change'
|
|
86
|
+
const INPUT_EVENT = 'input'
|
|
87
|
+
|
|
88
|
+
defineOptions({
|
|
58
89
|
name: 'TpInputNumber',
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
const { t } = useLocale()
|
|
93
|
+
const ns = useNamespace('input-number')
|
|
94
|
+
const input = ref()
|
|
95
|
+
const vm = getCurrentInstance().proxy
|
|
96
|
+
const key = ref(1)
|
|
97
|
+
|
|
98
|
+
// eslint-disable-next-line vue/no-setup-props-destructure
|
|
99
|
+
const data = reactive({
|
|
100
|
+
currentValue: props.modelValue,
|
|
101
|
+
userInput: null,
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
const { formItem } = useFormItem()
|
|
105
|
+
|
|
106
|
+
const minDisabled = computed(
|
|
107
|
+
() => isNumber(props.modelValue) && props.modelValue <= props.min
|
|
108
|
+
)
|
|
109
|
+
const maxDisabled = computed(
|
|
110
|
+
() => isNumber(props.modelValue) && props.modelValue >= props.max
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
const numPrecision = computed(() => {
|
|
114
|
+
const stepPrecision = getPrecision(props.step)
|
|
115
|
+
if (!isUndefined(props.precision)) {
|
|
116
|
+
if (stepPrecision > props.precision) {
|
|
117
|
+
debugWarn(
|
|
118
|
+
'InputNumber',
|
|
119
|
+
'precision should not be less than the decimal places of step'
|
|
120
|
+
)
|
|
75
121
|
}
|
|
76
|
-
|
|
122
|
+
return props.precision
|
|
123
|
+
} else {
|
|
124
|
+
return Math.max(getPrecision(props.modelValue), stepPrecision)
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
const controlsAtRight = computed(() => {
|
|
128
|
+
return props.controls && props.controlsPosition === 'right'
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
const inputNumberSize = useFormSize()
|
|
132
|
+
const inputNumberDisabled = useFormDisabled()
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @tagplus
|
|
136
|
+
* Modificado para permitir um valor padrão vazio ou 0 de acordo com a prop
|
|
137
|
+
*/
|
|
138
|
+
const displayValue = computed(() => {
|
|
139
|
+
if (data.userInput !== null) {
|
|
140
|
+
return data.userInput
|
|
141
|
+
}
|
|
142
|
+
let currentValue = data.currentValue
|
|
77
143
|
|
|
78
|
-
props:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
},
|
|
83
|
-
stepStrictly: {
|
|
84
|
-
type: Boolean,
|
|
85
|
-
default: false
|
|
86
|
-
},
|
|
87
|
-
max: {
|
|
88
|
-
type: Number,
|
|
89
|
-
default: Infinity
|
|
90
|
-
},
|
|
91
|
-
min: {
|
|
92
|
-
type: Number,
|
|
93
|
-
default: -Infinity
|
|
94
|
-
},
|
|
95
|
-
value: {
|
|
96
|
-
type: [Number, String],
|
|
97
|
-
default: null
|
|
98
|
-
},
|
|
99
|
-
disabled: Boolean,
|
|
100
|
-
size: {
|
|
101
|
-
type: [String, Boolean],
|
|
102
|
-
default: false
|
|
103
|
-
},
|
|
104
|
-
controls: {
|
|
105
|
-
type: Boolean,
|
|
106
|
-
default: true
|
|
107
|
-
},
|
|
108
|
-
controlsPosition: {
|
|
109
|
-
type: String,
|
|
110
|
-
default: ''
|
|
111
|
-
},
|
|
112
|
-
name: {
|
|
113
|
-
type: [String, Boolean],
|
|
114
|
-
default: false
|
|
115
|
-
},
|
|
116
|
-
label: {
|
|
117
|
-
type: [String],
|
|
118
|
-
default: ''
|
|
119
|
-
},
|
|
120
|
-
placeholder: {
|
|
121
|
-
type: [String, Boolean],
|
|
122
|
-
default: false
|
|
123
|
-
},
|
|
124
|
-
precision: {
|
|
125
|
-
type: Number,
|
|
126
|
-
default: 2,
|
|
127
|
-
validator (val) {
|
|
128
|
-
return val >= 0 && val === parseInt(val, 10)
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
// Customizada
|
|
132
|
-
usarVirgula: {
|
|
133
|
-
type: Boolean,
|
|
134
|
-
default: true
|
|
135
|
-
},
|
|
136
|
-
// Customizada - Se false permite campo vazio
|
|
137
|
-
stringDefaultsZero: {
|
|
138
|
-
type: Boolean,
|
|
139
|
-
default: true
|
|
140
|
-
}
|
|
141
|
-
},
|
|
144
|
+
const fallbackValue = props.stringDefaultsZero ? 0 : ''
|
|
145
|
+
if (props.modelValue === '' || isNil(currentValue) || currentValue === ''){
|
|
146
|
+
return fallbackValue
|
|
147
|
+
}
|
|
142
148
|
|
|
143
|
-
|
|
144
|
-
return
|
|
145
|
-
|
|
146
|
-
|
|
149
|
+
if (isNumber(currentValue)) {
|
|
150
|
+
if (Number.isNaN(currentValue)) return fallbackValue
|
|
151
|
+
if (!isUndefined(props.precision)) {
|
|
152
|
+
currentValue = currentValue.toFixed(props.precision)
|
|
147
153
|
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
},
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
154
|
+
}
|
|
155
|
+
return currentValue
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @tagplus
|
|
160
|
+
* Criado para simular o comportamento do type=number porque ele não deixa
|
|
161
|
+
* exibir os valores formatados no padrão pt-br 100.555,55
|
|
162
|
+
*/
|
|
163
|
+
const displayFormatter = computed(() => {
|
|
164
|
+
const decimalChar = vm.$t('locale.number.decimal')
|
|
165
|
+
const thousandsChar = vm.$t('locale.number.thousands')
|
|
166
|
+
return (value) => {
|
|
167
|
+
// Essa linha simula o comportamento do type="number" para não deixar digitar letras
|
|
168
|
+
const noLetters = value.replaceAll(/[a-zA-Z]/g, '')
|
|
169
|
+
const res = noLetters.replace('.', decimalChar).replace(/\B(?=(\d{3})+(?!\d))/g, thousandsChar)
|
|
170
|
+
return res
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @tagplus
|
|
176
|
+
* Criado em conjunto do displayFormatter para simular o type="number"
|
|
177
|
+
* @see displayFormatter
|
|
178
|
+
*/
|
|
179
|
+
const inputParser = computed(() => {
|
|
180
|
+
const decimalChar = vm.$t('locale.number.decimal')
|
|
181
|
+
const thousandsChar = vm.$t('locale.number.thousands')
|
|
182
|
+
return (value) => {
|
|
183
|
+
const regexThou = `/\$\s?|(${thousandsChar}*)/g`
|
|
184
|
+
const res = value.replace(regexThou, '').replace(decimalChar, '.')
|
|
185
|
+
return res
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
const toPrecision = (num, pre) => {
|
|
190
|
+
// eslint-disable-next-line no-param-reassign
|
|
191
|
+
if (isUndefined(pre)) pre = numPrecision.value
|
|
192
|
+
if (pre === 0) return Math.round(num)
|
|
193
|
+
let snum = String(num)
|
|
194
|
+
const pointPos = snum.indexOf('.')
|
|
195
|
+
if (pointPos === -1) return num
|
|
196
|
+
const nums = snum.replace('.', '').split('')
|
|
197
|
+
const datum = nums[pointPos + pre]
|
|
198
|
+
if (!datum) return num
|
|
199
|
+
const length = snum.length
|
|
200
|
+
if (snum.charAt(length - 1) === '5') {
|
|
201
|
+
snum = `${snum.slice(0, Math.max(0, length - 1))}6`
|
|
202
|
+
}
|
|
203
|
+
return Number.parseFloat(Number(snum).toFixed(pre))
|
|
204
|
+
}
|
|
205
|
+
const getPrecision = (value) => {
|
|
206
|
+
if (isNil(value)) return 0
|
|
207
|
+
const valueString = value.toString()
|
|
208
|
+
const dotPosition = valueString.indexOf('.')
|
|
209
|
+
let precision = 0
|
|
210
|
+
if (dotPosition !== -1) {
|
|
211
|
+
precision = valueString.length - dotPosition - 1
|
|
212
|
+
}
|
|
213
|
+
return precision
|
|
214
|
+
}
|
|
215
|
+
const ensurePrecision = (val, coefficient = 1) => {
|
|
216
|
+
if (!isNumber(val)) return data.currentValue
|
|
217
|
+
// Solve the accuracy problem of JS decimal calculation by converting the value to integer.
|
|
218
|
+
return toPrecision(val + props.step * coefficient)
|
|
219
|
+
}
|
|
220
|
+
const increase = () => {
|
|
221
|
+
if (props.readonly || inputNumberDisabled.value || maxDisabled.value) return
|
|
222
|
+
const value = Number(displayValue.value) || 0
|
|
223
|
+
const newVal = ensurePrecision(value)
|
|
224
|
+
setCurrentValue(newVal)
|
|
225
|
+
emit(INPUT_EVENT, data.currentValue)
|
|
226
|
+
setCurrentValueToModelValue()
|
|
227
|
+
}
|
|
228
|
+
const decrease = () => {
|
|
229
|
+
if (props.readonly || inputNumberDisabled.value || minDisabled.value) return
|
|
230
|
+
const value = Number(displayValue.value) || 0
|
|
231
|
+
const newVal = ensurePrecision(value, -1)
|
|
232
|
+
setCurrentValue(newVal)
|
|
233
|
+
emit(INPUT_EVENT, data.currentValue)
|
|
234
|
+
setCurrentValueToModelValue()
|
|
235
|
+
}
|
|
236
|
+
const verifyValue = (value, update) => {
|
|
237
|
+
const { max, min, step, precision, stepStrictly, valueOnClear } = props
|
|
238
|
+
if (max < min) {
|
|
239
|
+
throwError('InputNumber', 'min should not be greater than max.')
|
|
240
|
+
}
|
|
241
|
+
let newVal = Number(value)
|
|
242
|
+
if (isNil(value) || Number.isNaN(newVal)) {
|
|
243
|
+
return null
|
|
244
|
+
}
|
|
245
|
+
if (value === '') {
|
|
246
|
+
if (valueOnClear === null) {
|
|
247
|
+
return null
|
|
233
248
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
249
|
+
newVal = isString(valueOnClear) ? { min, max }[valueOnClear] : valueOnClear
|
|
250
|
+
}
|
|
251
|
+
if (stepStrictly) {
|
|
252
|
+
newVal = toPrecision(Math.round(newVal / step) * step, precision)
|
|
253
|
+
}
|
|
254
|
+
if (!isUndefined(precision)) {
|
|
255
|
+
newVal = toPrecision(newVal, precision)
|
|
256
|
+
}
|
|
257
|
+
if (newVal > max || newVal < min) {
|
|
258
|
+
newVal = newVal > max ? max : min
|
|
259
|
+
update && emit(UPDATE_MODEL_EVENT, newVal)
|
|
260
|
+
}
|
|
261
|
+
return newVal
|
|
262
|
+
}
|
|
263
|
+
const setCurrentValue = (value, emitChange = true) => {
|
|
264
|
+
const oldVal = data.currentValue
|
|
265
|
+
const newVal = verifyValue(value)
|
|
266
|
+
if (!emitChange) {
|
|
267
|
+
emit(UPDATE_MODEL_EVENT, newVal)
|
|
268
|
+
return
|
|
269
|
+
}
|
|
270
|
+
if (oldVal === newVal) return
|
|
271
|
+
data.userInput = null
|
|
272
|
+
emit(UPDATE_MODEL_EVENT, newVal)
|
|
273
|
+
emit(CHANGE_EVENT, newVal, oldVal)
|
|
274
|
+
if (props.validateEvent) {
|
|
275
|
+
formItem?.validate?.('change').catch((err) => debugWarn(err))
|
|
276
|
+
}
|
|
277
|
+
data.currentValue = newVal
|
|
278
|
+
}
|
|
279
|
+
const handleInput = (value) => {
|
|
280
|
+
data.userInput = value
|
|
281
|
+
const newVal = value === '' ? null : Number(value)
|
|
282
|
+
emit(INPUT_EVENT, newVal)
|
|
283
|
+
setCurrentValue(newVal, false)
|
|
284
|
+
}
|
|
285
|
+
const handleInputChange = (value) => {
|
|
286
|
+
const newVal = value !== '' ? Number(value) : ''
|
|
287
|
+
if ((isNumber(newVal) && !Number.isNaN(newVal)) || value === '') {
|
|
288
|
+
setCurrentValue(newVal)
|
|
289
|
+
}
|
|
290
|
+
setCurrentValueToModelValue()
|
|
291
|
+
data.userInput = null
|
|
292
|
+
}
|
|
261
293
|
|
|
262
|
-
|
|
263
|
-
|
|
294
|
+
const focus = () => {
|
|
295
|
+
input.value?.focus?.()
|
|
296
|
+
}
|
|
264
297
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
298
|
+
const blur = () => {
|
|
299
|
+
input.value?.blur?.()
|
|
300
|
+
}
|
|
269
301
|
|
|
270
|
-
|
|
302
|
+
const handleFocus = (event) => {
|
|
303
|
+
emit('focus', event)
|
|
304
|
+
}
|
|
271
305
|
|
|
272
|
-
|
|
306
|
+
const handleBlur = (event) => {
|
|
307
|
+
data.userInput = null
|
|
308
|
+
emit('blur', event)
|
|
309
|
+
if (props.validateEvent) {
|
|
310
|
+
formItem?.validate?.('blur').catch((err) => debugWarn(err))
|
|
311
|
+
}
|
|
312
|
+
}
|
|
273
313
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
314
|
+
const setCurrentValueToModelValue = () => {
|
|
315
|
+
if (data.currentValue !== props.modelValue) {
|
|
316
|
+
data.currentValue = props.modelValue
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
watch(
|
|
320
|
+
() => props.modelValue,
|
|
321
|
+
(value, oldValue) => {
|
|
322
|
+
const newValue = verifyValue(value, true)
|
|
323
|
+
if (data.userInput === null && newValue !== oldValue) {
|
|
324
|
+
data.currentValue = newValue
|
|
278
325
|
}
|
|
279
326
|
},
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
const precisionFactor = Math.pow(10, this.numPrecision)
|
|
322
|
-
|
|
323
|
-
// Solve the accuracy problem of JS decimal calculation by converting the value to integer.
|
|
324
|
-
return this.toPrecision((precisionFactor * val + precisionFactor * step) / precisionFactor)
|
|
325
|
-
},
|
|
326
|
-
_decrease (val, step) {
|
|
327
|
-
if (typeof val !== 'number' && val !== undefined) return this.currentValue
|
|
328
|
-
|
|
329
|
-
const precisionFactor = Math.pow(10, this.numPrecision)
|
|
330
|
-
|
|
331
|
-
return this.toPrecision((precisionFactor * val - precisionFactor * step) / precisionFactor)
|
|
332
|
-
},
|
|
333
|
-
increase () {
|
|
334
|
-
if (this.inputNumberDisabled || this.maxDisabled) return
|
|
335
|
-
|
|
336
|
-
const value = this.value || 0
|
|
337
|
-
const newVal = this._increase(value, this.step)
|
|
338
|
-
|
|
339
|
-
this.setCurrentValue(newVal)
|
|
340
|
-
},
|
|
341
|
-
decrease () {
|
|
342
|
-
if (this.inputNumberDisabled || this.minDisabled) return
|
|
343
|
-
|
|
344
|
-
const value = this.value || 0
|
|
345
|
-
const newVal = this._decrease(value, this.step)
|
|
346
|
-
|
|
347
|
-
this.setCurrentValue(newVal)
|
|
348
|
-
},
|
|
349
|
-
handleBlur (event) {
|
|
350
|
-
if (!this.value && this.stringDefaultsZero && !this.precision) {
|
|
351
|
-
this.currentValue = 0
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
this.$emit('blur', event)
|
|
355
|
-
},
|
|
356
|
-
handleFocus (event) {
|
|
357
|
-
if (!this.value && !this.precision) {
|
|
358
|
-
this.currentValue = ''
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
this.$emit('focus', event)
|
|
362
|
-
},
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* Sobrescrito do element
|
|
366
|
-
*/
|
|
367
|
-
handleInput (value) {
|
|
368
|
-
this.userInput = value
|
|
369
|
-
let newVal
|
|
370
|
-
|
|
371
|
-
if (value === '' && this.stringDefaultsZero) {
|
|
372
|
-
newVal = Number(value.replace(',', '.'))
|
|
373
|
-
} else {
|
|
374
|
-
newVal = value
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
this.$emit('change', newVal)
|
|
378
|
-
},
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Sobrescrito do element
|
|
382
|
-
*/
|
|
383
|
-
handleInputChange (value) {
|
|
384
|
-
let newVal
|
|
385
|
-
|
|
386
|
-
if (value === '') {
|
|
387
|
-
// Por padrão converte '' para 0
|
|
388
|
-
if (this.stringDefaultsZero) {
|
|
389
|
-
newVal = 0
|
|
390
|
-
} else {
|
|
391
|
-
newVal = ''
|
|
392
|
-
}
|
|
393
|
-
} else {
|
|
394
|
-
newVal = Number(value.replace(',', '.'))
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
if (!isNaN(newVal) || value === '') {
|
|
398
|
-
this.setCurrentValue(newVal)
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
this.userInput = null
|
|
402
|
-
},
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* Sobrescrito do element
|
|
406
|
-
*/
|
|
407
|
-
setCurrentValue (newVal) {
|
|
408
|
-
const oldVal = this.currentValue
|
|
409
|
-
|
|
410
|
-
if (typeof newVal === 'number' && this.precision !== undefined) {
|
|
411
|
-
newVal = this.toPrecision(newVal, this.precision)
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
if (newVal >= this.max) newVal = this.max
|
|
415
|
-
|
|
416
|
-
if (newVal <= this.min) newVal = this.min
|
|
417
|
-
|
|
418
|
-
if (oldVal === newVal && newVal === this.value) return
|
|
419
|
-
|
|
420
|
-
this.userInput = null
|
|
421
|
-
this.$emit('input', newVal)
|
|
422
|
-
this.$emit('change', newVal, oldVal)
|
|
423
|
-
},
|
|
424
|
-
|
|
425
|
-
select () {
|
|
426
|
-
this.$refs.input.select()
|
|
327
|
+
{ immediate: true }
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* @tagplus
|
|
332
|
+
* Criado para observar se a lang mudou para reformatar o displayValue
|
|
333
|
+
*/
|
|
334
|
+
watch(
|
|
335
|
+
() => vm.$i18nHelper.hooks.onLanguageChanged,
|
|
336
|
+
(value, oldValue) => {
|
|
337
|
+
key.value++
|
|
338
|
+
}
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
onMounted(() => {
|
|
342
|
+
const { min, max, modelValue } = props
|
|
343
|
+
const innerInput = input.value?.input
|
|
344
|
+
innerInput.setAttribute('role', 'spinbutton')
|
|
345
|
+
if (Number.isFinite(max)) {
|
|
346
|
+
innerInput.setAttribute('aria-valuemax', String(max))
|
|
347
|
+
} else {
|
|
348
|
+
innerInput.removeAttribute('aria-valuemax')
|
|
349
|
+
}
|
|
350
|
+
if (Number.isFinite(min)) {
|
|
351
|
+
innerInput.setAttribute('aria-valuemin', String(min))
|
|
352
|
+
} else {
|
|
353
|
+
innerInput.removeAttribute('aria-valuemin')
|
|
354
|
+
}
|
|
355
|
+
innerInput.setAttribute(
|
|
356
|
+
'aria-valuenow',
|
|
357
|
+
data.currentValue || data.currentValue === 0
|
|
358
|
+
? String(data.currentValue)
|
|
359
|
+
: ''
|
|
360
|
+
)
|
|
361
|
+
innerInput.setAttribute('aria-disabled', String(inputNumberDisabled.value))
|
|
362
|
+
// eslint-disable-next-line no-eq-null, eqeqeq
|
|
363
|
+
if (!isNumber(modelValue) && modelValue != null) {
|
|
364
|
+
let val = Number(modelValue)
|
|
365
|
+
if (Number.isNaN(val)) {
|
|
366
|
+
val = null
|
|
427
367
|
}
|
|
368
|
+
emit(UPDATE_MODEL_EVENT, val)
|
|
428
369
|
}
|
|
429
|
-
}
|
|
370
|
+
})
|
|
371
|
+
onUpdated(() => {
|
|
372
|
+
const innerInput = input.value?.input
|
|
373
|
+
innerInput?.setAttribute('aria-valuenow', `${data.currentValue ?? ''}`)
|
|
374
|
+
})
|
|
375
|
+
defineExpose({
|
|
376
|
+
/** @description get focus the input component */
|
|
377
|
+
focus,
|
|
378
|
+
/** @description remove focus the input component */
|
|
379
|
+
blur,
|
|
380
|
+
})
|
|
430
381
|
</script>
|