From 1cd4705ad887602fdca7ade152bd2346ddcb83d0 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, 12 Aug 2024 10:36:05 +0800 Subject: [PATCH] =?UTF-8?q?Feat=EF=BC=9A=E6=94=AF=E6=8C=81=E4=B8=8D?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=B1=95=E5=BC=80=E6=94=B6=E8=B5=B7=E6=8C=89?= =?UTF-8?q?=E9=92=AE=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 --- .../src/constants/defaultOptions.js | 8 ++-- simple-mind-map/src/core/render/node/Node.js | 39 ++++++++++--------- .../src/core/render/node/nodeExpandBtn.js | 6 ++- .../node/nodeExpandBtnPlaceholderRect.js | 5 ++- .../src/layouts/CatalogOrganization.js | 3 +- simple-mind-map/src/layouts/Fishbone.js | 3 +- .../src/layouts/LogicalStructure.js | 9 +++-- simple-mind-map/src/layouts/MindMap.js | 9 +++-- .../src/layouts/OrganizationStructure.js | 3 +- simple-mind-map/src/layouts/Timeline.js | 3 +- .../src/layouts/VerticalTimeline.js | 9 +++-- simple-mind-map/src/plugins/Export.js | 3 +- 12 files changed, 61 insertions(+), 39 deletions(-) diff --git a/simple-mind-map/src/constants/defaultOptions.js b/simple-mind-map/src/constants/defaultOptions.js index 4874af62..5da7c1c6 100644 --- a/simple-mind-map/src/constants/defaultOptions.js +++ b/simple-mind-map/src/constants/defaultOptions.js @@ -86,6 +86,8 @@ export const defaultOpt = { maxHistoryCount: 500, // 是否一直显示节点的展开收起按钮,默认为鼠标移上去和激活时才显示 alwaysShowExpandBtn: false, + // 不显示展开收起按钮,优先级比alwaysShowExpandBtn配置高 + notShowExpandBtn: false, // 扩展节点可插入的图标 iconList: [ // { @@ -232,9 +234,9 @@ export const defaultOpt = { openPerformance: false, // 性能优化模式配置 performanceConfig: { - time: 250,// 当视图改变后多久刷新一次节点,单位:ms, - padding: 100,// 超出画布四周指定范围内依旧渲染节点 - removeNodeWhenOutCanvas: true,// 节点移除画布可视区域后从画布删除 + time: 250, // 当视图改变后多久刷新一次节点,单位:ms, + padding: 100, // 超出画布四周指定范围内依旧渲染节点 + removeNodeWhenOutCanvas: true // 节点移除画布可视区域后从画布删除 }, // 【Select插件】 diff --git a/simple-mind-map/src/core/render/node/Node.js b/simple-mind-map/src/core/render/node/Node.js index e1bd996c..741befe3 100644 --- a/simple-mind-map/src/core/render/node/Node.js +++ b/simple-mind-map/src/core/render/node/Node.js @@ -688,25 +688,28 @@ class Node { return } this.updateNodeActiveClass() - let { alwaysShowExpandBtn } = this.mindMap.opt - const childrenLength = this.nodeData.children.length - if (alwaysShowExpandBtn) { - // 需要移除展开收缩按钮 - if (this._expandBtn && childrenLength <= 0) { - this.removeExpandBtn() + const { alwaysShowExpandBtn, notShowExpandBtn } = this.mindMap.opt + // 不显示展开收起按钮则不需要处理 + if (!notShowExpandBtn) { + const childrenLength = this.nodeData.children.length + if (alwaysShowExpandBtn) { + // 需要移除展开收缩按钮 + if (this._expandBtn && childrenLength <= 0) { + this.removeExpandBtn() + } else { + // 更新展开收起按钮 + this.renderExpandBtn() + } } else { - // 更新展开收起按钮 - this.renderExpandBtn() - } - } else { - let { isActive, expand } = this.getData() - // 展开状态且非激活状态,且当前鼠标不在它上面,才隐藏 - if (childrenLength <= 0) { - this.removeExpandBtn() - } else if (expand && !isActive && !this._isMouseenter) { - this.hideExpandBtn() - } else { - this.showExpandBtn() + let { isActive, expand } = this.getData() + // 展开状态且非激活状态,且当前鼠标不在它上面,才隐藏 + if (childrenLength <= 0) { + this.removeExpandBtn() + } else if (expand && !isActive && !this._isMouseenter) { + this.hideExpandBtn() + } else { + this.showExpandBtn() + } } } // 更新概要 diff --git a/simple-mind-map/src/core/render/node/nodeExpandBtn.js b/simple-mind-map/src/core/render/node/nodeExpandBtn.js index 16001d15..87941fde 100644 --- a/simple-mind-map/src/core/render/node/nodeExpandBtn.js +++ b/simple-mind-map/src/core/render/node/nodeExpandBtn.js @@ -148,7 +148,8 @@ function removeExpandBtn() { // 显示展开收起按钮 function showExpandBtn() { - if (this.mindMap.opt.alwaysShowExpandBtn) return + const { alwaysShowExpandBtn, notShowExpandBtn } = this.mindMap.opt + if (alwaysShowExpandBtn || notShowExpandBtn) return setTimeout(() => { this.renderExpandBtn() }, 0) @@ -156,7 +157,8 @@ function showExpandBtn() { // 隐藏展开收起按钮 function hideExpandBtn() { - if (this.mindMap.opt.alwaysShowExpandBtn || this._isMouseenter) return + const { alwaysShowExpandBtn, notShowExpandBtn } = this.mindMap.opt + if (alwaysShowExpandBtn || this._isMouseenter || notShowExpandBtn) return // 非激活状态且展开状态鼠标移出才隐藏按钮 let { isActive, expand } = this.getData() if (!isActive && expand) { diff --git a/simple-mind-map/src/core/render/node/nodeExpandBtnPlaceholderRect.js b/simple-mind-map/src/core/render/node/nodeExpandBtnPlaceholderRect.js index 23d51ff4..da6410a5 100644 --- a/simple-mind-map/src/core/render/node/nodeExpandBtnPlaceholderRect.js +++ b/simple-mind-map/src/core/render/node/nodeExpandBtnPlaceholderRect.js @@ -10,8 +10,9 @@ function renderExpandBtnPlaceholderRect() { ) { return } - // 默认显示展开按钮的情况下也不需要渲染 - if (!this.mindMap.opt.alwaysShowExpandBtn) { + // 默认显示展开按钮的情况下或不显示展开收起按钮的情况下不需要渲染 + const { alwaysShowExpandBtn, notShowExpandBtn } = this.mindMap.opt + if (!alwaysShowExpandBtn && !notShowExpandBtn) { let { width, height } = this if (!this._unVisibleRectRegionNode) { this._unVisibleRectRegionNode = new Rect() diff --git a/simple-mind-map/src/layouts/CatalogOrganization.js b/simple-mind-map/src/layouts/CatalogOrganization.js index a5150232..7fc01868 100644 --- a/simple-mind-map/src/layouts/CatalogOrganization.js +++ b/simple-mind-map/src/layouts/CatalogOrganization.js @@ -204,7 +204,8 @@ class CatalogOrganization extends Base { return [] } let { left, top, width, height, expandBtnSize } = node - if (!this.mindMap.opt.alwaysShowExpandBtn) { + const { alwaysShowExpandBtn, notShowExpandBtn } = this.mindMap.opt + if (!alwaysShowExpandBtn || notShowExpandBtn) { expandBtnSize = 0 } let len = node.children.length diff --git a/simple-mind-map/src/layouts/Fishbone.js b/simple-mind-map/src/layouts/Fishbone.js index 3eb38c97..cf3ce45f 100644 --- a/simple-mind-map/src/layouts/Fishbone.js +++ b/simple-mind-map/src/layouts/Fishbone.js @@ -233,7 +233,8 @@ class Fishbone extends Base { return [] } let { top, height, expandBtnSize } = node - if (!this.mindMap.opt.alwaysShowExpandBtn) { + const { alwaysShowExpandBtn, notShowExpandBtn } = this.mindMap.opt + if (!alwaysShowExpandBtn || notShowExpandBtn) { expandBtnSize = 0 } let len = node.children.length diff --git a/simple-mind-map/src/layouts/LogicalStructure.js b/simple-mind-map/src/layouts/LogicalStructure.js index d866f1d0..ff3b6051 100644 --- a/simple-mind-map/src/layouts/LogicalStructure.js +++ b/simple-mind-map/src/layouts/LogicalStructure.js @@ -174,7 +174,8 @@ class LogicalStructure extends Base { return [] } let { left, top, width, height, expandBtnSize } = node - if (!this.mindMap.opt.alwaysShowExpandBtn) { + const { alwaysShowExpandBtn, notShowExpandBtn } = this.mindMap.opt + if (!alwaysShowExpandBtn || notShowExpandBtn) { expandBtnSize = 0 } let marginX = this.getMarginX(node.layerIndex + 1) @@ -215,7 +216,8 @@ class LogicalStructure extends Base { return [] } let { left, top, width, height, expandBtnSize } = node - if (!this.mindMap.opt.alwaysShowExpandBtn) { + const { alwaysShowExpandBtn, notShowExpandBtn } = this.mindMap.opt + if (!alwaysShowExpandBtn || notShowExpandBtn) { expandBtnSize = 0 } const { nodeUseLineStyle } = this.mindMap.themeConfig @@ -246,7 +248,8 @@ class LogicalStructure extends Base { return [] } let { left, top, width, height, expandBtnSize } = node - if (!this.mindMap.opt.alwaysShowExpandBtn) { + const { alwaysShowExpandBtn, notShowExpandBtn } = this.mindMap.opt + if (!alwaysShowExpandBtn || notShowExpandBtn) { expandBtnSize = 0 } const { diff --git a/simple-mind-map/src/layouts/MindMap.js b/simple-mind-map/src/layouts/MindMap.js index 8f616bc1..156a67df 100644 --- a/simple-mind-map/src/layouts/MindMap.js +++ b/simple-mind-map/src/layouts/MindMap.js @@ -213,7 +213,8 @@ class MindMap extends Base { return [] } let { left, top, width, height, expandBtnSize } = node - if (!this.mindMap.opt.alwaysShowExpandBtn) { + const { alwaysShowExpandBtn, notShowExpandBtn } = this.mindMap.opt + if (!alwaysShowExpandBtn || notShowExpandBtn) { expandBtnSize = 0 } let marginX = this.getMarginX(node.layerIndex + 1) @@ -256,7 +257,8 @@ class MindMap extends Base { return [] } let { left, top, width, height, expandBtnSize } = node - if (!this.mindMap.opt.alwaysShowExpandBtn) { + const { alwaysShowExpandBtn, notShowExpandBtn } = this.mindMap.opt + if (!alwaysShowExpandBtn || notShowExpandBtn) { expandBtnSize = 0 } const { nodeUseLineStyle } = this.mindMap.themeConfig @@ -296,7 +298,8 @@ class MindMap extends Base { return [] } let { left, top, width, height, expandBtnSize } = node - if (!this.mindMap.opt.alwaysShowExpandBtn) { + const { alwaysShowExpandBtn, notShowExpandBtn } = this.mindMap.opt + if (!alwaysShowExpandBtn || notShowExpandBtn) { expandBtnSize = 0 } const { diff --git a/simple-mind-map/src/layouts/OrganizationStructure.js b/simple-mind-map/src/layouts/OrganizationStructure.js index bc8bb12b..b0a666b4 100644 --- a/simple-mind-map/src/layouts/OrganizationStructure.js +++ b/simple-mind-map/src/layouts/OrganizationStructure.js @@ -182,7 +182,8 @@ class OrganizationStructure extends Base { return [] } let { left, top, width, height, expandBtnSize, isRoot } = node - if (!this.mindMap.opt.alwaysShowExpandBtn) { + const { alwaysShowExpandBtn, notShowExpandBtn } = this.mindMap.opt + if (!alwaysShowExpandBtn || notShowExpandBtn) { expandBtnSize = 0 } let x1 = left + width / 2 diff --git a/simple-mind-map/src/layouts/Timeline.js b/simple-mind-map/src/layouts/Timeline.js index c0626a71..1917f397 100644 --- a/simple-mind-map/src/layouts/Timeline.js +++ b/simple-mind-map/src/layouts/Timeline.js @@ -232,7 +232,8 @@ class Timeline extends Base { return [] } let { left, top, width, height, expandBtnSize } = node - if (!this.mindMap.opt.alwaysShowExpandBtn) { + const { alwaysShowExpandBtn, notShowExpandBtn } = this.mindMap.opt + if (!alwaysShowExpandBtn || notShowExpandBtn) { expandBtnSize = 0 } let len = node.children.length diff --git a/simple-mind-map/src/layouts/VerticalTimeline.js b/simple-mind-map/src/layouts/VerticalTimeline.js index ac10d581..2ce28e71 100644 --- a/simple-mind-map/src/layouts/VerticalTimeline.js +++ b/simple-mind-map/src/layouts/VerticalTimeline.js @@ -234,7 +234,8 @@ class VerticalTimeline extends Base { return [] } let { expandBtnSize } = node - if (!this.mindMap.opt.alwaysShowExpandBtn) { + const { alwaysShowExpandBtn, notShowExpandBtn } = this.mindMap.opt + if (!alwaysShowExpandBtn || notShowExpandBtn) { expandBtnSize = 0 } if (node.isRoot) { @@ -293,7 +294,8 @@ class VerticalTimeline extends Base { return [] } let { left, top, width, height, expandBtnSize } = node - if (!this.mindMap.opt.alwaysShowExpandBtn) { + const { alwaysShowExpandBtn, notShowExpandBtn } = this.mindMap.opt + if (!alwaysShowExpandBtn || notShowExpandBtn) { expandBtnSize = 0 } node.children.forEach((item, index) => { @@ -331,7 +333,8 @@ class VerticalTimeline extends Base { return [] } let { left, top, width, height, expandBtnSize } = node - if (!this.mindMap.opt.alwaysShowExpandBtn) { + const { alwaysShowExpandBtn, notShowExpandBtn } = this.mindMap.opt + if (!alwaysShowExpandBtn || notShowExpandBtn) { expandBtnSize = 0 } node.children.forEach((item, index) => { diff --git a/simple-mind-map/src/plugins/Export.js b/simple-mind-map/src/plugins/Export.js index 79667f90..52413970 100644 --- a/simple-mind-map/src/plugins/Export.js +++ b/simple-mind-map/src/plugins/Export.js @@ -288,7 +288,8 @@ class Export { handleNodeExport(node) { if (node && node.getData('isActive')) { node.deactivate() - if (!this.mindMap.opt.alwaysShowExpandBtn && node.getData('expand')) { + const { alwaysShowExpandBtn, notShowExpandBtn } = this.mindMap.opt + if (!alwaysShowExpandBtn && !notShowExpandBtn && node.getData('expand')) { node.removeExpandBtn() } }