From e4d4d044d641d632a7f6948b34ab6f898e97c51f Mon Sep 17 00:00:00 2001 From: KharchenkoVV Date: Wed, 9 Jun 2021 17:25:54 +0500 Subject: [PATCH] =?UTF-8?q?CF2-8:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D1=81=D0=BA=D0=B0=D1=87=D0=B8=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=80=D0=B5=D0=BF=D0=BE=D1=80=D1=82=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Report.jsx | 45 ++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/pages/Report.jsx b/src/pages/Report.jsx index c97151e..f3b30c0 100644 --- a/src/pages/Report.jsx +++ b/src/pages/Report.jsx @@ -37,11 +37,6 @@ const imgPaths = { '.las': '/images/las.png' } -const contentTypes = { - '.pdf': 'application/pdf', - '.las': 'application/octet-stream' -} - // Экспорт рендера export default function Report(props) { @@ -85,8 +80,8 @@ export default function Report(props) {
{ progressData.operation }
- getReportFile(event, progressData.reportName)} - download> + {getReportFile(event, progressData.reportName)}} + download={progressData.reportName}> { progressData.reportName } @@ -94,17 +89,31 @@ export default function Report(props) { } const getReportFile = async (event, reportFileName) => { - try { - const element = event.target - let bytesArray = await ReportService.getReport(wellId, reportFileName) - const contentType = contentTypes[reportFileName.slice(-4)] - let reportUrl = URL.createObjectURL(new File(bytesArray, {type: contentType})) - element.href = reportUrl - } catch (error) { - notify(`Не удалось скачать отчет по скважине (${wellId}) c - ${rangeDate[0].format("DD.MM.YYYY hh:mm:ss")} по - ${rangeDate[1].format("DD.MM.YYYY hh:mm:ss")}`, 'error') - console.log(error) + const element = event.target + + if(!element.href.length) { + try { + await fetch(`/api/report/${wellId}/${reportFileName}`, { + headers: { + Authorization: 'Bearer ' + localStorage['token'] + } + }) + .then(async (response) => { + const blob = await response.blob(); + + let reader = new FileReader(); + reader.readAsDataURL(blob); + reader.onload = function (e) { + element.href = e.target.result + element.click() + }; + }); + } catch (error) { + notify(`Не удалось скачать отчет по скважине (${wellId}) c + ${rangeDate[0].format("DD.MM.YYYY hh:mm:ss")} по + ${rangeDate[1].format("DD.MM.YYYY hh:mm:ss")}`, 'error') + console.log(error) + } } }