Commit c1616bc1 authored by zhangwenshuai's avatar zhangwenshuai

修改固定列逻辑,暂时隐藏右侧固定

parent f9986a79
...@@ -106,25 +106,31 @@ const DragFixed = (props: any) => { ...@@ -106,25 +106,31 @@ const DragFixed = (props: any) => {
let leftFixedWidth = 0; let leftFixedWidth = 0;
const fixedCol: any = {}; const fixedCol: any = {};
const fixedColOrder: any = [];
// 计算获取固定列 // 计算获取固定列
for (let i = 0; i < showColumns.length; i++) { for (let i = 0; i < showColumns.length; i++) {
leftFixedWidth += showColumns[i].width || columnWidth; leftFixedWidth += showColumns[i].width || columnWidth;
if (leftFixedWidth <= Number(fixedWidthNum)) { 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 { } else {
break; break;
} }
} }
const newColumns: any = []; let newColumns: any = [];
fixedColOrder.map((temp:any) => {
newColumns.push(fixedCol[temp]);
});
// 新的列数组包含刚固定的列(排在最前面)和原来的所有列,需要将后面重复的列剔除
newColumns = newColumns.concat(columns);
// 为固定列增加fixed属性 // 为固定列增加fixed属性
columns.map((item: any) => { const updateCache = (item: any) => {
if (fixedCol[item.columnName] === 1) {
item.fixed = 'left';
} else {
if (!!item.showStatus && item.fixed === 'left') {
item.fixed = '';
}
}
// 缓存 // 缓存
if (cachedFeAttr) { if (cachedFeAttr) {
const cachedCols = getCache({ tableId }); const cachedCols = getCache({ tableId });
...@@ -132,19 +138,38 @@ const DragFixed = (props: any) => { ...@@ -132,19 +138,38 @@ const DragFixed = (props: any) => {
cachedCols[item.columnName] = { cachedCols[item.columnName] = {
...cachedCols[item.columnName], ...cachedCols[item.columnName],
fixed: item.fixed, fixed: item.fixed,
orderNo: item.orderNo,
}; };
saveCache({ tableId, data: cachedCols }); 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') { if (typeof onDragFixed === 'function') {
onDragFixed(newColumns); onDragFixed(sortedColumns);
} }
// table回调 // table回调
if (typeof onResizeStop === 'function') { if (typeof onResizeStop === 'function') {
onResizeStop(newColumns); onResizeStop(sortedColumns);
} }
}; };
......
...@@ -539,7 +539,7 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -539,7 +539,7 @@ export default class AirTable extends Component<TableProps, TableState> {
tableWidth={tableWidth} tableWidth={tableWidth}
showColumns={showColumns} showColumns={showColumns}
columnWidth={columnWidth} columnWidth={columnWidth}
columns={columns} columns={formatColumns}
onResizeStart={this.onResizeStartLeftDragFixed} onResizeStart={this.onResizeStartLeftDragFixed}
onResizeStop={this.onResizeStopLeftDragFixed} onResizeStop={this.onResizeStopLeftDragFixed}
onDragFixed={onDragFixed} onDragFixed={onDragFixed}
...@@ -637,7 +637,7 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -637,7 +637,7 @@ export default class AirTable extends Component<TableProps, TableState> {
}} }}
</AutoSizer> </AutoSizer>
</div> </div>
{canFixed && ( {false && (
<RightDragFixed <RightDragFixed
tableId={tableId} tableId={tableId}
initLeft={tableWidth - rightWidth} initLeft={tableWidth - rightWidth}
...@@ -645,7 +645,7 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -645,7 +645,7 @@ export default class AirTable extends Component<TableProps, TableState> {
tableWidth={tableWidth} tableWidth={tableWidth}
showColumns={showColumns} showColumns={showColumns}
columnWidth={columnWidth} columnWidth={columnWidth}
columns={columns} columns={formatColumns}
paddingRight={paddingRight} paddingRight={paddingRight}
onResizeStart={this.onResizeStartRightDragFixed} onResizeStart={this.onResizeStartRightDragFixed}
onResizeStop={this.onResizeStopRightDragFixed} onResizeStop={this.onResizeStopRightDragFixed}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment