2022-12-08 18:06:36 +08:00
|
|
|
|
---
|
|
|
|
|
category: Components
|
2023-08-08 19:48:41 +08:00
|
|
|
|
group: 反馈
|
2022-12-08 18:06:36 +08:00
|
|
|
|
title: Watermark
|
2024-03-22 14:22:42 +08:00
|
|
|
|
subtitle: 水印
|
|
|
|
|
description: 给页面的某个区域加上水印。
|
2022-12-08 18:06:36 +08:00
|
|
|
|
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*wr1ISY50SyYAAAAAAAAAAAAADrJ8AQ/original
|
2023-02-09 22:17:31 +08:00
|
|
|
|
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*duAQQbjHlHQAAAAAAAAAAAAADrJ8AQ/original
|
2022-12-08 18:06:36 +08:00
|
|
|
|
demo:
|
|
|
|
|
cols: 1
|
2023-08-08 19:48:41 +08:00
|
|
|
|
tag: New
|
2022-12-08 18:06:36 +08:00
|
|
|
|
---
|
|
|
|
|
|
2024-03-22 14:22:42 +08:00
|
|
|
|
自 `5.0.0` 版本开始提供该组件。
|
2022-12-08 18:06:36 +08:00
|
|
|
|
|
|
|
|
|
## 何时使用
|
|
|
|
|
|
|
|
|
|
- 页面需要添加水印标识版权时使用。
|
|
|
|
|
- 适用于防止信息盗用。
|
|
|
|
|
|
|
|
|
|
## 代码演示
|
|
|
|
|
|
|
|
|
|
<!-- prettier-ignore -->
|
|
|
|
|
<code src="./demo/basic.tsx">基本</code>
|
|
|
|
|
<code src="./demo/multi-line.tsx">多行水印</code>
|
|
|
|
|
<code src="./demo/image.tsx">图片水印</code>
|
|
|
|
|
<code src="./demo/custom.tsx">自定义配置</code>
|
2023-08-08 16:48:26 +08:00
|
|
|
|
<code src="./demo/portal.tsx">Modal 与 Drawer</code>
|
2022-12-08 18:06:36 +08:00
|
|
|
|
|
|
|
|
|
## API
|
|
|
|
|
|
2023-08-08 18:27:48 +08:00
|
|
|
|
通用属性参考:[通用属性](/docs/react/common-props)
|
|
|
|
|
|
2024-01-13 14:27:42 +08:00
|
|
|
|
> 自 `antd@5.0.0` 版本开始提供该组件。
|
|
|
|
|
|
2022-12-08 18:06:36 +08:00
|
|
|
|
### Watermark
|
|
|
|
|
|
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
|
| width | 水印的宽度,`content` 的默认值为自身的宽度 | number | 120 | |
|
|
|
|
|
| height | 水印的高度,`content` 的默认值为自身的高度 | number | 64 | |
|
2023-10-13 15:16:08 +08:00
|
|
|
|
| inherit | 是否将水印传导给弹出组件如 Modal、Drawer | boolean | true | 5.11.0 |
|
2022-12-08 18:06:36 +08:00
|
|
|
|
| rotate | 水印绘制时,旋转的角度,单位 `°` | number | -22 | |
|
|
|
|
|
| zIndex | 追加的水印元素的 z-index | number | 9 | |
|
2023-02-28 11:20:15 +08:00
|
|
|
|
| image | 图片源,建议导出 2 倍或 3 倍图,优先级高 (支持 base64 格式) | string | - | |
|
2022-12-08 18:06:36 +08:00
|
|
|
|
| content | 水印文字内容 | string \| string[] | - | |
|
2022-12-22 14:12:26 +08:00
|
|
|
|
| font | 文字样式 | [Font](#font) | [Font](#font) | |
|
2022-12-13 15:47:57 +08:00
|
|
|
|
| gap | 水印之间的间距 | \[number, number\] | \[100, 100\] | |
|
2022-12-08 18:06:36 +08:00
|
|
|
|
| offset | 水印距离容器左上角的偏移量,默认为 `gap/2` | \[number, number\] | \[gap\[0\]/2, gap\[1\]/2\] | |
|
|
|
|
|
|
|
|
|
|
### Font
|
|
|
|
|
|
|
|
|
|
<!-- prettier-ignore -->
|
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
2023-09-18 09:56:32 +08:00
|
|
|
|
| color | 字体颜色 | [CanvasFillStrokeStyles.fillStyle](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/fillStyle) | rgba(0,0,0,.15) | |
|
2022-12-08 18:06:36 +08:00
|
|
|
|
| fontSize | 字体大小 | number | 16 | |
|
|
|
|
|
| fontWeight | 字体粗细 | `normal` \| `light` \| `weight` \| number | normal | |
|
|
|
|
|
| fontFamily | 字体类型 | string | sans-serif | |
|
|
|
|
|
| fontStyle | 字体样式 | `none` \| `normal` \| `italic` \| `oblique` | normal | |
|
2023-09-18 09:56:32 +08:00
|
|
|
|
| textAlign | 指定文本对齐方向 | [CanvasTextAlign](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/textAlign) | 5.10.0 |
|
2023-02-28 11:20:15 +08:00
|
|
|
|
|
2023-08-30 23:02:35 +08:00
|
|
|
|
## 主题变量(Design Token)
|
2023-04-11 10:25:24 +08:00
|
|
|
|
|
|
|
|
|
<ComponentTokenTable component="Watermark"></ComponentTokenTable>
|
|
|
|
|
|
2023-02-28 11:20:15 +08:00
|
|
|
|
## FAQ
|
|
|
|
|
|
|
|
|
|
### 处理异常图片水印
|
|
|
|
|
|
|
|
|
|
当使用图片水印且图片加载异常时,可以同时添加 `content` 防止水印失效(自 5.2.3 开始支持)。
|
|
|
|
|
|
|
|
|
|
```typescript jsx
|
|
|
|
|
<Watermark
|
|
|
|
|
height={30}
|
|
|
|
|
width={130}
|
|
|
|
|
content="Ant Design"
|
|
|
|
|
image="https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*lkAoRbywo0oAAAAAAAAAAAAADrJ8AQ/original"
|
|
|
|
|
>
|
|
|
|
|
<div style={{ height: 500 }} />
|
|
|
|
|
</Watermark>
|
|
|
|
|
```
|