Skip to content

Commit 2c15619

Browse files
fix:修复笔记本触摸板点击节点事件失效 (#1465)
1 parent 926f33e commit 2c15619

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/core/src/view/node/BaseNode.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export default abstract class BaseNode extends Component<IProps, IState> {
3535
}
3636
stepDrag: StepDrag;
3737
contextMenuTime: number;
38+
mouseUpDrag: boolean;
3839
startTime: number;
3940
clickTimer: number;
4041
modelDisposer: IReactionDisposer;
@@ -261,13 +262,17 @@ export default abstract class BaseNode extends Component<IProps, IState> {
261262
const { model } = this.props;
262263
model.isDragging = false;
263264
};
265+
handleMouseUp = () => {
266+
const { model } = this.props;
267+
this.mouseUpDrag = model.isDragging;
268+
};
264269
handleClick = (e: MouseEvent) => {
265270
// 节点拖拽进画布之后,不触发click事件相关emit
266271
// 点拖拽进画布没有触发mousedown事件,没有startTime,用这个值做区分
272+
const isDragging = this.mouseUpDrag === false;
267273
if (!this.startTime) return;
268-
const time = new Date().getTime() - this.startTime;
269-
if (time > 200) return; // 事件大于200ms,认为是拖拽, 不触发click事件。
270274
const { model, graphModel } = this.props;
275+
if (!isDragging) return; // 如果是拖拽, 不触发click事件。
271276
// 节点数据,多为事件对象数据抛出
272277
const nodeData = model.getData();
273278
const position = graphModel.getPointByClient({
@@ -426,6 +431,7 @@ export default abstract class BaseNode extends Component<IProps, IState> {
426431
<g
427432
className={`${this.getStateClassName()} ${className}`}
428433
onMouseDown={this.handleMouseDown}
434+
onMouseUp={this.handleMouseUp}
429435
onClick={this.handleClick}
430436
onMouseEnter={this.setHoverON}
431437
onMouseOver={this.setHoverON}

0 commit comments

Comments
 (0)