From fe5f9dbb2dd7596b9c6ae4a57bed9ed2e27e03fc Mon Sep 17 00:00:00 2001 From: jl-zhoujl2 Date: Fri, 18 Nov 2022 17:22:37 +0800 Subject: [PATCH] =?UTF-8?q?11.18=20=E4=BF=AE=E6=94=B9=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E8=B7=AF=E5=BE=84=E7=9A=84=E6=96=B9=E6=B3=95?= =?UTF-8?q?=EF=BC=8C=E8=AE=A9=E9=A1=B5=E9=9D=A2=E5=86=85pdf=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=AD=A3=E5=B8=B8=E8=8E=B7=E5=8F=96=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/PreviewJgtzsModal.tsx | 7 ++-- .../components/PreviewJgtzsModal.tsx | 7 ++-- src/utils/DownloadUtils.ts | 34 ++++++++++++++++++- src/utils/PdfModal/PdfModal.tsx | 7 ++-- 4 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/pages/Calibration/Supplier/ViewNotice/components/PreviewJgtzsModal.tsx b/src/pages/Calibration/Supplier/ViewNotice/components/PreviewJgtzsModal.tsx index 55d2f6f..1b21ee4 100644 --- a/src/pages/Calibration/Supplier/ViewNotice/components/PreviewJgtzsModal.tsx +++ b/src/pages/Calibration/Supplier/ViewNotice/components/PreviewJgtzsModal.tsx @@ -3,7 +3,7 @@ import { Modal, Button } from 'antd'; import PDF from 'react-pdf-js'; import ProCard from '@ant-design/pro-card'; import FileDown from '@/utils/Download'; -import { getDownloadFileUrl, getFileListByBid } from '@/utils/DownloadUtils'; +import { getFileListByBid, useDownLoadUrl } from '@/utils/DownloadUtils'; interface PreviewJgtzsModalProps { fileId: string, @@ -14,6 +14,7 @@ interface PreviewJgtzsModalProps { const PreviewJgtzsModal: React.FC = (props) => { const { fileId, downLoadFileName, modalVisible, onCancel } = props + const [url] = useDownLoadUrl(fileId); const [page, setPage] = useState(1); const [pages, setPages] = useState(0); const [fileExist, setFileExist] = useState("0");//0:未验证,1:验证后有,2:验证后没有 @@ -81,10 +82,10 @@ const PreviewJgtzsModal: React.FC = (props) => { > {fileExist == "0" ? (
- ) : fileExist == "1" ? ( + ) : fileExist == "1" ? url != "" && ( <> = (props) => { const { fileId, modalVisible, onCancel } = props + const [url] = useDownLoadUrl(fileId); const [page, setPage] = useState(1); const [pages, setPages] = useState(0); const [fileExist, setFileExist] = useState("0");//0:未验证,1:验证后有,2:验证后没有 @@ -79,10 +80,10 @@ const PreviewJgtzsModal: React.FC = (props) => { > {fileExist == "0" ? (
- ) : fileExist == "1" ? ( + ) : fileExist == "1" ? url != "" && ( <> { } return url; } +/** + * objectId获取文件下载链接 + * @param objectId + * @returns + */ +export const useDownLoadUrl = (objectId: string): string[] => { + const [url, setUrl] = useState(""); + useEffect(() => { + const getFileUrl = async () => { + console.log("objectId", objectId); + await getFilelist([objectId]).then(async res => { + if (res?.success && res?.data?.length > 0) { + const keyRes = await getDownloadSecretKey({ fileId: res?.data[res?.data?.length - 1].fileId });//获取key + let url = downloadAttachmentPath + '?fileId=' + res?.data[res?.data?.length - 1].fileId + '&documentSecretKey=' + keyRes?.data; + setUrl(url); + } + }) + } + if (isNotEmpty(objectId)) { + if (checkObjectId(objectId)) {//判断3.0 objectId + getFileUrl(); + } else { + let url = downloadPathBySecond + '?id=' + objectId + '&p=' + getTimeStamp(); + setUrl(url); + } + + } + }, [objectId]) + + return [url]; +} /** * 获取文件列表 * @param objectId diff --git a/src/utils/PdfModal/PdfModal.tsx b/src/utils/PdfModal/PdfModal.tsx index 80a7b21..40254e5 100644 --- a/src/utils/PdfModal/PdfModal.tsx +++ b/src/utils/PdfModal/PdfModal.tsx @@ -3,7 +3,7 @@ import { Modal, Button } from 'antd'; import PDF from 'react-pdf-js'; import ProCard from '@ant-design/pro-card'; import FileDown from '@/utils/Download'; -import { getDownloadFileUrl, getFileListByBid } from '../DownloadUtils'; +import { getFileListByBid, useDownLoadUrl } from '../DownloadUtils'; /** * Pdf Modal弹窗公共组件 * 2021.8.25 zhoujianlong 根据定标结果通知书的弹出窗口改造初始版本,增加备注 @@ -17,6 +17,7 @@ interface PdfModalProps { const PdfModal: React.FC = (props) => { const { fileId, downLoadFileName, modalVisible, onCancel } = props; + const [url] = useDownLoadUrl(fileId); const [page, setPage] = useState(1); //页码 const [pages, setPages] = useState(0); //总页数 const [fileExist, setFileExist] = useState('0'); //0:未验证,1:验证后有,2:验证后没有 @@ -93,10 +94,10 @@ const PdfModal: React.FC = (props) => { {fileExist == '0' ? (
- ) : fileExist == '1' ? ( + ) : fileExist == '1' ? url != "" && ( <>