@@ -328,21 +328,35 @@ export default function CrosstabTable({
328328 horizontalCombinations . forEach ( ( hCombination , colIndex ) => {
329329 const value = hCombination [ dimIndex ]
330330 const headerKey = `${ dimIndex } -${ colIndex } -${ value } `
331+ const hPath = generateDimensionPath ( hCombination )
332+ const hasColumnData = Object . keys ( tableData ) . some ( cellKey =>
333+ cellKey . startsWith ( hPath + '|' ) && Object . keys ( tableData [ cellKey ] ) . length > 0
334+ )
331335
332336 headerElements . push (
333- < div
334- key = { headerKey }
335- className = "grid-column-header"
336- style = { {
337- gridColumn : colDimensions + colIndex + 1 ,
338- gridRow : dimIndex + 1 ,
339- backgroundColor : 'white' ,
340- border : '1px solid #d9d9d9' ,
341- fontSize : dimIndex === 0 ? '12px' : '11px' ,
342- fontWeight : dimIndex === 0 ? 'bold' : 'normal'
343- } }
344- >
337+ < div
338+ key = { headerKey }
339+ className = "grid-column-header"
340+ style = { {
341+ gridColumn : colDimensions + colIndex + 1 ,
342+ gridRow : dimIndex + 1 ,
343+ backgroundColor : 'white' ,
344+ border : '1px solid #d9d9d9' ,
345+ fontSize : dimIndex === 0 ? '12px' : '11px' ,
346+ fontWeight : dimIndex === 0 ? 'bold' : 'normal' ,
347+ position : 'relative'
348+ } }
349+ >
345350 { value }
351+ { ( onGenerateColumn || onClearColumn ) && (
352+ < Dropdown
353+ menu = { { items : createColumnMenu ( hPath , hasColumnData ) } }
354+ trigger = { [ 'hover' ] }
355+ placement = "bottomRight"
356+ >
357+ < div className = "cell-menu-trigger" />
358+ </ Dropdown >
359+ ) }
346360 </ div >
347361 )
348362 } )
@@ -380,49 +394,7 @@ export default function CrosstabTable({
380394 }
381395 }
382396
383- // 为最后一个维度的每个组合添加菜单
384- if ( onGenerateColumn || onClearColumn ) {
385- horizontalCombinations . forEach ( ( hCombination , colIndex ) => {
386- const hPath = generateDimensionPath ( hCombination )
387- const hasColumnData = Object . keys ( tableData ) . some ( cellKey =>
388- cellKey . startsWith ( hPath + '|' ) && Object . keys ( tableData [ cellKey ] ) . length > 0
389- )
390-
391- headerElements . push (
392- < div
393- key = { `menu-${ colIndex } ` }
394- className = "grid-column-menu"
395- style = { {
396- gridColumn : colDimensions + colIndex + 1 ,
397- gridRow : metadata . horizontalDimensions . length ,
398- backgroundColor : 'transparent' ,
399- border : 'none' ,
400- padding : '0' ,
401- position : 'relative' ,
402- height : '100%' ,
403- width : '100%' ,
404- pointerEvents : 'none'
405- } }
406- >
407- < Dropdown
408- menu = { { items : createColumnMenu ( hPath , hasColumnData ) } }
409- trigger = { [ 'hover' ] }
410- placement = "bottomRight"
411- >
412- < div
413- className = "cell-menu-trigger"
414- style = { {
415- position : 'absolute' ,
416- top : 0 ,
417- right : 0 ,
418- pointerEvents : 'auto'
419- } }
420- />
421- </ Dropdown >
422- </ div >
423- )
424- } )
425- }
397+
426398
427399 return headerElements
428400 } ) ( ) }
@@ -443,21 +415,37 @@ export default function CrosstabTable({
443415 verticalCombinations . forEach ( ( vCombination , rowIndex ) => {
444416 const value = vCombination [ dimIndex ]
445417 const headerKey = `${ dimIndex } -${ rowIndex } -${ value } `
418+ const vPath = generateDimensionPath ( vCombination )
419+ const hasRowData = horizontalCombinations . some ( ( hCombination ) => {
420+ const hPath = generateDimensionPath ( hCombination )
421+ const cellKey = `${ hPath } |${ vPath } `
422+ return tableData [ cellKey ] && Object . keys ( tableData [ cellKey ] ) . length > 0
423+ } )
446424
447425 headerElements . push (
448- < div
449- key = { headerKey }
450- className = "grid-row-header"
451- style = { {
452- gridColumn : dimIndex + 1 ,
453- gridRow : rowDimensions + rowIndex + 1 ,
454- backgroundColor : 'white' ,
455- border : '1px solid #d9d9d9' ,
456- fontSize : '12px' ,
457- fontWeight : dimIndex === 0 ? 'bold' : 'normal'
458- } }
459- >
426+ < div
427+ key = { headerKey }
428+ className = "grid-row-header"
429+ style = { {
430+ gridColumn : dimIndex + 1 ,
431+ gridRow : rowDimensions + rowIndex + 1 ,
432+ backgroundColor : 'white' ,
433+ border : '1px solid #d9d9d9' ,
434+ fontSize : '12px' ,
435+ fontWeight : dimIndex === 0 ? 'bold' : 'normal' ,
436+ position : 'relative'
437+ } }
438+ >
460439 { value }
440+ { ( onGenerateRow || onClearRow ) && (
441+ < Dropdown
442+ menu = { { items : createRowMenu ( vPath , hasRowData ) } }
443+ trigger = { [ 'hover' ] }
444+ placement = "bottomRight"
445+ >
446+ < div className = "cell-menu-trigger" />
447+ </ Dropdown >
448+ ) }
461449 </ div >
462450 )
463451 } )
@@ -495,51 +483,7 @@ export default function CrosstabTable({
495483 }
496484 }
497485
498- // 为最后一个维度的每个组合添加菜单
499- if ( onGenerateRow || onClearRow ) {
500- verticalCombinations . forEach ( ( vCombination , rowIndex ) => {
501- const vPath = generateDimensionPath ( vCombination )
502- const hasRowData = horizontalCombinations . some ( ( hCombination ) => {
503- const hPath = generateDimensionPath ( hCombination )
504- const cellKey = `${ hPath } |${ vPath } `
505- return tableData [ cellKey ] && Object . keys ( tableData [ cellKey ] ) . length > 0
506- } )
507-
508- headerElements . push (
509- < div
510- key = { `menu-${ rowIndex } ` }
511- className = "grid-row-menu"
512- style = { {
513- gridColumn : metadata . verticalDimensions . length ,
514- gridRow : rowDimensions + rowIndex + 1 ,
515- backgroundColor : 'transparent' ,
516- border : 'none' ,
517- padding : '0' ,
518- position : 'relative' ,
519- height : '100%' ,
520- width : '100%' ,
521- pointerEvents : 'none'
522- } }
523- >
524- < Dropdown
525- menu = { { items : createRowMenu ( vPath , hasRowData ) } }
526- trigger = { [ 'hover' ] }
527- placement = "bottomRight"
528- >
529- < div
530- className = "cell-menu-trigger"
531- style = { {
532- position : 'absolute' ,
533- top : 0 ,
534- right : 0 ,
535- pointerEvents : 'auto'
536- } }
537- />
538- </ Dropdown >
539- </ div >
540- )
541- } )
542- }
486+
543487
544488 return headerElements
545489 } ) ( ) }
@@ -562,13 +506,7 @@ export default function CrosstabTable({
562506 gridColumn : colDimensions + colIndex + 1 ,
563507 gridRow : rowDimensions + rowIndex + 1 ,
564508 backgroundColor : isGenerating ? '#f0f0f0' : 'white' ,
565- border : '1px solid #d9d9d9' ,
566- cursor : 'pointer'
567- } }
568- onClick = { ( ) => {
569- if ( ! isGenerating && onGenerateCell ) {
570- onGenerateCell ( hPath , vPath )
571- }
509+ border : '1px solid #d9d9d9'
572510 } }
573511 >
574512 < div className = "cell-content" >
@@ -578,7 +516,7 @@ export default function CrosstabTable({
578516 ) : cellContent ? (
579517 < Text > { cellContent } </ Text >
580518 ) : (
581- < Text type = "secondary" > 点击生成 </ Text >
519+ < Text type = "secondary" > - </ Text >
582520 ) }
583521 </ div >
584522 </ div >
0 commit comments