Skip to content

Commit 6c7edc6

Browse files
committed
fix:bug fix
1 parent eb1773b commit 6c7edc6

5 files changed

Lines changed: 104 additions & 36 deletions

File tree

src/frontend/platform/src/pages/Dashboard/colorSchemes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ export const getDefaultMetricStyle = (title, subtitle) => ({
530530
"subtitleFontSize": 14,
531531
"subtitleColor": "#666",
532532
"subtitleAlign": "left",
533-
"subtitleBold": false,
533+
"subtitleBold": true,
534534
"subtitleItalic": false,
535535
"subtitleUnderline": false,
536536
"metricFontSize": 28,

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ const FULL_DEFAULT_STYLE_CONFIG: ComponentStyleConfig = {
2929
bgColor: "",
3030

3131
title: "",
32-
titleFontSize: 14,
33-
titleBold: false,
32+
titleFontSize: 16,
33+
titleBold: true,
3434
titleItalic: false,
3535
titleUnderline: false,
3636
titleStrikethrough: false,
@@ -44,7 +44,7 @@ const FULL_DEFAULT_STYLE_CONFIG: ComponentStyleConfig = {
4444
xAxisUnderline: false,
4545
xAxisStrikethrough: false,
4646
xAxisAlign: "center",
47-
xAxisColor: "#000000",
47+
xAxisColor: "#666666",
4848

4949
yAxisTitle: "",
5050
yAxisFontSize: 14,
@@ -53,16 +53,16 @@ const FULL_DEFAULT_STYLE_CONFIG: ComponentStyleConfig = {
5353
yAxisUnderline: false,
5454
yAxisStrikethrough: false,
5555
yAxisAlign: "center",
56-
yAxisColor: "#000000",
56+
yAxisColor: "#666666",
5757

5858
legendPosition: "bottom",
59-
legendFontSize: 14,
59+
legendFontSize: 12,
6060
legendBold: false,
6161
legendItalic: false,
6262
legendUnderline: false,
6363
legendStrikethrough: false,
6464
legendAlign: "left",
65-
legendColor: "#000000",
65+
legendColor: "#999999",
6666

6767
showSubtitle: false,
6868
subtitle: "",
@@ -256,6 +256,7 @@ export function ComponentConfigDrawer() {
256256
originalName: field.displayName || field.fieldName,
257257
fieldType: field.role,
258258
timeGranularity: field.timeGranularity,
259+
isDivide: field.isDivide,
259260
sort: null
260261
}
261262
chartState.setCategoryDimensions(prev => [...prev, newDimension])
@@ -360,7 +361,8 @@ export function ComponentConfigDrawer() {
360361
fieldType: field.role,
361362
sort: null,
362363
aggregation: 'sum' as const,
363-
isVirtual: currentIsVirtual
364+
isVirtual: currentIsVirtual,
365+
isDivide: field.isDivide,
364366
}
365367

366368
chartState.setValueDimensions(prev => [...prev, newMetric])

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export function DatasetSelector({ selectedDatasetCode, isMetricCard, onDatasetCh
9191
fieldId: data.fieldId,
9292
fieldCode: data.fieldCode,
9393
fieldType,
94+
isDivide: data.isDivide,
9495
timeGranularity: data.timeGranularity,
9596
}
9697

@@ -121,6 +122,7 @@ export function DatasetSelector({ selectedDatasetCode, isMetricCard, onDatasetCh
121122
displayName: m.name,
122123
fieldType: m.field_type,
123124
isVirtual: m.is_virtual,
125+
isDivide: m.formula,
124126
role: "metric" as const
125127
}))
126128

@@ -278,7 +280,8 @@ export function DatasetSelector({ selectedDatasetCode, isMetricCard, onDatasetCh
278280
displayName: t(metric.field),
279281
fieldType: "number",
280282
role: "metric" as const,
281-
isVirtual: metric.is_virtual
283+
isVirtual: metric.is_virtual,
284+
isDivide: metric.formula,
282285
}
283286
return (
284287
<div

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

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client"
22

3-
import { useState } from "react"
3+
import { useEffect, useState } from "react"
44
import { Button } from "@/components/bs-ui/button"
55
import { Settings, X, Check } from "lucide-react"
66
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/bs-ui/dialog"
@@ -36,6 +36,7 @@ interface DimensionItem {
3636
isVirtual?: boolean // 补充定义
3737
fieldId?: string
3838
timeGranularity?: string
39+
isDivide?: string
3940
}
4041

4142
interface DimensionBlockProps {
@@ -91,7 +92,42 @@ export function DimensionBlock({
9192
const [formatDialogOpen, setFormatDialogOpen] = useState(false)
9293
const [localFormat, setLocalFormat] = useState<MetricFormat | null>(null)
9394
const [hoveredIcon, setHoveredIcon] = useState<string | null>(null)
94-
95+
// 监听editingMetric变化,设置默认格式
96+
useEffect(() => {
97+
if (editingMetric) {
98+
console.log('Editing metric:', editingMetric);
99+
100+
const currentFormat = editingMetric.numberFormat;
101+
102+
if (currentFormat) {
103+
console.log('使用现有的 numberFormat:', currentFormat);
104+
setLocalFormat({
105+
type: currentFormat.type,
106+
decimalPlaces: currentFormat.decimalPlaces || 2,
107+
unit: currentFormat.unit || '',
108+
suffix: currentFormat.suffix || '',
109+
thousandSeparator: currentFormat.thousandSeparator || false
110+
});
111+
} else {
112+
const defaultFormat: MetricFormat = editingMetric.isDivide === "divide"
113+
? {
114+
type: 'percent',
115+
decimalPlaces: 2,
116+
thousandSeparator: false,
117+
unit: undefined,
118+
suffix: ''
119+
}
120+
: {
121+
type: 'number',
122+
decimalPlaces: 2,
123+
thousandSeparator: false,
124+
unit: '',
125+
suffix: ''
126+
};
127+
setLocalFormat(defaultFormat);
128+
}
129+
}
130+
}, [editingMetric]);
95131
const getFieldTypeStyle = (dimension: DimensionItem) => {
96132
const isSelected = selectedDimensionId === dimension.id
97133
const bgColor = isSelected
@@ -301,15 +337,6 @@ export function DimensionBlock({
301337
<DropdownMenuItem
302338
onClick={() => {
303339
setEditingMetric(dimension)
304-
setLocalFormat(
305-
dimension.numberFormat || {
306-
type: 'number',
307-
decimalPlaces: 2,
308-
unit: '',
309-
suffix: '',
310-
thousandSeparator: false
311-
}
312-
)
313340
setFormatDialogOpen(true)
314341
}}
315342
>

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

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export function useChartState(initialComponent: DashboardComponent) {
131131
fieldType: 'metric',
132132
isVirtual: metric.isVirtual || false,
133133
aggregation: metric.aggregation || 'sum',
134+
isDivide: metric.formula,
134135
numberFormat: metric.numberFormat || {
135136
type: 'number',
136137
decimalPlaces: 2,
@@ -499,7 +500,8 @@ export function useChartState(initialComponent: DashboardComponent) {
499500
sort: null,
500501
sortPriority: 0,
501502
timeGranularity: data.timeGranularity,
502-
fieldType
503+
fieldType,
504+
isDivide: data.isDivide,
503505
}
504506

505507
if (section === 'category') {
@@ -601,23 +603,57 @@ export function useChartState(initialComponent: DashboardComponent) {
601603
timeGranularity: stackDimensions[0].timeGranularity || null
602604
} : undefined
603605

604-
const metrics = valueDimensions.map(metric => ({
605-
fieldId: metric.fieldId,
606-
fieldName: metric.originalName,
607-
fieldCode: metric.name,
608-
displayName: metric.displayName,
609-
sort: metric.sort,
610-
isVirtual: metric.isVirtual,
611-
aggregation: metric.aggregation || 'sum',
612-
numberFormat: metric.numberFormat || {
613-
type: 'number' as const,
614-
decimalPlaces: 2,
615-
unit: undefined,
616-
suffix: undefined,
617-
thousandSeparator: true
606+
const metrics = valueDimensions.map(metric => {
607+
let numberFormat;
608+
if (metric.isDivide === "divide") {
609+
console.log('检测到除法指标:', metric.displayName);
610+
if (metric.numberFormat) {
611+
if (metric.numberFormat.type === 'percent') {
612+
numberFormat = metric.numberFormat;
613+
console.log('已使用百分比格式:', numberFormat);
614+
} else {
615+
numberFormat = {
616+
type: 'percent' as const,
617+
decimalPlaces: metric.numberFormat.decimalPlaces || 2,
618+
unit: undefined,
619+
suffix: metric.numberFormat.suffix || '',
620+
thousandSeparator: false
621+
};
622+
}
623+
} else {
624+
numberFormat = {
625+
type: 'percent' as const,
626+
decimalPlaces: 2,
627+
unit: undefined,
628+
suffix: '',
629+
thousandSeparator: false
630+
};
631+
}
632+
} else {
633+
numberFormat = metric.numberFormat || {
634+
type: 'number' as const,
635+
decimalPlaces: 2,
636+
unit: undefined,
637+
suffix: undefined,
638+
thousandSeparator: true
639+
};
618640
}
619-
}))
620641

642+
console.log('最终 numberFormat:', numberFormat);
643+
644+
return {
645+
fieldId: metric.fieldId,
646+
fieldName: metric.originalName,
647+
fieldCode: metric.name,
648+
displayName: metric.displayName,
649+
sort: metric.sort,
650+
isVirtual: metric.isVirtual,
651+
aggregation: metric.aggregation || 'sum',
652+
isDivide: metric.isDivide,
653+
formula: metric.isDivide === "divide" ? "divide" : undefined,
654+
numberFormat: numberFormat
655+
}
656+
})
621657
// 4. 构建字段顺序 - 按照 sortPriorityOrder 排序
622658
const allFields = [
623659
...categoryDimensions.map(d => ({

0 commit comments

Comments
 (0)