dluptydi1#
好的,收到,我们看看哈~
e5nqia272#
自己定义了事件监听,做的`useEffect(() => {document.onkeydown = hotKey},[selectedNode, selectedEdge, cvs])
const hotKey = (event) => { const key = event.keyCode const ctrlKey = event.ctrlKey || event.metaKey const shiftKey = event.shiftKey if (ctrlKey) { event.preventDefault(); if(shiftKey){ switch(key){ case 90: { cvs.redo(); break; } case 76: { if(selectedNode?.id && selectedNode.options.readOnly){ handleUnlock()//解锁 }else if(selectedEdge && selectedEdge.options['readOnly']){ handleUnlock()//解锁 } break; } } }else{ switch(key){ case 68:{ if(selectedNode?.id && !selectedNode.options.readOnly){ cvs.removeNode(selectedNode?.id); }else if(selectedEdge && !selectedEdge.options['readOnly']){ cvs.removeEdge(selectedEdge) } break; } case 76: { if(selectedNode?.id && !selectedNode.options.readOnly){ handleLock()//锁定 }else if(selectedEdge && !selectedEdge.options['readOnly']){ handleLock()//锁定 } break; } case 77: { setAddVisible(!addVisible) setRelatedVisible(false) break; } case 90:{ cvs.undo(); break; } } } } }`
2条答案
按热度按时间dluptydi1#
好的,收到,我们看看哈~
e5nqia272#
自己定义了事件监听,做的
`
useEffect(() => {
document.onkeydown = hotKey
},[selectedNode, selectedEdge, cvs])