forked from XiaoMi/hiui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(preview): 增加水印示例和禁止下载示例(XiaoMi#2808)
- Loading branch information
xiamiao
committed
May 9, 2024
1 parent
9103ff9
commit 4906055
Showing
4 changed files
with
117 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react' | ||
import Preview from '../src' | ||
import Grid from '@hi-ui/grid' | ||
|
||
/** | ||
* @title 禁止右键下载 | ||
*/ | ||
export const Banned = () => { | ||
const [showIndex, setShowIndex] = React.useState(-1) | ||
const [images] = React.useState([ | ||
'http://i1.mifile.cn/f/i/hiui/docs/card/pic_1.png', | ||
'http://i1.mifile.cn/f/i/hiui/docs/card/pic_2.png', | ||
'http://i1.mifile.cn/f/i/hiui/docs/card/pic_3.png', | ||
'http://i1.mifile.cn/f/i/hiui/docs/card/pic_4.png', | ||
]) | ||
|
||
return ( | ||
<> | ||
<h1>Banned</h1> | ||
<div className="preview-banned__wrap"> | ||
<Preview | ||
title={`pic_${showIndex}.png`} | ||
src={images[showIndex]} | ||
visible={showIndex !== -1} | ||
ifAllowDownload={false} | ||
onClose={() => { | ||
setShowIndex(-1) | ||
}} | ||
/> | ||
|
||
<Grid.Row gutter={true}> | ||
{images.map((url, index) => { | ||
return ( | ||
<Grid.Col span={4} key={index}> | ||
<div> | ||
<img | ||
src={url} | ||
style={{ width: '100%', cursor: 'pointer' }} | ||
onClick={() => { | ||
setShowIndex(index) | ||
}} | ||
/> | ||
</div> | ||
</Grid.Col> | ||
) | ||
})} | ||
</Grid.Row> | ||
</div> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from 'react' | ||
import Preview from '../src' | ||
import Grid from '@hi-ui/grid' | ||
|
||
/** | ||
* @title 添加水印 | ||
*/ | ||
export const Watermark = () => { | ||
const [showIndex, setShowIndex] = React.useState(-1) | ||
const [images] = React.useState([ | ||
'http://i1.mifile.cn/f/i/hiui/docs/card/pic_1.png', | ||
'http://i1.mifile.cn/f/i/hiui/docs/card/pic_2.png', | ||
'http://i1.mifile.cn/f/i/hiui/docs/card/pic_3.png', | ||
'http://i1.mifile.cn/f/i/hiui/docs/card/pic_4.png', | ||
]) | ||
|
||
return ( | ||
<> | ||
<h1>Watermark</h1> | ||
<div className="preview-watermark__wrap"> | ||
<Preview | ||
title={`pic_${showIndex}.png`} | ||
src={images[showIndex]} | ||
visible={showIndex !== -1} | ||
onClose={() => { | ||
setShowIndex(-1) | ||
}} | ||
previewWatermarkProps={{ | ||
content: ['HiUI', '做中台,就用 HiUI'], | ||
style: { | ||
pointerEvents: 'none', | ||
position: 'fixed', | ||
top: 0, | ||
right: 0, | ||
bottom: 0, | ||
left: 0, | ||
zIndex: 2048, | ||
}, | ||
}} | ||
/> | ||
|
||
<Grid.Row gutter={true}> | ||
{images.map((url, index) => { | ||
return ( | ||
<Grid.Col span={4} key={index}> | ||
<div> | ||
<img | ||
src={url} | ||
style={{ width: '100%', cursor: 'pointer' }} | ||
onClick={() => { | ||
setShowIndex(index) | ||
}} | ||
/> | ||
</div> | ||
</Grid.Col> | ||
) | ||
})} | ||
</Grid.Row> | ||
</div> | ||
</> | ||
) | ||
} |