From 6efe4a3fd6a83b320d0d7d324b66462ff301b4e4 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Fri, 24 Mar 2023 15:26:24 +0800 Subject: [PATCH] =?UTF-8?q?Feature=EF=BC=9A1.=E6=94=AF=E6=8C=81=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=8F=92=E5=85=A5=E8=8A=82=E7=82=B9=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E6=96=87=E5=AD=97=EF=BC=9B2.=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=9B3.=E8=8A=82=E7=82=B9=E6=8F=92?= =?UTF-8?q?=E5=85=A5=E5=92=8C=E5=88=A0=E9=99=A4=E5=91=BD=E4=BB=A4=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=BC=A0=E5=85=A5=E6=8C=87=E5=AE=9A=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E5=92=8C=E5=88=9D=E5=A7=8B=E8=8A=82=E7=82=B9=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/index.js | 6 +++- simple-mind-map/src/Command.js | 2 ++ simple-mind-map/src/Render.js | 53 ++++++++++++++++++++++------------ 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/simple-mind-map/index.js b/simple-mind-map/index.js index 5e0bed02..314c9ff6 100644 --- a/simple-mind-map/index.js +++ b/simple-mind-map/index.js @@ -68,7 +68,11 @@ const defaultOpt = { // 鼠标滚动的行为,如果customHandleMousewheel传了自定义函数,这个属性不生效 mousewheelAction: 'zoom',// zoom(放大缩小)、move(上下移动) // 当mousewheelAction设为move时,可以通过该属性控制鼠标滚动一下视图移动的步长,单位px - mousewheelMoveStep: 100 + mousewheelMoveStep: 100, + // 默认插入的二级节点的文字 + defaultInsertSecondLevelNodeText: '二级节点', + // 默认插入的二级以下节点的文字 + defaultInsertBelowSecondLevelNodeText: '分支主题' } // 思维导图 diff --git a/simple-mind-map/src/Command.js b/simple-mind-map/src/Command.js index 4d9bd8c7..0d1880e2 100644 --- a/simple-mind-map/src/Command.js +++ b/simple-mind-map/src/Command.js @@ -81,6 +81,8 @@ class Command { if (this.history.length > 0 && JSON.stringify(this.history[this.history.length - 1]) === JSON.stringify(data)) { return } + // 删除当前历史指针后面的数据 + this.history = this.history.slice(0, this.activeHistoryIndex + 1) this.history.push(simpleDeepClone(data)) this.activeHistoryIndex = this.history.length - 1 this.mindMap.emit('data_change', data) diff --git a/simple-mind-map/src/Render.js b/simple-mind-map/src/Render.js index 4c87a471..5c9a0b64 100644 --- a/simple-mind-map/src/Render.js +++ b/simple-mind-map/src/Render.js @@ -353,17 +353,26 @@ class Render { } } + // 规范指定节点数据 + formatAppointNodes(appointNodes) { + if (!appointNodes) return [] + return Array.isArray(appointNodes) ? appointNodes: [appointNodes] + } + // 插入同级节点,多个节点只会操作第一个节点 - insertNode(openEdit = true) { - if (this.activeNodeList.length <= 0) { + insertNode(openEdit = true, appointNodes = [], appointData = null) { + appointNodes = this.formatAppointNodes(appointNodes) + if (this.activeNodeList.length <= 0 && appointNodes.length <= 0) { return } - let first = this.activeNodeList[0] + let { defaultInsertSecondLevelNodeText, defaultInsertBelowSecondLevelNodeText } = this.mindMap.opt + let list = appointNodes.length > 0 ? appointNodes : this.activeNodeList + let first = list[0] if (first.isRoot) { - this.insertChildNode() + this.insertChildNode(openEdit, appointNodes, appointData) } else { - let text = first.layerIndex === 1 ? '二级节点' : '分支主题' + let text = first.layerIndex === 1 ? defaultInsertSecondLevelNodeText : defaultInsertBelowSecondLevelNodeText if (first.layerIndex === 1) { first.parent.initRender = true } @@ -372,7 +381,8 @@ class Render { inserting: openEdit, data: { text: text, - expand: true + expand: true, + ...(appointData || {}) }, children: [] }) @@ -382,20 +392,24 @@ class Render { // 插入子节点 - insertChildNode(openEdit = true) { - if (this.activeNodeList.length <= 0) { + insertChildNode(openEdit = true, appointNodes = [], appointData = null) { + appointNodes = this.formatAppointNodes(appointNodes) + if (this.activeNodeList.length <= 0 && appointNodes.length <= 0) { return } - this.activeNodeList.forEach(node => { + let { defaultInsertSecondLevelNodeText, defaultInsertBelowSecondLevelNodeText } = this.mindMap.opt + let list = appointNodes.length > 0 ? appointNodes : this.activeNodeList + list.forEach(node => { if (!node.nodeData.children) { node.nodeData.children = [] } - let text = node.isRoot ? '二级节点' : '分支主题' + let text = node.isRoot ? defaultInsertSecondLevelNodeText : defaultInsertBelowSecondLevelNodeText node.nodeData.children.push({ inserting: openEdit, data: { text: text, - expand: true + expand: true, + ...(appointData || {}) }, children: [] }) @@ -548,11 +562,14 @@ class Render { // 移除节点 - removeNode() { - if (this.activeNodeList.length <= 0) { + removeNode(appointNodes = []) { + appointNodes = this.formatAppointNodes(appointNodes) + if (this.activeNodeList.length <= 0 && appointNodes.length <= 0) { return } - let root = this.activeNodeList.find((node) => { + let isAppointNodes = appointNodes.length > 0 + let list = isAppointNodes ? appointNodes : this.activeNodeList + let root = list.find((node) => { return node.isRoot }) if (root) { @@ -563,8 +580,9 @@ class Render { root.children = [] root.nodeData.children = [] } else { - for (let i = 0; i < this.activeNodeList.length; i++) { - let node = this.activeNodeList[i] + for (let i = 0; i < list.length; i++) { + let node = list[i] + if (isAppointNodes) list.splice(i, 1) if (node.isGeneralization) { // 删除概要节点 this.setNodeData(node.generalizationBelongNode, { @@ -580,8 +598,7 @@ class Render { } } } - this.activeNodeList = [] - this.mindMap.emit('node_active', null, []) + this.mindMap.emit('node_active', null, this.activeNodeList) this.mindMap.render() }