From 67bc81d3e22a33b438edbd8982003aa4cefc1659 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 14 Sep 2025 01:17:46 +0800 Subject: [PATCH] fix user custom exchange rates update page /dialog could not be opened --- src/components/base/NumberInputBase.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/components/base/NumberInputBase.ts b/src/components/base/NumberInputBase.ts index e6b2a2fe..ba4c0a65 100644 --- a/src/components/base/NumberInputBase.ts +++ b/src/components/base/NumberInputBase.ts @@ -3,7 +3,7 @@ import { computed, watch } from 'vue'; import { useI18n } from '@/locales/helpers.ts'; import { type CommonNumberInputProps, useCommonNumberInputBase } from '@/components/base/CommonNumberInputBase.ts'; -import { isNumber, replaceAll, removeAll } from '@/lib/common.ts'; +import { isDefined, isNumber, replaceAll, removeAll } from '@/lib/common.ts'; import { NumeralSystem } from '@/core/numeral.ts'; export interface NumberInputProps extends CommonNumberInputProps { @@ -60,11 +60,11 @@ export function useNumberInputBase(props: NumberInputProps, emit: NumberInputEmi function getValidFormattedValue(value: number, textualValue: string): string { if (isNumber(props.minValue) && value < props.minValue) { - return getFormattedValue(props.minValue); + return getFormattedValue(props.minValue, numeralSystem.value); } if (isNumber(props.maxValue) && value > props.maxValue) { - return getFormattedValue(props.maxValue); + return getFormattedValue(props.maxValue, numeralSystem.value); } const decimalSeparator = getCurrentDecimalSeparator(); @@ -72,25 +72,29 @@ export function useNumberInputBase(props: NumberInputProps, emit: NumberInputEmi return replaceAll(removeAll(textualValue, digitGroupingSymbol), '.', decimalSeparator); } - function getFormattedValue(value: number): string { + function getFormattedValue(value: number, customNumeralSystem?: NumeralSystem): string { + if (!isDefined(customNumeralSystem)) { + customNumeralSystem = getCurrentNumeralSystemType(); + } + if (!Number.isNaN(value) && Number.isFinite(value)) { const decimalSeparator = getCurrentDecimalSeparator(); if (isNumber(props.maxDecimalCount) && props.maxDecimalCount >= 0) { - return replaceAll(numeralSystem.value.replaceWesternArabicDigitsToLocalizedDigits(value.toFixed(props.maxDecimalCount)), '.', decimalSeparator); + return replaceAll(customNumeralSystem.replaceWesternArabicDigitsToLocalizedDigits(value.toFixed(props.maxDecimalCount)), '.', decimalSeparator); } else { - return replaceAll(numeralSystem.value.replaceWesternArabicDigitsToLocalizedDigits(value.toString(10)), '.', decimalSeparator); + return replaceAll(customNumeralSystem.replaceWesternArabicDigitsToLocalizedDigits(value.toString(10)), '.', decimalSeparator); } } - return numeralSystem.value.digitZero; + return customNumeralSystem.digitZero; } watch(() => props.modelValue, (newValue) => { const numericCurrentValue = parseNumber(currentValue.value); if (newValue !== numericCurrentValue) { - const newStringValue = getFormattedValue(newValue); + const newStringValue = getFormattedValue(newValue, numeralSystem.value); if (!(newStringValue === numeralSystem.value.digitZero && currentValue.value === '')) { currentValue.value = newStringValue;