Feat:优化水印插件
This commit is contained in:
parent
88fa6225eb
commit
a316d0f0fe
@ -11,15 +11,31 @@ class Watermark {
|
|||||||
this.angle = 0 // 旋转角度
|
this.angle = 0 // 旋转角度
|
||||||
this.text = '' // 水印文字
|
this.text = '' // 水印文字
|
||||||
this.textStyle = {} // 水印文字样式
|
this.textStyle = {} // 水印文字样式
|
||||||
this.watermarkDraw = this.mindMap.svg
|
this.watermarkDraw = null // 容器
|
||||||
.group()
|
|
||||||
.css({ 'pointer-events': 'none', 'user-select': 'none' })
|
|
||||||
this.maxLong = Math.sqrt(
|
this.maxLong = 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 || {})
|
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() {
|
hasWatermark() {
|
||||||
return !!this.text.trim()
|
return !!this.text.trim()
|
||||||
@ -40,10 +56,14 @@ class Watermark {
|
|||||||
// 绘制水印
|
// 绘制水印
|
||||||
// 非精确绘制,会绘制一些超出可视区域的水印
|
// 非精确绘制,会绘制一些超出可视区域的水印
|
||||||
draw() {
|
draw() {
|
||||||
this.watermarkDraw.clear()
|
// 清空之前的水印
|
||||||
|
if (this.watermarkDraw) this.watermarkDraw.clear()
|
||||||
|
// 如果没有水印数据,那么水印容器也删除掉
|
||||||
if (!this.hasWatermark()) {
|
if (!this.hasWatermark()) {
|
||||||
|
this.removeContainer()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
this.createContainer()
|
||||||
let x = 0
|
let x = 0
|
||||||
while (x < this.mindMap.width) {
|
while (x < this.mindMap.width) {
|
||||||
this.drawText(x)
|
this.drawText(x)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user