2024-04-08 14:04:08 +08:00
|
|
|
import React from 'react';
|
2023-07-07 09:54:19 +08:00
|
|
|
import {
|
|
|
|
DownloadOutlined,
|
2024-09-11 23:32:37 +08:00
|
|
|
LeftOutlined,
|
|
|
|
RightOutlined,
|
2023-07-07 09:54:19 +08:00
|
|
|
RotateLeftOutlined,
|
|
|
|
RotateRightOutlined,
|
|
|
|
SwapOutlined,
|
2024-06-22 21:59:12 +08:00
|
|
|
UndoOutlined,
|
2023-07-07 09:54:19 +08:00
|
|
|
ZoomInOutlined,
|
|
|
|
ZoomOutOutlined,
|
|
|
|
} from '@ant-design/icons';
|
2023-07-28 16:17:43 +08:00
|
|
|
import { Image, Space } from 'antd';
|
2023-06-21 19:58:28 +08:00
|
|
|
|
2024-09-11 23:32:37 +08:00
|
|
|
const imageList = [
|
|
|
|
'https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg',
|
|
|
|
'https://gw.alipayobjects.com/zos/antfincdn/aPkFc8Sj7n/method-draw-image.svg',
|
|
|
|
];
|
2023-06-21 19:58:28 +08:00
|
|
|
|
2024-07-11 04:59:22 +08:00
|
|
|
// you can download flipped and rotated image
|
|
|
|
// https://codesandbox.io/s/zi-ding-yi-gong-ju-lan-antd-5-7-0-forked-c9jvmp
|
2024-09-11 23:32:37 +08:00
|
|
|
const App: React.FC = () => {
|
|
|
|
const [current, setCurrent] = React.useState(0);
|
|
|
|
|
|
|
|
// or you can download flipped and rotated image
|
|
|
|
// https://codesandbox.io/s/zi-ding-yi-gong-ju-lan-antd-5-7-0-forked-c9jvmp
|
|
|
|
const onDownload = () => {
|
|
|
|
const url = imageList[current];
|
|
|
|
const suffix = url.slice(url.lastIndexOf('.'));
|
|
|
|
const filename = Date.now() + suffix;
|
2023-06-21 19:58:28 +08:00
|
|
|
|
2024-09-11 23:32:37 +08:00
|
|
|
fetch(url)
|
|
|
|
.then((response) => response.blob())
|
|
|
|
.then((blob) => {
|
|
|
|
const blobUrl = URL.createObjectURL(new Blob([blob]));
|
|
|
|
const link = document.createElement('a');
|
|
|
|
link.href = blobUrl;
|
|
|
|
link.download = filename;
|
|
|
|
document.body.appendChild(link);
|
|
|
|
link.click();
|
|
|
|
URL.revokeObjectURL(blobUrl);
|
|
|
|
link.remove();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Image.PreviewGroup
|
|
|
|
preview={{
|
|
|
|
toolbarRender: (
|
|
|
|
_,
|
|
|
|
{
|
|
|
|
transform: { scale },
|
|
|
|
actions: {
|
|
|
|
onActive,
|
|
|
|
onFlipY,
|
|
|
|
onFlipX,
|
|
|
|
onRotateLeft,
|
|
|
|
onRotateRight,
|
|
|
|
onZoomOut,
|
|
|
|
onZoomIn,
|
|
|
|
onReset,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
) => (
|
|
|
|
<Space size={12} className="toolbar-wrapper">
|
|
|
|
<LeftOutlined onClick={() => onActive?.(-1)} />
|
|
|
|
<RightOutlined onClick={() => onActive?.(1)} />
|
|
|
|
<DownloadOutlined onClick={onDownload} />
|
|
|
|
<SwapOutlined rotate={90} onClick={onFlipY} />
|
|
|
|
<SwapOutlined onClick={onFlipX} />
|
|
|
|
<RotateLeftOutlined onClick={onRotateLeft} />
|
|
|
|
<RotateRightOutlined onClick={onRotateRight} />
|
|
|
|
<ZoomOutOutlined disabled={scale === 1} onClick={onZoomOut} />
|
|
|
|
<ZoomInOutlined disabled={scale === 50} onClick={onZoomIn} />
|
|
|
|
<UndoOutlined onClick={onReset} />
|
|
|
|
</Space>
|
|
|
|
),
|
|
|
|
onChange: (index) => {
|
|
|
|
setCurrent(index);
|
2024-07-11 04:59:22 +08:00
|
|
|
},
|
2024-09-11 23:32:37 +08:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{imageList.map((item) => (
|
|
|
|
<Image key={item} src={item} width={200} />
|
|
|
|
))}
|
|
|
|
</Image.PreviewGroup>
|
|
|
|
);
|
|
|
|
};
|
2024-07-11 04:59:22 +08:00
|
|
|
|
2023-06-21 19:58:28 +08:00
|
|
|
export default App;
|