2024-05-10 10:38:39 +08:00
|
|
|
import { Images } from '@/constants/common';
|
2024-05-08 10:30:18 +08:00
|
|
|
import { api_host } from '@/utils/api';
|
2024-05-09 11:30:15 +08:00
|
|
|
import { Flex, Image } from 'antd';
|
2024-05-08 10:30:18 +08:00
|
|
|
import { useParams, useSearchParams } from 'umi';
|
2024-05-10 10:38:39 +08:00
|
|
|
import Docx from './docx';
|
2024-05-08 10:30:18 +08:00
|
|
|
import Excel from './excel';
|
2024-05-09 11:30:15 +08:00
|
|
|
import Pdf from './pdf';
|
2024-05-08 10:30:18 +08:00
|
|
|
|
|
|
|
|
import styles from './index.less';
|
|
|
|
|
|
2024-05-09 11:30:15 +08:00
|
|
|
// TODO: The interface returns an incorrect content-type for the SVG.
|
|
|
|
|
|
2024-05-08 10:30:18 +08:00
|
|
|
const DocumentViewer = () => {
|
|
|
|
|
const { id: documentId } = useParams();
|
|
|
|
|
const api = `${api_host}/file/get/${documentId}`;
|
|
|
|
|
const [currentQueryParameters] = useSearchParams();
|
|
|
|
|
const ext = currentQueryParameters.get('ext');
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<section className={styles.viewerWrapper}>
|
2024-05-09 11:30:15 +08:00
|
|
|
{Images.includes(ext!) && (
|
|
|
|
|
<Flex className={styles.image} align="center" justify="center">
|
|
|
|
|
<Image src={api} preview={false}></Image>
|
|
|
|
|
</Flex>
|
|
|
|
|
)}
|
|
|
|
|
{ext === 'pdf' && <Pdf url={api}></Pdf>}
|
|
|
|
|
{(ext === 'xlsx' || ext === 'xls') && <Excel filePath={api}></Excel>}
|
2024-05-10 10:38:39 +08:00
|
|
|
|
|
|
|
|
{ext === 'docx' && <Docx filePath={api}></Docx>}
|
2024-05-08 10:30:18 +08:00
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default DocumentViewer;
|