Feat:优化水印插件

This commit is contained in:
wanglin2 2023-10-11 11:36:54 +08:00
parent 88fa6225eb
commit a316d0f0fe

View File

@ -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)