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'