Fix:修复容器尺寸改变后没有水印没有重新绘制的问题

This commit is contained in:
wanglin2 2023-10-17 16:01:03 +08:00
parent 8466a3e99f
commit 9e4652b7b5
2 changed files with 32 additions and 2 deletions

View File

@ -190,6 +190,7 @@ class MindMap {
resize() { resize() {
this.getElRectInfo() this.getElRectInfo()
this.svg.size(this.width, this.height) this.svg.size(this.width, this.height)
this.emit('resize')
} }
// 监听事件 // 监听事件

View File

@ -12,10 +12,29 @@ class Watermark {
this.text = '' // 水印文字 this.text = '' // 水印文字
this.textStyle = {} // 水印文字样式 this.textStyle = {} // 水印文字样式
this.watermarkDraw = null // 容器 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) 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.handleConfig(config)
this.draw() this.draw()
} }
// 插件被移除前做的事情
beforePluginRemove() {
this.unBindEvent()
}
// 插件被卸载前做的事情
beforePluginDestroy() {
this.unBindEvent()
}
} }
Watermark.instanceName = 'watermark' Watermark.instanceName = 'watermark'