index.js 741 B

12345678910111213141516171819202122232425262728
  1. import FileViewer from 'react-file-viewer';
  2. import { Modal } from 'antd';
  3. import { memo } from 'react';
  4. const FileViewerModal = ({ url = '', visible, onCancel }) => {
  5. const type = url?.split('.')[url?.split('.').length - 1];
  6. console.log(url, type);
  7. return (
  8. <Modal
  9. title="预览"
  10. open={visible}
  11. width={1000}
  12. onCancel={onCancel}
  13. onOk={onCancel}
  14. bodyStyle={{ height: '680px', overflowY: 'hidden' }}
  15. >
  16. <FileViewer
  17. fileType={type}
  18. filePath={url}
  19. onError={() => console.log('Failed to load')}
  20. errorComponent={console.log('出现错误')}
  21. unsupportedComponent={console.log('不支持')}
  22. />
  23. </Modal>
  24. );
  25. };
  26. export default FileViewerModal;