From 8f8c6c9d95605cb6773144f5b7d47571536d177b 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: Thu, 5 Sep 2024 18:21:38 +0800 Subject: [PATCH] =?UTF-8?q?Feat=EF=BC=9AexpandBtnNumHandler=E9=80=89?= =?UTF-8?q?=E9=A1=B9=E6=96=B0=E5=A2=9E=E8=8A=82=E7=82=B9=E5=AE=9E=E4=BE=8B?= =?UTF-8?q?=E7=9A=84=E5=9B=9E=E8=B0=83=E5=8F=82=E6=95=B0?= 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/core/render/node/nodeExpandBtn.js | 8 +++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/simple-mind-map/src/constants/defaultOptions.js b/simple-mind-map/src/constants/defaultOptions.js index 886b914d..71510f26 100644 --- a/simple-mind-map/src/constants/defaultOptions.js +++ b/simple-mind-map/src/constants/defaultOptions.js @@ -67,9 +67,7 @@ export const defaultOpt = { close: '' }, // 处理收起节点数量 - expandBtnNumHandler: num => { - return num - }, + expandBtnNumHandler: null, // 是否显示带数量的收起按钮 isShowExpandNum: true, // 是否只有当鼠标在画布内才响应快捷键事件 diff --git a/simple-mind-map/src/core/render/node/nodeExpandBtn.js b/simple-mind-map/src/core/render/node/nodeExpandBtn.js index 87941fde..baf26b36 100644 --- a/simple-mind-map/src/core/render/node/nodeExpandBtn.js +++ b/simple-mind-map/src/core/render/node/nodeExpandBtn.js @@ -1,5 +1,6 @@ import btnsSvg from '../../../svg/btns' import { SVG, Circle, G, Text } from '@svgdotjs/svg.js' +import { isUndef } from '../../../utils' // 创建展开收起按钮的内容节点 function createExpandNodeContent() { @@ -78,7 +79,12 @@ function updateExpandBtnNode() { }) // 计算子节点数量 let count = this.sumNode(this.nodeData.children) - count = expandBtnNumHandler(count) + if (typeof expandBtnNumHandler === 'function') { + const res = expandBtnNumHandler(count, this) + if (!isUndef(res)) { + count = res + } + } node.text(String(count)) } else { this._fillExpandNode.stroke('none')