n20-common-lib 3.3.19 → 3.3.21
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/package.json +1 -1
- package/src/components/InputNumber/index.vue +38 -23
- package/src/i18n.json +557 -413
package/package.json
CHANGED
|
@@ -161,7 +161,7 @@ export default {
|
|
|
161
161
|
watch: {
|
|
162
162
|
value: {
|
|
163
163
|
handler(val) {
|
|
164
|
-
if (this.isHighPrecision()) {
|
|
164
|
+
if (this.isHighPrecision() || this.isAdaptivePrecision()) {
|
|
165
165
|
if (val === undefined || val === null || val === '') {
|
|
166
166
|
this.valueStr = ''
|
|
167
167
|
} else {
|
|
@@ -230,18 +230,11 @@ export default {
|
|
|
230
230
|
|
|
231
231
|
const decimalPart = normalized.split('.')[1] || ''
|
|
232
232
|
if (this.isAdaptivePrecision()) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (decimalPlaces < this.fNum) {
|
|
239
|
-
return decimalToFixed(normalized, this.fNum)
|
|
240
|
-
}
|
|
241
|
-
if (decimalPlaces > this.maxDecimalPlaces()) {
|
|
242
|
-
return decimalToFixed(normalized, this.maxDecimalPlaces())
|
|
243
|
-
}
|
|
244
|
-
return decimalToFixed(normalized, decimalPlaces)
|
|
233
|
+
// 先按最大位数舍入,再移除无意义尾零,最后补齐 format 指定的最少位数。
|
|
234
|
+
// 舍入后重新规范化,避免进位产生的尾零被保留为额外的小数精度。
|
|
235
|
+
const roundedValue = normalizeDecimal(decimalToFixed(normalized, this.maxDecimalPlaces()))
|
|
236
|
+
const decimalPlaces = (roundedValue.split('.')[1] || '').length
|
|
237
|
+
return decimalToFixed(roundedValue, Math.max(this.fNum, decimalPlaces))
|
|
245
238
|
}
|
|
246
239
|
const roundedValue = this.rangeAuto && decimalPart.length >= this.fNum
|
|
247
240
|
? normalized
|
|
@@ -269,7 +262,7 @@ export default {
|
|
|
269
262
|
},
|
|
270
263
|
stepFn(ev) {
|
|
271
264
|
if ((ev.code === 'ArrowUp' || ev.code === 'ArrowDown') && !this.disabled) {
|
|
272
|
-
if (this.isHighPrecision()) {
|
|
265
|
+
if (this.isHighPrecision() || this.isAdaptivePrecision()) {
|
|
273
266
|
const currentValue = normalizeDecimal(this.valueStr)
|
|
274
267
|
if (!currentValue) return
|
|
275
268
|
|
|
@@ -320,7 +313,7 @@ export default {
|
|
|
320
313
|
this.changeIng = false
|
|
321
314
|
})
|
|
322
315
|
|
|
323
|
-
if (this.isHighPrecision()) {
|
|
316
|
+
if (this.isHighPrecision() || this.isAdaptivePrecision()) {
|
|
324
317
|
const normalized = normalizeDecimal(valStr)
|
|
325
318
|
if (!normalized) {
|
|
326
319
|
this.valueStr = ''
|
|
@@ -336,6 +329,14 @@ export default {
|
|
|
336
329
|
|
|
337
330
|
let nextValue = this.normalizeHighPrecisionValue(valStr)
|
|
338
331
|
|
|
332
|
+
// 低精度纯数字输入沿用严格步长校正;高精度字符串仍保持原有处理方式。
|
|
333
|
+
if (!this.isHighPrecision() && this.type === 'number' && this.stepStrictly) {
|
|
334
|
+
const numericValue = N(normalized)
|
|
335
|
+
if (numericValue % this.step !== 0) {
|
|
336
|
+
nextValue = N.toString(Math.round(numericValue / this.step) * this.step)
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
339
340
|
if (compareDecimal(nextValue, this.min) < 0) {
|
|
340
341
|
nextValue = normalizeDecimal(this.min)
|
|
341
342
|
} else if (compareDecimal(nextValue, this.max) > 0) {
|
|
@@ -346,15 +347,29 @@ export default {
|
|
|
346
347
|
|
|
347
348
|
const formatted = this.type === 'number' ? nextValue : N.addThousands(nextValue)
|
|
348
349
|
this.valueStr = formatted
|
|
349
|
-
this
|
|
350
|
-
const
|
|
351
|
-
const
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
this.$emit('
|
|
355
|
-
this.dispatch('ElFormItem', 'el.form.change', [nextValue])
|
|
350
|
+
if (this.isAdaptivePrecision()) {
|
|
351
|
+
const emittedValue = this.shouldEmitString() ? nextValue : Number(nextValue)
|
|
352
|
+
const valueChanged = normalizeDecimal(this.value) !== normalizeDecimal(nextValue)
|
|
353
|
+
// 格式变化也同步 v-model,并在 blur 前回传,避免显示已补零但提交值仍带多余尾零。
|
|
354
|
+
if (this.value !== emittedValue) {
|
|
355
|
+
this.$emit('input', emittedValue)
|
|
356
356
|
}
|
|
357
|
-
|
|
357
|
+
// 仅规范化尾零不算数值变化,避免重复触发业务 change 和表单校验。
|
|
358
|
+
if (valueChanged) {
|
|
359
|
+
this.$emit('change', emittedValue)
|
|
360
|
+
this.dispatch('ElFormItem', 'el.form.change', [emittedValue])
|
|
361
|
+
}
|
|
362
|
+
} else {
|
|
363
|
+
this.$nextTick(() => {
|
|
364
|
+
const oldValue = normalizeDecimal(this.value)
|
|
365
|
+
const normalizedNextValue = normalizeDecimal(nextValue)
|
|
366
|
+
if (oldValue !== normalizedNextValue) {
|
|
367
|
+
this.$emit('input', nextValue)
|
|
368
|
+
this.$emit('change', nextValue)
|
|
369
|
+
this.dispatch('ElFormItem', 'el.form.change', [nextValue])
|
|
370
|
+
}
|
|
371
|
+
})
|
|
372
|
+
}
|
|
358
373
|
return
|
|
359
374
|
}
|
|
360
375
|
|