Skip to content

FxWatermark 水印

在页面或容器上覆盖水印(文本 / 多行 / 图片 / 富文本),支持防删除、暗水印。基于 watermark-js-plus不依赖任何 UI 框架

FxWatermark 属于 @fx/components

基础用法

<FxWatermark> 作为容器包裹内容,水印画在容器内。

多行文本

content-type="multi-line-text"content&#10;(换行符)分隔多行。

图片水印

content-type="image"image 传图片地址。

富文本

content-type="rich-text"content 传 HTML 片段。

描边水印

text-type="stroke" 用描边方式绘制文字(默认 fill 填充),适合需要强对比的场景。

网格布局

layout="grid" + grid-layout-options

防删除 + 动效

mutation-observe 监听 DOM 篡改自动恢复;monitor-protection 开启保护;movable 平移动效。

暗水印

blind 开启暗水印(肉眼几乎不可见)。配合 FxWatermarkDecoder 解析还原。

全局水印

不绑定容器,用 createWatermark(options, mode?) 盖全屏,返回库实例,自行 .create() / .destroy()

局部引入

ts
import {
  FxWatermark,
  createWatermark,
  decodeBlindWatermark,
  Watermark,
  BlindWatermark,
} from "@fx/components"

API

Attributes

属性说明类型默认值
blind暗水印(内部用 BlindWatermark)booleanfalse
disabled禁用水印(销毁已绘制水印;false 恢复重绘)——常驻包裹 + 开关显隐场景用booleanfalse
content内容(文本/多行/富文本)string
content-type内容类型'text' | 'image' | 'multi-line-text' | 'rich-text''text'
image图片水印地址(content-type=image)string
width / height水印画布宽高number库默认
rotate旋转角度number库默认
global-alpha透明度number库默认
z-index层级number库默认
text-type文本绘制方式(填充/描边)'fill' | 'stroke''fill'
font-size / font-color / font-weight / font-family字体string库默认
font-style / font-variant斜体/小型大写字母等string''
line-height行高(多行文本间距)number30
letter-spacing / word-spacing字间距/词间距string'0px'
text-align水平排布'start' | 'center' | 'end' | 'left' | 'right'随定位
text-baseline垂直基线'top' | 'middle' | 'bottom' | 'alphabetic' | …随定位
text-row-max-width单行最大宽度(多行自动换行)number同 width
rich-text-width / rich-text-height富文本宽高(content-type=rich-text)number
layout布局'default' | 'grid''default'
grid-layout-options网格布局GridLayoutOptions
auxiliary-line辅助线(调试画布边界)booleanfalse
background-position背景定位string'0 0'
background-repeat背景重复string'repeat'
movable平移动效booleanfalse
mutation-observeDOM 篡改监听(防删除)booleantrue
monitor-protection保护booleanfalse
translate-placement / translate-x / translate-y定位库默认
image-width / image-height图片水印尺寸number
advanced-style / shadow-style / extra-draw-func / filter高级绘制

完整字段见 watermark-js-plus WatermarkOptionsparent / mode 不对外(parent 固定根元素,mode 由 blind 映射)。

Events

事件说明载荷
success创建成功
before-destroy销毁前
destroyed销毁后
observe-errorMutationObserver 失败

Slots

名称说明
default水印覆盖的子内容

Exposes

名称说明类型
create创建水印() => Promise<void>
destroy销毁水印() => void
check检查水印是否存在() => Promise<boolean>
changeOptions更新配置(args, mode?, redraw?) => Promise<void>

全局 API

createWatermark(options, mode?)

创建水印实例(全局层面),返回库实例。

ts
const wm = createWatermark({ content: "悦安", globalAlpha: 0.5 })
wm.create()
wm.changeOptions({ content: "新文字" })
wm.destroy()

// 暗水印
const blind = createWatermark({ content: "secret" }, "blind")
blind.create()
参数类型说明
optionsWatermarkOptionswatermark-js-plus 配置
mode'default' | 'blind'缺省 'default'

同时 re-export 库原始类:Watermark / BlindWatermark / ImageWatermark,可直接 new Watermark(opts).create()