From a047dabbd07cfe5ecd0301565958ba4ab0753351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Mon, 24 Jun 2024 18:42:14 +0800 Subject: [PATCH] =?UTF-8?q?Feat=EF=BC=9A=E6=96=B0=E5=A2=9E=E6=8B=A6?= =?UTF-8?q?=E6=88=AA=E8=8A=82=E7=82=B9=E5=BC=80=E5=A7=8B=E6=8B=96=E6=8B=BD?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E4=BE=8B=E5=8C=96=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/constants/defaultOptions.js | 4 +++- simple-mind-map/src/plugins/Drag.js | 14 ++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/simple-mind-map/src/constants/defaultOptions.js b/simple-mind-map/src/constants/defaultOptions.js index cdca2fbc..70a7f4fc 100644 --- a/simple-mind-map/src/constants/defaultOptions.js +++ b/simple-mind-map/src/constants/defaultOptions.js @@ -256,6 +256,8 @@ export const defaultOpt = { handleDragCloneNode: null, // 即将拖拽完成前调用该函数,函数接收一个对象作为参数:{overlapNodeUid,prevNodeUid,nextNodeUid},代表拖拽信息,如果要阻止本次拖拽,那么可以返回true,此时node_dragend事件不会再触发。函数可以是异步函数,返回Promise实例 beforeDragEnd: null, + // 即将开始调整节点前调用该函数,函数接收当前即将被拖拽的节点实例列表作为参数,如果要阻止本次拖拽,那么可以返回true + beforeDragStart: null, // 【Watermark插件】 // 水印配置 @@ -380,5 +382,5 @@ export const defaultOpt = { beforeHideRichTextEdit: null, // 设置富文本节点编辑框和节点大小一致,形成伪原地编辑的效果 // 需要注意的是,只有当节点内只有文本、且形状是矩形才会有比较好的效果 - richTextEditFakeInPlace: false, + richTextEditFakeInPlace: false } diff --git a/simple-mind-map/src/plugins/Drag.js b/simple-mind-map/src/plugins/Drag.js index 8d95cd7f..2c41e90e 100644 --- a/simple-mind-map/src/plugins/Drag.js +++ b/simple-mind-map/src/plugins/Drag.js @@ -19,7 +19,7 @@ class Drag extends Base { // 复位 reset() { - // 是否正在跳转中 + // 是否正在拖拽中 this.isDragging = false // 鼠标按下的节点 this.mousedownNode = null @@ -223,7 +223,7 @@ class Drag extends Base { // 拖动中 onMove(x, y, e) { - if (!this.isMousedown) { + if (!this.isMousedown || !this.isDragging) { return } // 更新克隆节点的位置 @@ -245,9 +245,8 @@ class Drag extends Base { } // 开始拖拽时初始化一些数据 - handleStartMove() { + async handleStartMove() { if (!this.isDragging) { - this.isDragging = true // 鼠标按下的节点 let node = this.mousedownNode // 计算鼠标按下的位置距离节点左上角的距离 @@ -268,12 +267,19 @@ class Drag extends Base { // 否则只拖拽按下的节点 this.beingDragNodeList = [node] } + // 拦截拖拽 + const { beforeDragStart } = this.mindMap.opt + if (typeof beforeDragStart === 'function') { + const stop = await beforeDragStart([...this.beingDragNodeList]) + if (stop) return + } // 将节点树转为节点数组 this.nodeTreeToList() // 创建克隆节点 this.createCloneNode() // 清除当前所有激活的节点 this.mindMap.execCommand('CLEAR_ACTIVE_NODE') + this.isDragging = true } }