Commit a18fde7a authored by zhangwenshuai's avatar zhangwenshuai

update

parent 285e8132
...@@ -15,6 +15,7 @@ const DragSorted = (props: any) => { ...@@ -15,6 +15,7 @@ const DragSorted = (props: any) => {
columns, columns,
cachedFeAttr, cachedFeAttr,
position, position,
columnChsName,
} = props; } = props;
if (!canSorted || position === 'left' || position === 'right') { if (!canSorted || position === 'left' || position === 'right') {
return <div className={s.sortedWrap}>{props.children}</div>; return <div className={s.sortedWrap}>{props.children}</div>;
...@@ -100,7 +101,7 @@ const DragSorted = (props: any) => { ...@@ -100,7 +101,7 @@ const DragSorted = (props: any) => {
} }
timerInterval.current = setInterval(() => { timerInterval.current = setInterval(() => {
onDragSortedMove(dir, step); onDragSortedMove(dir, step);
}, 350); }, 150);
} else { } else {
// 需要停止,清除已有计时器 // 需要停止,清除已有计时器
// eslint-disable-next-line no-lonely-if // eslint-disable-next-line no-lonely-if
...@@ -147,8 +148,10 @@ const DragSorted = (props: any) => { ...@@ -147,8 +148,10 @@ const DragSorted = (props: any) => {
} }
// 拖动回调 // 拖动回调
const newColumns: any[] = []; const newColumns: any[] = [];
columns.map((item: any) => { // 从右往左拖
if (Number(dragColumnOrder) > Number(dropColumnOrder)) { if (Number(dragColumnOrder) > Number(dropColumnOrder)) {
// columns已排序
columns.map((item: any, i: number) => {
if (item.orderNo >= Number(dropColumnOrder) && item.orderNo <= Number(dragColumnOrder)) { if (item.orderNo >= Number(dropColumnOrder) && item.orderNo <= Number(dragColumnOrder)) {
if (item.columnName === dragColumn) { if (item.columnName === dragColumn) {
newColumns.push({ newColumns.push({
...@@ -158,28 +161,34 @@ const DragSorted = (props: any) => { ...@@ -158,28 +161,34 @@ const DragSorted = (props: any) => {
} else { } else {
newColumns.push({ newColumns.push({
...item, ...item,
orderNo: item.orderNo + 1, orderNo: columns[i + 1].orderNo,
}); });
} }
} else { } else {
newColumns.push(item); newColumns.push(item);
} }
} else { });
} else {
// 从左往右拖
const index = columns.findIndex((item: any) => {
return item.columnName === dropColumn;
});
columns.map((item: any, i: number) => {
if (item.columnName === dragColumn) { if (item.columnName === dragColumn) {
newColumns.push({ newColumns.push({
...item, ...item,
orderNo: Number(dropColumnOrder) - 1, orderNo: columns[index - 1].orderNo,
}); });
} else if (item.orderNo >= Number(dragColumnOrder) && item.orderNo <= Number(dropColumnOrder)) { } else if (item.orderNo > Number(dragColumnOrder) && item.orderNo < Number(dropColumnOrder)) {
newColumns.push({ newColumns.push({
...item, ...item,
orderNo: item.orderNo - 1, orderNo: columns[i - 1].orderNo,
}); });
} else { } else {
newColumns.push(item); newColumns.push(item);
} }
} });
}); }
if (cachedFeAttr) { if (cachedFeAttr) {
const cachedCols = getCache({ tableId }); const cachedCols = getCache({ tableId });
if (cachedCols) { if (cachedCols) {
...@@ -219,6 +228,7 @@ const DragSorted = (props: any) => { ...@@ -219,6 +228,7 @@ const DragSorted = (props: any) => {
columnCopyDiv.style.left = `${targetRect.x - originLeft}px`; columnCopyDiv.style.left = `${targetRect.x - originLeft}px`;
// 影子div宽度=拖动列宽度 // 影子div宽度=拖动列宽度
columnCopyDiv.style.width = `${targetRect.width}px`; columnCopyDiv.style.width = `${targetRect.width}px`;
columnCopyDiv.innerText = columnChsName;
// 鼠标x点与拖动列x点之间的距离(记录下来方便后续使用) // 鼠标x点与拖动列x点之间的距离(记录下来方便后续使用)
const detaX = curX - targetRect.x; const detaX = curX - targetRect.x;
columnCopyDiv.setAttribute('data-deta-x', String(detaX)); columnCopyDiv.setAttribute('data-deta-x', String(detaX));
...@@ -237,7 +247,7 @@ const DragSorted = (props: any) => { ...@@ -237,7 +247,7 @@ const DragSorted = (props: any) => {
// 阻止默认行为 // 阻止默认行为
e.preventDefault(); e.preventDefault();
}, },
[columnName, orderNo], [columnName, orderNo, onMouseMove, onMouseUp],
); );
return ( return (
......
...@@ -109,4 +109,6 @@ ...@@ -109,4 +109,6 @@
background: rgba(0, 0, 0, 0.3); background: rgba(0, 0, 0, 0.3);
display: none; display: none;
cursor: grab; cursor: grab;
text-align: center;
padding-top: @paddingSmX;
} }
...@@ -274,6 +274,7 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -274,6 +274,7 @@ export default class AirTable extends Component<TableProps, TableState> {
> >
<DragSorted <DragSorted
columnName={columnName} columnName={columnName}
columnChsName={columnChsName}
orderNo={orderNo} orderNo={orderNo}
canSorted={canSorted} canSorted={canSorted}
onDragSorted={onDragSorted} onDragSorted={onDragSorted}
......
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