Skip to content

Commit

Permalink
🐛 fix: pdf preview
Browse files Browse the repository at this point in the history
  • Loading branch information
eternallycyf committed Dec 14, 2024
1 parent 273e568 commit 6e2b160
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
8 changes: 8 additions & 0 deletions packages/ims-view-pc/src/components/FileUpload/demo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ const App: React.FC = () => {
fileId: 'excelxlsx',
url: 'https://ims-view-pc-eternallycyfs-projects.vercel.app/excel.xlsx',
},
{
fileName: 'pdf.pdf',
id: 'rc-upload-1734098585253-16',
status: 'done',
percent: 100,
fileId: 'pdf',
url: 'https://ims-view-pc-eternallycyfs-projects.vercel.app/pdf.pdf',
},
],
}}
formList={[
Expand Down
11 changes: 9 additions & 2 deletions packages/ims-view-pc/src/components/FileViewer/FileViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { message, Modal } from 'antd';
import axios from 'axios';
import React, { PureComponent } from 'react';
import { ExcelRenderer } from 'react-excel-renderer';
import FileView from './FileView';
Expand Down Expand Up @@ -34,7 +35,7 @@ class FilePreView extends PureComponent<any, any> {
};
}
//显隐状态的改变
controlIsShow = (params: {
controlIsShow = async (params: {
src?: string;
base64?: string;
originFileObj?: any;
Expand All @@ -50,7 +51,13 @@ class FilePreView extends PureComponent<any, any> {
return message.error('该文件不支持预览');
}
if (fileType == 'xlsx') {
ExcelRenderer(originFileObj, (err: Error, resp: any) => {
const url = src;
const res = await axios.get(url, {
responseType: 'blob',
});

const blob = res.data;
ExcelRenderer(blob, (err: Error, resp: any) => {
this.setState({
excelData: {
cols: resp.cols,
Expand Down
Binary file added public/images/pdf.pdf
Binary file not shown.

0 comments on commit 6e2b160

Please sign in to comment.