forked from ddrilling/asb_cloud_front
CF2-8: Добавлено скачивание репортов
This commit is contained in:
parent
a89c5200d7
commit
e4d4d044d6
@ -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) {
|
||||
<br />
|
||||
<span> { progressData.operation } </span>
|
||||
<br />
|
||||
<a onClick={event => getReportFile(event, progressData.reportName)}
|
||||
download>
|
||||
<a onClick={event => {getReportFile(event, progressData.reportName)}}
|
||||
download={progressData.reportName}>
|
||||
{ progressData.reportName }
|
||||
</a>
|
||||
</>
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user