diff --git a/simple-mind-map/src/plugins/Watermark.js b/simple-mind-map/src/plugins/Watermark.js index c511be50..3d8a99bb 100644 --- a/simple-mind-map/src/plugins/Watermark.js +++ b/simple-mind-map/src/plugins/Watermark.js @@ -11,15 +11,31 @@ class Watermark { this.angle = 0 // 旋转角度 this.text = '' // 水印文字 this.textStyle = {} // 水印文字样式 - this.watermarkDraw = this.mindMap.svg - .group() - .css({ 'pointer-events': 'none', 'user-select': 'none' }) + this.watermarkDraw = null // 容器 this.maxLong = Math.sqrt( Math.pow(this.mindMap.width, 2) + Math.pow(this.mindMap.height, 2) ) this.updateWatermark(this.mindMap.opt.watermarkConfig || {}) } + // 创建水印容器 + createContainer() { + if (this.watermarkDraw) return + this.watermarkDraw = this.mindMap.svg + .group() + .css({ 'pointer-events': 'none', 'user-select': 'none' }) + .addClass('smm-water-mark-container') + } + + // 删除水印容器 + removeContainer() { + if (!this.watermarkDraw) { + return + } + this.watermarkDraw.remove() + this.watermarkDraw = null + } + // 获取是否存在水印 hasWatermark() { return !!this.text.trim() @@ -40,10 +56,14 @@ class Watermark { // 绘制水印 // 非精确绘制,会绘制一些超出可视区域的水印 draw() { - this.watermarkDraw.clear() + // 清空之前的水印 + if (this.watermarkDraw) this.watermarkDraw.clear() + // 如果没有水印数据,那么水印容器也删除掉 if (!this.hasWatermark()) { + this.removeContainer() return } + this.createContainer() let x = 0 while (x < this.mindMap.width) { this.drawText(x)