Skip to content

Commit 18972a4

Browse files
committed
fix: bug fix
1 parent 7012a7a commit 18972a4

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/frontend/platform/src/pages/Dashboard/components/config/DimensionBlock.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ export function DimensionBlock({
101101

102102
if (currentFormat) {
103103
console.log('使用现有的 numberFormat:', currentFormat);
104+
const defaultDecimal = currentFormat.type === 'number' ? 0 : 2;
104105
setLocalFormat({
105106
type: currentFormat.type,
106-
decimalPlaces: currentFormat.decimalPlaces || 2,
107+
decimalPlaces: currentFormat.decimalPlaces ?? defaultDecimal,
107108
unit: currentFormat.unit || '',
108109
suffix: currentFormat.suffix || '',
109110
thousandSeparator: currentFormat.thousandSeparator || false
@@ -119,7 +120,7 @@ export function DimensionBlock({
119120
}
120121
: {
121122
type: 'number',
122-
decimalPlaces: 2,
123+
decimalPlaces: 0,
123124
thousandSeparator: false,
124125
unit: '',
125126
suffix: ''
@@ -425,11 +426,15 @@ export function DimensionBlock({
425426
newUnit = localFormat.unit || '';
426427
}
427428

429+
// 切换类型时,数值一律 0,小数位其他类型一律 2,互不影响
430+
const newDecimalPlaces = newType === 'number' ? 0 : 2;
431+
428432
setLocalFormat({
429433
...localFormat,
430434
type: newType,
431435
unit: newUnit,
432-
thousandSeparator: newThousandSeparator
436+
thousandSeparator: newThousandSeparator,
437+
decimalPlaces: newDecimalPlaces
433438
})
434439
}}
435440
className="flex gap-6"
@@ -482,7 +487,8 @@ export function DimensionBlock({
482487
onBlur={(e) => {
483488
const val = e.target.value;
484489
if (val === '' || isNaN(Number(val))) {
485-
setLocalFormat({ ...localFormat, decimalPlaces: 2 })
490+
const defaultDecimal = localFormat.type === 'number' ? 0 : 2;
491+
setLocalFormat({ ...localFormat, decimalPlaces: defaultDecimal })
486492
}
487493
}}
488494
className="w-full"

0 commit comments

Comments
 (0)