n20-common-lib 2.22.80 → 2.22.81
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
CHANGED
|
@@ -228,24 +228,18 @@ export default {
|
|
|
228
228
|
formatStringValue(value, originalValue = value) {
|
|
229
229
|
const decimal = parseDecimal(value)
|
|
230
230
|
if (!decimal) return ''
|
|
231
|
-
|
|
231
|
+
if (this.isAdaptivePrecision()) {
|
|
232
|
+
// 与 3.0 自动补零规则一致:先按最大位数舍入,再去除多余尾零并补齐最少位数。
|
|
233
|
+
const rounded = decimal.toDecimalPlaces(this.maxDecimalPlaces())
|
|
234
|
+
const places = Math.max(this.fNum, rounded.decimalPlaces())
|
|
235
|
+
return rounded.isZero() ? new Decimal(0).toFixed(places) : rounded.toFixed(places)
|
|
236
|
+
}
|
|
237
|
+
// 其他字符串模式沿用原有规则,rangeAuto 保留原始小数长度参与格式化。
|
|
232
238
|
const fraction = String(originalValue).replace(/,/g, '').trim().match(/\.(\d+)$/)
|
|
233
239
|
const originalPlaces = Math.max(decimal.decimalPlaces(), fraction ? fraction[1].length : 0)
|
|
234
|
-
const places = this.rangeAuto
|
|
235
|
-
? Math.max(
|
|
236
|
-
this.fNum,
|
|
237
|
-
this.isAdaptivePrecision() ? Math.min(originalPlaces, this.maxDecimalPlaces()) : originalPlaces
|
|
238
|
-
)
|
|
239
|
-
: this.fNum
|
|
240
|
+
const places = this.rangeAuto ? Math.max(this.fNum, originalPlaces) : this.fNum
|
|
240
241
|
// 先按目标位数四舍五入,避免转成 Number 后丢失精度。
|
|
241
242
|
const fixedValue = decimal.toDecimalPlaces(places).toFixed(places)
|
|
242
|
-
// format + dNum + rangeAuto 场景中,format 是最少位数,dNum 是最多位数。
|
|
243
|
-
// 保留补齐后的尾零,使回显和用户输入的小数位一致。
|
|
244
|
-
if (this.isAdaptivePrecision()) {
|
|
245
|
-
return decimal.toDecimalPlaces(places).isZero()
|
|
246
|
-
? new Decimal(0).toFixed(places)
|
|
247
|
-
: fixedValue
|
|
248
|
-
}
|
|
249
243
|
// 其他高精度场景保留当前分支的规范化逻辑:移除尾部 0。
|
|
250
244
|
const trimmedValue = fixedValue
|
|
251
245
|
.replace(/(\.\d*?[1-9])0+$/, '$1')
|
|
@@ -274,6 +268,21 @@ export default {
|
|
|
274
268
|
const decimal = parseDecimal(valStr)
|
|
275
269
|
const value = decimal ? this.formatStringValue(this.constrainStringValue(decimal, this.stepStrictly), valStr) : undefined
|
|
276
270
|
this.setStringDisplay(value)
|
|
271
|
+
if (this.isAdaptivePrecision()) {
|
|
272
|
+
const previousDecimal = parseDecimal(this.value)
|
|
273
|
+
const nextDecimal = parseDecimal(value)
|
|
274
|
+
const valueChanged = previousDecimal && nextDecimal
|
|
275
|
+
? !previousDecimal.eq(nextDecimal)
|
|
276
|
+
: this.value !== value
|
|
277
|
+
// 格式变化也在 blur 前同步绑定值,避免显示已归一化而提交值仍保留原始尾零。
|
|
278
|
+
if (this.value !== value) this.$emit('input', value)
|
|
279
|
+
// 仅补零或裁剪尾零不触发业务 change;数值比较仍使用本分支的 Decimal。
|
|
280
|
+
if (valueChanged) {
|
|
281
|
+
this.$emit('change', value)
|
|
282
|
+
this.dispatch('ElFormItem', 'el.form.change', [value])
|
|
283
|
+
}
|
|
284
|
+
return
|
|
285
|
+
}
|
|
277
286
|
this.$nextTick(() => {
|
|
278
287
|
if (this.value !== value) {
|
|
279
288
|
this.$emit('input', value)
|