import React, { useState } from 'react'; import { Upload } from 'antd'; import ImgCrop from 'antd-img-crop'; import type { RcFile, UploadFile, UploadProps } from 'antd/es/upload/interface'; const App: React.FC = () => { const [fileList, setFileList] = useState([ { 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 ( {fileList.length < 5 && '+ Upload'} ); }; export default App;