diff --git a/packages/s2-core/src/common/store/index.ts b/packages/s2-core/src/common/store/index.ts index c97c4dff69..9736710567 100644 --- a/packages/s2-core/src/common/store/index.ts +++ b/packages/s2-core/src/common/store/index.ts @@ -54,7 +54,8 @@ interface StoreKey { drillDownDataCache: DrillDownDataCache[]; // 每个层级下钻的维度缓存 drillDownFieldInLevel: DrillDownFieldInLevel[]; - [key: string]: any; + // 列宽等分模式下初始化计算的列宽 + adaptiveColWidth: number; } /** diff --git a/packages/s2-core/src/facet/layout/util/process-default-col-width-by-type.ts b/packages/s2-core/src/facet/layout/util/process-default-col-width-by-type.ts index 4cff77f126..c4b638206a 100644 --- a/packages/s2-core/src/facet/layout/util/process-default-col-width-by-type.ts +++ b/packages/s2-core/src/facet/layout/util/process-default-col-width-by-type.ts @@ -103,6 +103,7 @@ export default function processDefaultColWidthByType( // if (!facet.spreadsheet.isValueInCols()) { // cellCfg.width = WidthType.ValueInRow; // } + facet.spreadsheet.store.set('adaptiveColWidth', colWidth); return colWidth; } diff --git a/packages/s2-core/src/interaction/row-col-resize.ts b/packages/s2-core/src/interaction/row-col-resize.ts index 4065070010..ba07b9906c 100644 --- a/packages/s2-core/src/interaction/row-col-resize.ts +++ b/packages/s2-core/src/interaction/row-col-resize.ts @@ -203,10 +203,28 @@ export class RowColResize extends BaseInteraction { }); } + // 获取列拖拽的最小宽度 + private getMinCellWidth = () => { + let adaptiveColWidth: number; + // 列等宽平铺模式下,需要限定拖拽最小宽度为等宽值 + if ( + this.spreadsheet.isColAdaptive() && + !this.spreadsheet.isHierarchyTreeType() + ) { + adaptiveColWidth = this.spreadsheet.store.get( + 'adaptiveColWidth', + ) as number; + } + const cellWidth = adaptiveColWidth || MIN_CELL_WIDTH; + return cellWidth; + }; + private resizeMouseMove = (ev: any) => { // is dragging if (this.resizeGroup && this.resizeGroup.get('visible')) { ev.preventDefault(); + + const minCellWidth = this.getMinCellWidth(); const info = this.getResizeInfo(); const children = this.resizeGroup.get('children'); if (children) { @@ -218,10 +236,10 @@ export class RowColResize extends BaseInteraction { if (info.type === 'col') { // 横向移动 let offset = ev.originalEvent.offsetX - this.startPos.offsetX; - if (start[1] + offset - info.offsetX < MIN_CELL_WIDTH) { + if (start[1] + offset - info.offsetX < minCellWidth) { // 禁止拖到最小宽度 - this.startPos.offsetX = info.offsetX + MIN_CELL_WIDTH; - offset = info.offsetX + MIN_CELL_WIDTH - start[1]; + this.startPos.offsetX = info.offsetX + minCellWidth; + offset = info.offsetX + minCellWidth - start[1]; } else { this.startPos.offsetX = ev.originalEvent.offsetX; }