mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-05 09:49:57 +08:00
c7832505ae
* fix: fix ci fail * fix: fix ci fail * update rotationSlider prop
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { Upload } from 'antd';
|
|
import ImgCrop from 'antd-img-crop';
|
|
import type { RcFile, UploadFile, UploadProps } from 'antd/es/upload/interface';
|
|
import React, { useState } from 'react';
|
|
|
|
const App: React.FC = () => {
|
|
const [fileList, setFileList] = useState<UploadFile[]>([
|
|
{
|
|
uid: '-1',
|
|
name: 'image.png',
|
|
status: 'done',
|
|
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
|
},
|
|
]);
|
|
|
|
const onChange: UploadProps['onChange'] = ({ fileList: newFileList }) => {
|
|
setFileList(newFileList);
|
|
};
|
|
|
|
const onPreview = async (file: UploadFile) => {
|
|
let src = file.url as string;
|
|
if (!src) {
|
|
src = await new Promise((resolve) => {
|
|
const reader = new FileReader();
|
|
reader.readAsDataURL(file.originFileObj as RcFile);
|
|
reader.onload = () => resolve(reader.result as string);
|
|
});
|
|
}
|
|
const image = new Image();
|
|
image.src = src;
|
|
const imgWindow = window.open(src);
|
|
imgWindow?.document.write(image.outerHTML);
|
|
};
|
|
|
|
return (
|
|
<ImgCrop rotationSlider>
|
|
<Upload
|
|
action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
|
|
listType="picture-card"
|
|
fileList={fileList}
|
|
onChange={onChange}
|
|
onPreview={onPreview}
|
|
>
|
|
{fileList.length < 5 && '+ Upload'}
|
|
</Upload>
|
|
</ImgCrop>
|
|
);
|
|
};
|
|
|
|
export default App;
|