2022-12-08 18:06:36 +08:00
|
|
|
|
---
|
|
|
|
|
category: Components
|
|
|
|
|
subtitle: 水印
|
2023-08-08 19:48:41 +08:00
|
|
|
|
group: 反馈
|
2022-12-08 18:06:36 +08:00
|
|
|
|
title: Watermark
|
|
|
|
|
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
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
给页面的某个区域加上水印。
|
|
|
|
|
|
|
|
|
|
## 何时使用
|
|
|
|
|
|
|
|
|
|
- 页面需要添加水印标识版权时使用。
|
|
|
|
|
- 适用于防止信息盗用。
|
|
|
|
|
|
|
|
|
|
## 代码演示
|
|
|
|
|
|
|
|
|
|
<!-- 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)
|
|
|
|
|
|
2022-12-08 18:06:36 +08:00
|
|
|
|
### Watermark
|
|
|
|
|
|
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
|
| width | 水印的宽度,`content` 的默认值为自身的宽度 | number | 120 | |
|
|
|
|
|
| height | 水印的高度,`content` 的默认值为自身的高度 | number | 64 | |
|
|
|
|
|
| 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 -->
|
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
|
| color | 字体颜色 | string | rgba(0,0,0,.15) | |
|
|
|
|
|
| fontSize | 字体大小 | number | 16 | |
|
|
|
|
|
| fontWeight | 字体粗细 | `normal` \| `light` \| `weight` \| number | normal | |
|
|
|
|
|
| fontFamily | 字体类型 | string | sans-serif | |
|
|
|
|
|
| fontStyle | 字体样式 | `none` \| `normal` \| `italic` \| `oblique` | normal | |
|
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>
|
|
|
|
|
```
|