@@ -60,7 +60,6 @@ export function ComponentConfigDrawer() {
6060 // 使用自定义Hook管理所有图表状态
6161 const chartState = useChartState ( editingComponent )
6262 const [ isMetricCard , setIsMetricCard ] = useState ( true )
63- console . log ( editingComponent , 3434343434 ) ;
6463
6564 // 从Hook中解构状态和方法
6665 const {
@@ -118,8 +117,20 @@ export function ComponentConfigDrawer() {
118117 return false
119118 }
120119 }
121-
120+ const isFieldInCategoryOrStack = ( fieldId : string ) => {
121+ return (
122+ categoryDimensions . some ( dim => dim . fieldId === fieldId ) ||
123+ stackDimensions . some ( dim => dim . fieldId === fieldId )
124+ )
125+ }
122126 if ( field . role === 'dimension' ) {
127+ if ( isFieldInCategoryOrStack ( safeFieldId ) ) {
128+ toast ( {
129+ description : t ( "useChartState.warn.fieldExists" ) ,
130+ variant : "warning"
131+ } )
132+ return
133+ }
123134 if ( categoryDimensions . length < 2 && isMetricCard ) {
124135 if ( isFieldAlreadyAdded ( safeFieldId , 'category' ) ) {
125136 toast ( {
@@ -141,6 +152,13 @@ export function ComponentConfigDrawer() {
141152 }
142153 chartState . setCategoryDimensions ( prev => [ ...prev , newDimension ] )
143154 } else if ( currentChartHasStack && stackDimensions . length === 0 && isMetricCard ) {
155+ if ( isFieldInCategoryOrStack ( safeFieldId ) ) {
156+ toast ( {
157+ description : t ( "useChartState.warn.fieldExists" ) ,
158+ variant : "warning"
159+ } )
160+ return
161+ }
144162 if ( isFieldAlreadyAdded ( safeFieldId , 'stack' ) ) {
145163 toast ( {
146164 description : t ( "componentConfigDrawer.toast.fieldAlreadyExists" , {
@@ -190,21 +208,21 @@ export function ComponentConfigDrawer() {
190208 }
191209
192210 if ( valueDimensions . length > 0 ) {
193- if ( currentIsVirtual && ! hasVirtualMetric ) {
194- toast ( {
195- description : t ( "componentConfigDrawer.toast.virtualMetricConflict" ) ,
196- variant : "warning"
197- } )
198- return
199- }
211+ // if (currentIsVirtual && !hasVirtualMetric) {
212+ // toast({
213+ // description: t("componentConfigDrawer.toast.virtualMetricConflict"),
214+ // variant: "warning"
215+ // })
216+ // return
217+ // }
200218
201- if ( ! currentIsVirtual && hasVirtualMetric ) {
202- toast ( {
203- description : t ( "componentConfigDrawer.toast.virtualMetricConflict" ) ,
204- variant : "warning"
205- } )
206- return
207- }
219+ // if (!currentIsVirtual && hasVirtualMetric) {
220+ // toast({
221+ // description: t("componentConfigDrawer.toast.virtualMetricConflict"),
222+ // variant: "warning"
223+ // })
224+ // return
225+ // }
208226
209227 // 多个虚拟指标
210228 // if (currentIsVirtual && hasVirtualMetric) {
@@ -293,6 +311,14 @@ export function ComponentConfigDrawer() {
293311
294312 const saveDisplayName = useCallback ( ( ) => {
295313 if ( editingDimension ) {
314+ const trimmedName = editingDimension . displayName ?. trim ( ) ;
315+ if ( ! trimmedName ) {
316+ toast ( {
317+ description : t ( "componentConfigDrawer.dialog.displayRequired" ) ,
318+ variant : "error"
319+ } ) ;
320+ return ;
321+ }
296322 // 更新对应的维度显示名称
297323 const updateDimensions = ( prev : any [ ] ) =>
298324 prev . map ( d => d . id === editingDimension . id ? { ...d , displayName : editingDimension . displayName } : d )
@@ -608,8 +634,71 @@ export function ComponentConfigDrawer() {
608634 const chartLabel = ChartGroupItems
609635 . flatMap ( item => item . data )
610636 . find ( item => item . type === data . type ) ?. label ;
611- if ( chartLabel ) {
612- setTitle ( t ( `chart.${ chartLabel } ` ) ) ;
637+
638+ // 判断用户是否自定义过标题
639+ const userCustomizedTitle = editingComponent . title !== styleConfig . title ;
640+ const newTitle = userCustomizedTitle ? editingComponent . title : ( chartLabel ? t ( `chart.${ chartLabel } ` ) : title ) ;
641+
642+ if ( ! userCustomizedTitle && chartLabel ) {
643+ setTitle ( newTitle ) ;
644+ }
645+
646+ // 立即触发图表更新
647+ if ( editingComponent ) {
648+ // 使用当前实际的限制配置
649+ const currentLimitType = limitType ;
650+ const currentLimitValue = limitValue ;
651+
652+ // 获取当前数据配置
653+ const dataConfig = getDataConfig ( currentLimitType , currentLimitValue , editingComponent . data_config ?. timeFilter ) ;
654+
655+ // 根据新图表类型调整配置
656+ const STACKED_CHART_TYPES = new Set < ChartType > ( [
657+ ChartType . StackedBar ,
658+ ChartType . StackedHorizontalBar ,
659+ ChartType . StackedLine
660+ ] ) ;
661+
662+ const isNewChartStacked = STACKED_CHART_TYPES . has ( data . type ) ;
663+ const isCurrentChartStacked = currentChartHasStack ;
664+
665+ let updatedDataConfig = { ...dataConfig } ;
666+
667+ // 处理堆叠维度
668+ if ( isCurrentChartStacked && ! isNewChartStacked ) {
669+ // 从堆叠图切换到非堆叠图:移除堆叠维度配置
670+ updatedDataConfig = {
671+ ...updatedDataConfig ,
672+ stackDimension : undefined ,
673+ // 保持其他维度不变
674+ dimensions : updatedDataConfig . dimensions || [ ] ,
675+ metrics : updatedDataConfig . metrics || [ ]
676+ } ;
677+ } else if ( ! isCurrentChartStacked && isNewChartStacked ) {
678+ // 从非堆叠图切换到堆叠图:清空堆叠维度(用户需要手动添加)
679+ updatedDataConfig = {
680+ ...updatedDataConfig ,
681+ stackDimension : undefined , // 清空堆叠维度
682+ // 保持其他维度不变
683+ dimensions : updatedDataConfig . dimensions || [ ] ,
684+ metrics : updatedDataConfig . metrics || [ ]
685+ } ;
686+ }
687+
688+ // 更新组件配置
689+ updateEditingComponent ( {
690+ type : data . type ,
691+ data_config : updatedDataConfig ,
692+ title : newTitle ,
693+ style_config : {
694+ ...styleConfig ,
695+ title : newTitle // 同时更新styleConfig中的标题
696+ } ,
697+ dataset_code : editingComponent . dataset_code
698+ } ) ;
699+
700+ // 刷新图表
701+ refreshChart ( editingComponent . id ) ;
613702 }
614703 } } maxHeight = { 500 } >
615704 < div className = "relative w-full group" >
@@ -730,7 +819,7 @@ export function ComponentConfigDrawer() {
730819 < div
731820 key = { field . id }
732821 draggable
733- onMouseDown = { ( ) => setDraggingId ( field . id ) }
822+ onMouseDown = { ( ) => { } }
734823 onDragStart = { ( e ) => {
735824 setDraggingId ( field . id )
736825 e . dataTransfer . effectAllowed = 'move'
0 commit comments