diff --git a/simple-mind-map/src/constants/defaultOptions.js b/simple-mind-map/src/constants/defaultOptions.js index 1f1b5709..1945944b 100644 --- a/simple-mind-map/src/constants/defaultOptions.js +++ b/simple-mind-map/src/constants/defaultOptions.js @@ -182,5 +182,9 @@ export const defaultOpt = { // 节点鼠标hover和激活时显示的矩形边框距节点内容的距离 hoverRectPadding: 2, // 双击节点进入节点文本编辑时是否默认选中文本,默认只在创建新节点时会选中 - selectTextOnEnterEditText: false + selectTextOnEnterEditText: false, + // 拖拽模式 + // default:按住画布、根节点都可拖拽画布 + // noCanvas:按住根节点和 + dragMode: '' } diff --git a/simple-mind-map/src/core/render/node/Node.js b/simple-mind-map/src/core/render/node/Node.js index 2bc4408c..9bca88b9 100644 --- a/simple-mind-map/src/core/render/node/Node.js +++ b/simple-mind-map/src/core/render/node/Node.js @@ -394,14 +394,23 @@ class Node { this.active(e) }) this.group.on('mousedown', e => { - if (this.isRoot && e.which === 3 && !this.mindMap.opt.readonly) { - e.stopPropagation() - } - if (!this.isRoot && e.which !== 2 && !this.mindMap.opt.readonly) { - e.stopPropagation() + const { readonly, enableCtrlKeyNodeSelection, useLeftKeySelectionRightKeyDrag } = this.mindMap.opt + // 只读模式不需要阻止冒泡 + if (!readonly) { + if (this.isRoot) { + // 根节点,右键拖拽画布模式下不需要阻止冒泡 + if (e.which === 3 && !useLeftKeySelectionRightKeyDrag) { + e.stopPropagation() + } + } else { + // 非根节点,且按下的是非鼠标中键,需要阻止事件冒泡 + if (e.which !== 2) { + e.stopPropagation() + } + } } // 多选和取消多选 - if (e.ctrlKey && this.mindMap.opt.enableCtrlKeyNodeSelection) { + if (e.ctrlKey && enableCtrlKeyNodeSelection) { this.isMultipleChoice = true let isActive = this.nodeData.data.isActive if (!isActive)