Skip to content

Commit

Permalink
fix:修复笔记本触摸板点击节点事件失效 (#1465)
Browse files Browse the repository at this point in the history
  • Loading branch information
wuchenguang1998 authored Feb 5, 2024
1 parent 926f33e commit 2c15619
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/core/src/view/node/BaseNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default abstract class BaseNode extends Component<IProps, IState> {
}
stepDrag: StepDrag;
contextMenuTime: number;
mouseUpDrag: boolean;
startTime: number;
clickTimer: number;
modelDisposer: IReactionDisposer;
Expand Down Expand Up @@ -261,13 +262,17 @@ export default abstract class BaseNode extends Component<IProps, IState> {
const { model } = this.props;
model.isDragging = false;
};
handleMouseUp = () => {
const { model } = this.props;
this.mouseUpDrag = model.isDragging;
};
handleClick = (e: MouseEvent) => {
// 节点拖拽进画布之后,不触发click事件相关emit
// 点拖拽进画布没有触发mousedown事件,没有startTime,用这个值做区分
const isDragging = this.mouseUpDrag === false;
if (!this.startTime) return;
const time = new Date().getTime() - this.startTime;
if (time > 200) return; // 事件大于200ms,认为是拖拽, 不触发click事件。
const { model, graphModel } = this.props;
if (!isDragging) return; // 如果是拖拽, 不触发click事件。
// 节点数据,多为事件对象数据抛出
const nodeData = model.getData();
const position = graphModel.getPointByClient({
Expand Down Expand Up @@ -426,6 +431,7 @@ export default abstract class BaseNode extends Component<IProps, IState> {
<g
className={`${this.getStateClassName()} ${className}`}
onMouseDown={this.handleMouseDown}
onMouseUp={this.handleMouseUp}
onClick={this.handleClick}
onMouseEnter={this.setHoverON}
onMouseOver={this.setHoverON}
Expand Down

0 comments on commit 2c15619

Please sign in to comment.