mirror of
https://github.com/VisActor/VTable
synced 2024-11-21 17:40:10 +00:00
Merge pull request #2848 from VisActor/2831-bug-drag-row-error
2831 bug drag row error
This commit is contained in:
commit
103b5b79f5
@ -0,0 +1,11 @@
|
||||
{
|
||||
"changes": [
|
||||
{
|
||||
"comment": "fix: when up on canvas blank area not drag position rightly #2831\n\n",
|
||||
"type": "none",
|
||||
"packageName": "@visactor/vtable"
|
||||
}
|
||||
],
|
||||
"packageName": "@visactor/vtable",
|
||||
"email": "892739385@qq.com"
|
||||
}
|
36
packages/vtable/src/event/helper.ts
Normal file
36
packages/vtable/src/event/helper.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { TABLE_EVENT_TYPE } from '../core/TABLE_EVENT_TYPE';
|
||||
import type { ListTableAPI } from '../ts-types';
|
||||
import type { BaseTableAPI } from '../ts-types/base-table';
|
||||
|
||||
export function fireMoveColEventListeners(table: BaseTableAPI, endMoveColSuccess: boolean, e: Event) {
|
||||
if (
|
||||
endMoveColSuccess &&
|
||||
table.stateManager.columnMove?.colSource !== -1 &&
|
||||
table.stateManager.columnMove?.rowSource !== -1 &&
|
||||
table.stateManager.columnMove?.colTarget !== -1 &&
|
||||
table.stateManager.columnMove?.rowTarget !== -1
|
||||
) {
|
||||
// 下面触发CHANGE_HEADER_POSITION 区别于pointerup
|
||||
if ((table as any).hasListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION)) {
|
||||
table.fireListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION, {
|
||||
target: { col: table.stateManager.columnMove.colTarget, row: table.stateManager.columnMove.rowTarget },
|
||||
source: {
|
||||
col: table.stateManager.columnMove.colSource,
|
||||
row: table.stateManager.columnMove.rowSource
|
||||
},
|
||||
event: e
|
||||
});
|
||||
}
|
||||
} else if (!endMoveColSuccess) {
|
||||
if ((table as any).hasListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION_FAIL)) {
|
||||
table.fireListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION_FAIL, {
|
||||
target: { col: table.stateManager.columnMove.colTarget, row: table.stateManager.columnMove.rowTarget },
|
||||
source: {
|
||||
col: table.stateManager.columnMove.colSource,
|
||||
row: table.stateManager.columnMove.rowSource
|
||||
},
|
||||
event: e
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ import type { EventManager } from '../event';
|
||||
import { getPixelRatio } from '../../tools/pixel-ratio';
|
||||
import { endResizeCol, endResizeRow } from './table-group';
|
||||
import { isCellDisableSelect } from '../../state/select/is-cell-select-highlight';
|
||||
import { fireMoveColEventListeners } from '../helper';
|
||||
export function bindContainerDomListener(eventManager: EventManager) {
|
||||
const table = eventManager.table;
|
||||
const stateManager = table.stateManager;
|
||||
@ -572,36 +573,7 @@ export function bindContainerDomListener(eventManager: EventManager) {
|
||||
endResizeRow(table);
|
||||
} else if (stateManager.isMoveCol()) {
|
||||
const endMoveColSuccess = table.stateManager.endMoveCol();
|
||||
if (
|
||||
endMoveColSuccess &&
|
||||
table.stateManager.columnMove?.colSource !== -1 &&
|
||||
table.stateManager.columnMove?.rowSource !== -1 &&
|
||||
table.stateManager.columnMove?.colTarget !== -1 &&
|
||||
table.stateManager.columnMove?.rowTarget !== -1
|
||||
) {
|
||||
// 下面触发CHANGE_HEADER_POSITION 区别于pointerup
|
||||
if ((table as any).hasListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION)) {
|
||||
table.fireListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION, {
|
||||
target: { col: table.stateManager.columnMove.colTarget, row: table.stateManager.columnMove.rowTarget },
|
||||
source: {
|
||||
col: table.stateManager.columnMove.colSource,
|
||||
row: table.stateManager.columnMove.rowSource
|
||||
},
|
||||
event: e
|
||||
});
|
||||
}
|
||||
} else if (!endMoveColSuccess) {
|
||||
if ((table as any).hasListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION_FAIL)) {
|
||||
table.fireListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION_FAIL, {
|
||||
target: { col: table.stateManager.columnMove.colTarget, row: table.stateManager.columnMove.rowTarget },
|
||||
source: {
|
||||
col: table.stateManager.columnMove.colSource,
|
||||
row: table.stateManager.columnMove.rowSource
|
||||
},
|
||||
event: e
|
||||
});
|
||||
}
|
||||
}
|
||||
fireMoveColEventListeners(table, endMoveColSuccess, e);
|
||||
} else if (stateManager.isSelecting()) {
|
||||
if (table.stateManager.select?.ranges?.length) {
|
||||
const lastCol = table.stateManager.select.ranges[table.stateManager.select.ranges.length - 1].end.col;
|
||||
@ -637,6 +609,9 @@ export function bindContainerDomListener(eventManager: EventManager) {
|
||||
endResizeCol(table);
|
||||
} else if (stateManager.interactionState === 'grabing' && stateManager.isResizeRow()) {
|
||||
endResizeRow(table);
|
||||
} else if (stateManager.isMoveCol()) {
|
||||
const endMoveColSuccess = table.stateManager.endMoveCol();
|
||||
fireMoveColEventListeners(table, endMoveColSuccess, e);
|
||||
}
|
||||
};
|
||||
eventManager.globalEventListeners.push({
|
||||
|
@ -23,6 +23,7 @@ import { getCellMergeInfo } from '../../scenegraph/utils/get-cell-merge';
|
||||
import type { CheckBox, CheckboxAttributes, Radio } from '@visactor/vrender-components';
|
||||
import { ResizeColumnHotSpotSize } from '../../tools/global';
|
||||
import { handleWhell } from '../scroll';
|
||||
import { fireMoveColEventListeners } from '../helper';
|
||||
export function bindTableGroupListener(eventManager: EventManager) {
|
||||
const table = eventManager.table;
|
||||
const stateManager = table.stateManager;
|
||||
@ -597,33 +598,9 @@ export function bindTableGroupListener(eventManager: EventManager) {
|
||||
} else if (stateManager.isResizeRow()) {
|
||||
endResizeRow(table);
|
||||
} else if (stateManager.isMoveCol()) {
|
||||
const eventArgsSet: SceneEvent = getCellEventArgsSet(e);
|
||||
// const eventArgsSet: SceneEvent = getCellEventArgsSet(e);
|
||||
const endMoveColSuccess = table.stateManager.endMoveCol();
|
||||
if (
|
||||
endMoveColSuccess &&
|
||||
eventArgsSet.eventArgs &&
|
||||
(table as any).hasListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION)
|
||||
) {
|
||||
table.fireListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION, {
|
||||
target: { col: eventArgsSet.eventArgs.col, row: eventArgsSet.eventArgs.row },
|
||||
source: {
|
||||
col: table.stateManager.columnMove.colSource,
|
||||
row: table.stateManager.columnMove.rowSource
|
||||
},
|
||||
event: e.nativeEvent
|
||||
});
|
||||
} else if (!endMoveColSuccess) {
|
||||
if ((table as any).hasListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION_FAIL)) {
|
||||
table.fireListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION_FAIL, {
|
||||
target: { col: table.stateManager.columnMove.colTarget, row: table.stateManager.columnMove.rowTarget },
|
||||
source: {
|
||||
col: table.stateManager.columnMove.colSource,
|
||||
row: table.stateManager.columnMove.rowSource
|
||||
},
|
||||
event: e
|
||||
});
|
||||
}
|
||||
}
|
||||
fireMoveColEventListeners(table, endMoveColSuccess, e.nativeEvent);
|
||||
} else if (stateManager.isSelecting()) {
|
||||
table.stateManager.endSelectCells();
|
||||
if (table.stateManager.isFillHandle()) {
|
||||
|
@ -282,9 +282,9 @@ export function endMoveCol(state: StateManager): boolean {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
state.columnMove.moving = false;
|
||||
setTimeout(() => {
|
||||
//触发事件 CHANGE_HEADER_POSITION 还需要用到这些值 所以延迟清理
|
||||
state.columnMove.moving = false;
|
||||
delete state.columnMove.colSource;
|
||||
delete state.columnMove.rowSource;
|
||||
delete state.columnMove.colTarget;
|
||||
|
Loading…
Reference in New Issue
Block a user