From 52eb141ba3ee251547a4001ea5397fe314aebe03 Mon Sep 17 00:00:00 2001 From: zhangwenshuai Date: Mon, 21 Dec 2020 16:08:04 +0800 Subject: [PATCH] update --- components/apolloTable/component/Cell.tsx | 2 +- components/apolloTable/component/Column.less | 1 + .../apolloTable/component/DragSorted.tsx | 8 ++++-- components/apolloTable/component/Table.tsx | 26 +++++++++++-------- components/apolloTable/component/index.tsx | 2 ++ 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/components/apolloTable/component/Cell.tsx b/components/apolloTable/component/Cell.tsx index 96b1948..3f6ef7b 100644 --- a/components/apolloTable/component/Cell.tsx +++ b/components/apolloTable/component/Cell.tsx @@ -456,7 +456,7 @@ const Cell = (props: CellProps) => { > {columnIndex === 0 && position !== 'right' && - record.groupConfig[3] && + record.groupConfig[2] && `${record.groupConfig[2].colChsName}:${record.groupTextArr[2]}`} )} diff --git a/components/apolloTable/component/Column.less b/components/apolloTable/component/Column.less index 8f26e3a..276e950 100644 --- a/components/apolloTable/component/Column.less +++ b/components/apolloTable/component/Column.less @@ -24,6 +24,7 @@ width: @textFontGen; color: @textPrimaryColor; margin-right: 5px; + user-select: none; } .colTitle { diff --git a/components/apolloTable/component/DragSorted.tsx b/components/apolloTable/component/DragSorted.tsx index 7c83406..aa156a7 100644 --- a/components/apolloTable/component/DragSorted.tsx +++ b/components/apolloTable/component/DragSorted.tsx @@ -135,8 +135,8 @@ const DragSorted = (props: any) => { const dropMove = dropCol.current && dropCol.current.move; // 清理操作 clean(); - // 没有列信息 - if (!dragColumn || !dropColumn) { + // 没有列信息或没有移动位置 + if (!dragColumn || !dropColumn || dragColumn === dropColumn) { return; } // 拖动回调 @@ -217,6 +217,10 @@ const DragSorted = (props: any) => { // 表格初始位置x点 const originLeft = container.getBoundingClientRect().x || 0; // 拖动列矩形 + if (!e.target.offsetParent) { + // 兼容处理 + return; + } const targetRect = e.target.offsetParent.getBoundingClientRect(); const curX = e.clientX; // 影子div显示 diff --git a/components/apolloTable/component/Table.tsx b/components/apolloTable/component/Table.tsx index 12c8c9c..dfee187 100644 --- a/components/apolloTable/component/Table.tsx +++ b/components/apolloTable/component/Table.tsx @@ -61,7 +61,7 @@ export default class AirTable extends Component { memoizeTotalHeight: Function; static getDerivedStateFromProps(nextProps: TableProps, prevState: TableState) { - const { columns, dataSource, groupConfig } = prevState; + const { columns, dataSource } = prevState; const nextState: TableState = { ...prevState, }; @@ -71,19 +71,15 @@ export default class AirTable extends Component { if (JSON.stringify(columns) !== JSON.stringify(nextProps.columns)) { nextState.columns = nextProps.columns; } - if (JSON.stringify(groupConfig) !== JSON.stringify(nextProps.groupConfig)) { - nextState.groupConfig = nextProps.groupConfig; - } return nextState; } constructor(props: TableProps) { super(props); - const { columns, dataSource, groupConfig, width, height } = props; + const { columns, dataSource, width, height } = props; this.state = { columns, dataSource, - groupConfig, tableWidth: width || 0, tableHeight: height || 0, }; @@ -98,8 +94,10 @@ export default class AirTable extends Component { this.memoizeData = memoizeOne(this.filterData); } - componentWillReceiveProps(prevProps: Readonly, prevState: Readonly, snapshot?: any): void { - if (JSON.stringify(prevState.groupConfig) !== JSON.stringify(this.state.groupConfig)) { + componentDidUpdate(prevProps: Readonly): void { + if ( + JSON.stringify(this.props.dataSource) !== JSON.stringify(prevProps.dataSource) + ) { this.recomputeGridSize(); } } @@ -539,7 +537,10 @@ export default class AirTable extends Component { }} columnCount={leftCount} width={leftWidth + scrollbarWidth} - rowHeight={getRowHeight.bind(null, { dataSource, rowHeight })} + rowHeight={getRowHeight.bind(this, { + dataSource, + rowHeight, + })} rowCount={rowCount} height={tableBodyHeight - scrollbarWidth} scrollTop={scrollTop} @@ -622,7 +623,7 @@ export default class AirTable extends Component { })} columnCount={columnCount} width={realWidth} - rowHeight={getRowHeight.bind(null, { + rowHeight={getRowHeight.bind(this, { dataSource, rowHeight, })} @@ -743,7 +744,10 @@ export default class AirTable extends Component { }} columnCount={rightCount} width={rightWidth + scrollbarWidth} - rowHeight={getRowHeight.bind(null, { dataSource, rowHeight })} + rowHeight={getRowHeight.bind(this, { + dataSource, + rowHeight, + })} rowCount={rowCount} height={tableBodyHeight - scrollbarWidth} scrollTop={scrollTop} diff --git a/components/apolloTable/component/index.tsx b/components/apolloTable/component/index.tsx index fbd266b..1df35f7 100644 --- a/components/apolloTable/component/index.tsx +++ b/components/apolloTable/component/index.tsx @@ -73,6 +73,8 @@ const formatData = (config: string[], dataSource: any[]) => { groupTextArr[2] = group3Cell.text; } }); + // 先清空之前的 + delete row.classList; if (groupKeyArr[0]) { const group1Key = groupKeyArr[0]; const group1Text = groupTextArr[0]; -- 2.21.0