function touchHandler(event) { event.stopPropagation(); var touches = event.changedTouches, first = touches[0], type = ""; switch (event.type) { case "touchstart": type = "mousedown"; break; case "touchmove": type = "mousemove"; break; case "touchend": type = "mouseup"; break; default: return; } var simulatedEvent = new MouseEvent(type, { "altKey": false, "button": 0, "buttons": 0, "clientX": first.clientX, "clientY": first.clientY, "ctrlKey": false, "metaKey": false, "relatedTarget": first, "screenX": first.screenX, "screenY": first.screenY, "shiftKey": false }); // var simulatedEvent = document.createEvent("MouseEvent"); // simulatedEvent.initMouseEvent(type, true, true, window, 1, // first.screenX, first.screenY, // first.clientX, first.clientY, false, // false, false, false, 0/*left*/, null); first.target.dispatchEvent(simulatedEvent); } function init() { document.addEventListener("touchstart", touchHandler, true); document.addEventListener("touchmove", touchHandler, true); document.addEventListener("touchend", touchHandler, true); document.addEventListener("touchcancel", touchHandler, true); HTMLElement.prototype.__defineGetter__("ondblclick", function () { return this.doubleTap; }); HTMLElement.prototype.__defineSetter__("ondblclick", function (fun) { this.doubleTap = fun; $(this).on("doubleTap", fun) }); var eventlstener = HTMLElement.prototype.addEventListener; HTMLElement.prototype.addEventListener = function (type, fun, op) { if (type == "click") { eventlstener.call(this, type, function (e) { if (!this.startTime) { this.startTime = new Date().getTime(); fun.call(this); } else { const time = new Date().getTime() - this.startTime; this.startTime = new Date().getTime(); if (time > 200) { fun.call(this); } else { e.detail = 2; fun.call(this); } } }, op); } else { eventlstener.apply(this, arguments); } } // handleClick = (e: MouseEvent) => { // // 节点拖拽进画布之后,不触发click事件相关emit // // 点拖拽进画布没有触发mousedown事件,没有startTime,用这个值做区分 // if (!this.startTime) return; // const time = new Date().getTime() - this.startTime; // if (time > 200) return; // 事件大于200ms,认为是拖拽, 不触发click事件。 // const { model, graphModel } = this.props; // // 节点数据,多为事件对象数据抛出 // const nodeData = model.getData(); // const position = graphModel.getPointByClient({ // x: e.clientX, // y: e.clientY, // }); // const eventOptions: EventArgs = { // data: nodeData, // e, // position, // isSelected: false, // isMultiple: false, // }; // const isRightClick = e.button === 2; // // 这里 IE 11不能正确显示 // const isDoubleClick = e.detail === 2; // // 判断是否有右击,如果有右击则取消点击事件触发 // if (isRightClick) return; // const { editConfigModel } = graphModel; // // 在multipleSelect tool禁用的情况下,允许取消选中节点 // const isMultiple = isMultipleSelect(e, editConfigModel); // eventOptions.isMultiple = isMultiple; // if (model.isSelected && !isDoubleClick && isMultiple) { // eventOptions.isSelected = false; // model.setSelected(false); // } else { // graphModel.selectNodeById(model.id, isMultiple); // eventOptions.isSelected = true; // this.toFront(); // } // // 不是双击的,默认都是单击 // if (isDoubleClick) { // if (editConfigModel.nodeTextEdit && model.text.editable) { // model.setSelected(false); // graphModel.setElementStateById(model.id, ElementState.TEXT_EDIT); // } // graphModel.eventCenter.emit(EventType.NODE_DBCLICK, eventOptions); // } else { // graphModel.eventCenter.emit(EventType.ELEMENT_CLICK, eventOptions); // graphModel.eventCenter.emit(EventType.NODE_CLICK, eventOptions); // } // }; }