From 9e4652b7b501e05d2d66c41a887961ca2e123be2 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Tue, 17 Oct 2023 16:01:03 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E5=AE=B9?= =?UTF-8?q?=E5=99=A8=E5=B0=BA=E5=AF=B8=E6=94=B9=E5=8F=98=E5=90=8E=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E6=B0=B4=E5=8D=B0=E6=B2=A1=E6=9C=89=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E7=BB=98=E5=88=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/index.js | 1 + simple-mind-map/src/plugins/Watermark.js | 33 ++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/simple-mind-map/index.js b/simple-mind-map/index.js index 70c1a7bd..42bd6508 100644 --- a/simple-mind-map/index.js +++ b/simple-mind-map/index.js @@ -190,6 +190,7 @@ class MindMap { resize() { this.getElRectInfo() this.svg.size(this.width, this.height) + this.emit('resize') } // 监听事件 diff --git a/simple-mind-map/src/plugins/Watermark.js b/simple-mind-map/src/plugins/Watermark.js index 3d8a99bb..b9597598 100644 --- a/simple-mind-map/src/plugins/Watermark.js +++ b/simple-mind-map/src/plugins/Watermark.js @@ -12,10 +12,29 @@ class Watermark { this.text = '' // 水印文字 this.textStyle = {} // 水印文字样式 this.watermarkDraw = null // 容器 - this.maxLong = Math.sqrt( + this.maxLong = this.getMaxLong() + this.updateWatermark(this.mindMap.opt.watermarkConfig || {}) + this.bindEvent() + } + + getMaxLong() { + return Math.sqrt( Math.pow(this.mindMap.width, 2) + Math.pow(this.mindMap.height, 2) ) - this.updateWatermark(this.mindMap.opt.watermarkConfig || {}) + } + + bindEvent() { + this.onResize = this.onResize.bind(this) + this.mindMap.on('resize', this.onResize) + } + + unBindEvent() { + this.mindMap.off('resize', this.onResize) + } + + onResize() { + this.maxLong = this.getMaxLong() + this.draw() } // 创建水印容器 @@ -136,6 +155,16 @@ class Watermark { this.handleConfig(config) this.draw() } + + // 插件被移除前做的事情 + beforePluginRemove() { + this.unBindEvent() + } + + // 插件被卸载前做的事情 + beforePluginDestroy() { + this.unBindEvent() + } } Watermark.instanceName = 'watermark'