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'
|
'.las': '/images/las.png'
|
||||||
}
|
}
|
||||||
|
|
||||||
const contentTypes = {
|
|
||||||
'.pdf': 'application/pdf',
|
|
||||||
'.las': 'application/octet-stream'
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Экспорт рендера
|
// Экспорт рендера
|
||||||
export default function Report(props) {
|
export default function Report(props) {
|
||||||
@ -85,8 +80,8 @@ export default function Report(props) {
|
|||||||
<br />
|
<br />
|
||||||
<span> { progressData.operation } </span>
|
<span> { progressData.operation } </span>
|
||||||
<br />
|
<br />
|
||||||
<a onClick={event => getReportFile(event, progressData.reportName)}
|
<a onClick={event => {getReportFile(event, progressData.reportName)}}
|
||||||
download>
|
download={progressData.reportName}>
|
||||||
{ progressData.reportName }
|
{ progressData.reportName }
|
||||||
</a>
|
</a>
|
||||||
</>
|
</>
|
||||||
@ -94,17 +89,31 @@ export default function Report(props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getReportFile = async (event, reportFileName) => {
|
const getReportFile = async (event, reportFileName) => {
|
||||||
try {
|
const element = event.target
|
||||||
const element = event.target
|
|
||||||
let bytesArray = await ReportService.getReport(wellId, reportFileName)
|
if(!element.href.length) {
|
||||||
const contentType = contentTypes[reportFileName.slice(-4)]
|
try {
|
||||||
let reportUrl = URL.createObjectURL(new File(bytesArray, {type: contentType}))
|
await fetch(`/api/report/${wellId}/${reportFileName}`, {
|
||||||
element.href = reportUrl
|
headers: {
|
||||||
} catch (error) {
|
Authorization: 'Bearer ' + localStorage['token']
|
||||||
notify(`Не удалось скачать отчет по скважине (${wellId}) c
|
}
|
||||||
${rangeDate[0].format("DD.MM.YYYY hh:mm:ss")} по
|
})
|
||||||
${rangeDate[1].format("DD.MM.YYYY hh:mm:ss")}`, 'error')
|
.then(async (response) => {
|
||||||
console.log(error)
|
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