From c1616bc1551e4e069f7d93ec7230d01c0b497d64 Mon Sep 17 00:00:00 2001 From: zhangwenshuai Date: Thu, 17 Dec 2020 15:33:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9B=BA=E5=AE=9A=E5=88=97?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E6=9A=82=E6=97=B6=E9=9A=90=E8=97=8F?= =?UTF-8?q?=E5=8F=B3=E4=BE=A7=E5=9B=BA=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apolloTable/component/DragFixed.tsx | 51 ++++++++++++++----- components/apolloTable/component/Table.tsx | 6 +-- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/components/apolloTable/component/DragFixed.tsx b/components/apolloTable/component/DragFixed.tsx index d32cbfa..5cd089e 100644 --- a/components/apolloTable/component/DragFixed.tsx +++ b/components/apolloTable/component/DragFixed.tsx @@ -106,25 +106,31 @@ const DragFixed = (props: any) => { let leftFixedWidth = 0; const fixedCol: any = {}; + const fixedColOrder: any = []; // 计算获取固定列 for (let i = 0; i < showColumns.length; i++) { leftFixedWidth += showColumns[i].width || columnWidth; if (leftFixedWidth <= Number(fixedWidthNum)) { - fixedCol[showColumns[i].columnName] = 1; + fixedColOrder.push(showColumns[i].columnName); + // 固定列修改排序到最前面 + fixedCol[showColumns[i].columnName] = { + ...showColumns[i], + fixed: 'left', + orderNo: i + 1, + }; } else { break; } } - const newColumns: any = []; + let newColumns: any = []; + fixedColOrder.map((temp:any) => { + newColumns.push(fixedCol[temp]); + }); + // 新的列数组包含刚固定的列(排在最前面)和原来的所有列,需要将后面重复的列剔除 + newColumns = newColumns.concat(columns); + // 为固定列增加fixed属性 - columns.map((item: any) => { - if (fixedCol[item.columnName] === 1) { - item.fixed = 'left'; - } else { - if (!!item.showStatus && item.fixed === 'left') { - item.fixed = ''; - } - } + const updateCache = (item: any) => { // 缓存 if (cachedFeAttr) { const cachedCols = getCache({ tableId }); @@ -132,19 +138,38 @@ const DragFixed = (props: any) => { cachedCols[item.columnName] = { ...cachedCols[item.columnName], fixed: item.fixed, + orderNo: item.orderNo, }; saveCache({ tableId, data: cachedCols }); } } - newColumns.push(item); + }; + const sortedColumns: any = []; + newColumns.map((item: any, i: number) => { + if (i >= fixedColOrder.length) { + // 除了新增加的固定列,之前的固定列都还原为未固定 + if (item.fixed === 'left') { + item.fixed = ''; + } + // 剔除重复列 + if (!fixedCol[item.columnName]) { + // 重新排序 + item.orderNo = sortedColumns.length + 1; + updateCache(item); + sortedColumns.push(item); + } + } else { + updateCache(item); + sortedColumns.push(item); + } }); // 业务回调 if (typeof onDragFixed === 'function') { - onDragFixed(newColumns); + onDragFixed(sortedColumns); } // table回调 if (typeof onResizeStop === 'function') { - onResizeStop(newColumns); + onResizeStop(sortedColumns); } }; diff --git a/components/apolloTable/component/Table.tsx b/components/apolloTable/component/Table.tsx index 9112c0d..9dc8277 100644 --- a/components/apolloTable/component/Table.tsx +++ b/components/apolloTable/component/Table.tsx @@ -539,7 +539,7 @@ export default class AirTable extends Component { tableWidth={tableWidth} showColumns={showColumns} columnWidth={columnWidth} - columns={columns} + columns={formatColumns} onResizeStart={this.onResizeStartLeftDragFixed} onResizeStop={this.onResizeStopLeftDragFixed} onDragFixed={onDragFixed} @@ -637,7 +637,7 @@ export default class AirTable extends Component { }} - {canFixed && ( + {false && ( { tableWidth={tableWidth} showColumns={showColumns} columnWidth={columnWidth} - columns={columns} + columns={formatColumns} paddingRight={paddingRight} onResizeStart={this.onResizeStartRightDragFixed} onResizeStop={this.onResizeStopRightDragFixed} -- 2.21.0