Commit 4c3e4db7 authored by zhangwenshuai's avatar zhangwenshuai

修改apolloTable dragFixed

parent ba4641e1
...@@ -3,9 +3,9 @@ import { ResizableBox } from 'react-resizable'; ...@@ -3,9 +3,9 @@ import { ResizableBox } from 'react-resizable';
import styles from './DragFixed.less'; import styles from './DragFixed.less';
const DragFixed = (props: any) => { const DragFixed = (props: any) => {
const { initLeft, initTop, onResizeStart, tableWidth, showColumns, columnWidth, columns, onResizeStop } = props; const { tableId, initLeft, initTop, onResizeStart, showColumns, columnWidth, columns, onResizeStop } = props;
// 表格 // 表格
const container: any = document.querySelector('#tableContainer'); const container: any = document.querySelector(`#apolloTable_${tableId}`);
// 滑块wrap // 滑块wrap
const handleWrap: any = document.querySelector('#leftFixedHandleWrap'); const handleWrap: any = document.querySelector('#leftFixedHandleWrap');
// 滑块 // 滑块
...@@ -44,11 +44,11 @@ const DragFixed = (props: any) => { ...@@ -44,11 +44,11 @@ const DragFixed = (props: any) => {
}; };
const onResizeHandle = (e: any) => { const onResizeHandle = (e: any) => {
const originLeft = container.getBoundingClientRect().x || 0; const containerRect: any = container.getBoundingClientRect();
let inTableLeft = e.x - originLeft; let inTableLeft = e.x - containerRect.x;
// left不能超过表格一半宽度 // left不能超过表格一半宽度
if (inTableLeft > tableWidth / 2) { if (inTableLeft > containerRect.width / 2) {
inTableLeft = tableWidth / 2; inTableLeft = containerRect.width / 2;
} }
let fixedWidth = 0; let fixedWidth = 0;
let index = 0; let index = 0;
...@@ -60,14 +60,7 @@ const DragFixed = (props: any) => { ...@@ -60,14 +60,7 @@ const DragFixed = (props: any) => {
break; break;
} }
} }
let leftHandleLeft = 0; const leftHandleLeft = fixedWidth - (showColumns[index].width || columnWidth);
if (inTableLeft > fixedWidth - (showColumns[index].width || columnWidth) / 2) {
// left位于当前列中间偏右
leftHandleLeft = fixedWidth;
} else {
// left位于当前列中间偏左
leftHandleLeft = fixedWidth - (showColumns[index].width || columnWidth);
}
// 拖动时显示分割线 // 拖动时显示分割线
dividerWrap.style.display = 'block'; dividerWrap.style.display = 'block';
// 分割线取列的边侧位置 // 分割线取列的边侧位置
......
...@@ -4,18 +4,18 @@ import styles from './DragFixed.less'; ...@@ -4,18 +4,18 @@ import styles from './DragFixed.less';
const DragFixed = (props: any) => { const DragFixed = (props: any) => {
const { const {
tableId,
initLeft, initLeft,
initTop, initTop,
onResizeStart, onResizeStart,
tableWidth,
showColumns, showColumns,
columnWidth, columnWidth,
columns, columns,
onResizeStop, onResizeStop,
scrollbarWidth, paddingRight,
} = props; } = props;
// 表格 // 表格
const container: any = document.querySelector('#tableContainer'); const container: any = document.querySelector(`#apolloTable_${tableId}`);
// 滑块wrap // 滑块wrap
const handleWrap: any = document.querySelector('#rightFixedHandleWrap'); const handleWrap: any = document.querySelector('#rightFixedHandleWrap');
// 滑块 // 滑块
...@@ -57,8 +57,8 @@ const DragFixed = (props: any) => { ...@@ -57,8 +57,8 @@ const DragFixed = (props: any) => {
const containerRect: any = container.getBoundingClientRect(); const containerRect: any = container.getBoundingClientRect();
let inTableRight = containerRect.right - e.x; let inTableRight = containerRect.right - e.x;
// left不能超过表格一半宽度 // left不能超过表格一半宽度
if (inTableRight > tableWidth / 2) { if (inTableRight > containerRect.width / 2) {
inTableRight = tableWidth / 2; inTableRight = containerRect.width / 2;
} }
let fixedWidth = 0; let fixedWidth = 0;
let index = 0; let index = 0;
...@@ -70,20 +70,17 @@ const DragFixed = (props: any) => { ...@@ -70,20 +70,17 @@ const DragFixed = (props: any) => {
break; break;
} }
} }
let rightHandleLeft = fixedWidth - (showColumns[index].width || columnWidth); let rightHandleLeft = fixedWidth - (showColumns[index].width || columnWidth);
// if (inTableRight > fixedWidth - (showColumns[index].width || columnWidth) / 2) { if (fixedWidth === inTableRight) {
// // left位于当前列中间偏右 rightHandleLeft = fixedWidth;
// rightHandleLeft = fixedWidth; }
// } else {
// // left位于当前列中间偏左
// rightHandleLeft = fixedWidth - (showColumns[index].width || columnWidth);
// }
// 拖动时显示分割线 // 拖动时显示分割线
dividerWrap.style.display = 'block'; dividerWrap.style.display = 'block';
// 分割线取列的边侧位置 // 分割线取列的边侧位置
divider.style.left = `${containerRect.width - scrollbarWidth - rightHandleLeft}px`; divider.style.left = `${containerRect.width - paddingRight - rightHandleLeft}px`;
// 拖动线取鼠标位置 // 拖动线取鼠标位置
handleWrap.style.left = `${containerRect.width - scrollbarWidth - inTableRight}px`; handleWrap.style.left = `${containerRect.width - paddingRight - inTableRight}px`;
// 滑动过程中滑块始终显示 // 滑动过程中滑块始终显示
// 滑块wrap添加hovered样式 // 滑块wrap添加hovered样式
handleWrap.classList.add(styles.hovered); handleWrap.classList.add(styles.hovered);
...@@ -92,6 +89,7 @@ const DragFixed = (props: any) => { ...@@ -92,6 +89,7 @@ const DragFixed = (props: any) => {
}; };
const onResizeStopHandle = () => { const onResizeStopHandle = () => {
const containerRect: any = container.getBoundingClientRect();
// 当前固定列宽度为分割线的left // 当前固定列宽度为分割线的left
const fixedWidth: string = divider.style.left; const fixedWidth: string = divider.style.left;
// 样式转数值 // 样式转数值
...@@ -110,7 +108,7 @@ const DragFixed = (props: any) => { ...@@ -110,7 +108,7 @@ const DragFixed = (props: any) => {
// 计算获取固定列 // 计算获取固定列
for (let i = showColumns.length - 1; i >= 0; i--) { for (let i = showColumns.length - 1; i >= 0; i--) {
leftFixedWidth += showColumns[i].width || columnWidth; leftFixedWidth += showColumns[i].width || columnWidth;
if (leftFixedWidth <= tableWidth + scrollbarWidth - Number(fixedWidthNum)) { if (leftFixedWidth <= containerRect.width - paddingRight - Number(fixedWidthNum)) {
fixedCol[showColumns[i].columnName] = 1; fixedCol[showColumns[i].columnName] = 1;
} else { } else {
break; break;
......
...@@ -117,7 +117,8 @@ ...@@ -117,7 +117,8 @@
background-color: rgba(255, 255, 255, 0.4); background-color: rgba(255, 255, 255, 0.4);
z-index: 4; z-index: 4;
display: none; display: none;
pointer-events: none; //pointer-events: none;
user-select: none;
.widthHandle { .widthHandle {
position: absolute; position: absolute;
cursor: ew-resize; cursor: ew-resize;
......
...@@ -639,6 +639,7 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -639,6 +639,7 @@ export default class AirTable extends Component<TableProps, TableState> {
)} )}
{canFixed && ( {canFixed && (
<LeftDragFixed <LeftDragFixed
tableId={tableId}
initLeft={leftWidth} initLeft={leftWidth}
initTop={headerHeight} initTop={headerHeight}
tableWidth={tableWidth} tableWidth={tableWidth}
...@@ -741,13 +742,14 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -741,13 +742,14 @@ export default class AirTable extends Component<TableProps, TableState> {
</div> </div>
{canFixed && ( {canFixed && (
<RightDragFixed <RightDragFixed
tableId={tableId}
initLeft={tableWidth - rightWidth} initLeft={tableWidth - rightWidth}
initTop={headerHeight} initTop={headerHeight}
tableWidth={tableWidth} tableWidth={tableWidth}
showColumns={showColumns} showColumns={showColumns}
columnWidth={columnWidth} columnWidth={columnWidth}
columns={columns} columns={columns}
scrollbarWidth={scrollbarWidth} paddingRight={paddingRight}
onResizeStart={this.onResizeStartRightDragFixed} onResizeStart={this.onResizeStartRightDragFixed}
onResizeStop={this.onResizeStopLeftDragFixed} onResizeStop={this.onResizeStopLeftDragFixed}
/> />
......
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