2022-10-17 17:59:45 +05:00
|
|
|
|
import { Link, useLocation, useNavigate, useParams } from 'react-router-dom'
|
2022-10-17 18:19:13 +05:00
|
|
|
|
import { memo, useCallback, useEffect, useMemo, useState } from 'react'
|
2022-06-29 16:45:38 +05:00
|
|
|
|
import { InfoCircleFilled, CloseCircleOutlined } from '@ant-design/icons'
|
|
|
|
|
import { Button, Result, Typography } from 'antd'
|
|
|
|
|
|
|
|
|
|
import { downloadFile, invokeWebApiWrapperAsync } from '@components/factory'
|
|
|
|
|
import { wrapPrivateComponent } from '@utils'
|
|
|
|
|
import { FileService, WellService } from '@api'
|
|
|
|
|
|
|
|
|
|
import AccessDenied from './AccessDenied'
|
|
|
|
|
|
|
|
|
|
const { Paragraph, Text } = Typography
|
|
|
|
|
|
|
|
|
|
export const getLinkToFile = (fileInfo) => `/file_download/${fileInfo.idWell}/${fileInfo.id}`
|
|
|
|
|
|
|
|
|
|
const FileDownload = memo(function FileDownload() {
|
|
|
|
|
const { idWell, idFile } = useParams()
|
|
|
|
|
const [well, setWell] = useState({})
|
|
|
|
|
const [file, setFile] = useState({})
|
|
|
|
|
const [isError, setIsError] = useState(false)
|
|
|
|
|
|
|
|
|
|
const navigate = useNavigate()
|
2022-10-17 17:59:45 +05:00
|
|
|
|
const location = useLocation()
|
2022-10-17 18:19:13 +05:00
|
|
|
|
const isFirstOpenApp = useMemo(() => location.key === 'default', [location])
|
2022-06-29 16:45:38 +05:00
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
invokeWebApiWrapperAsync(
|
|
|
|
|
async () => setWell(await WellService.get(idWell)),
|
|
|
|
|
null,
|
|
|
|
|
'Не удалось получить информацию о скважине',
|
2022-08-18 11:49:10 +05:00
|
|
|
|
{ actionName: 'Получение данных о скважине' }
|
2022-06-29 16:45:38 +05:00
|
|
|
|
)
|
|
|
|
|
}, [idWell])
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
invokeWebApiWrapperAsync(
|
|
|
|
|
async () => {
|
2022-10-17 17:59:45 +05:00
|
|
|
|
const file = await FileService.getFileInfo(idFile)
|
|
|
|
|
setFile(file)
|
2022-06-29 16:45:38 +05:00
|
|
|
|
},
|
|
|
|
|
null,
|
|
|
|
|
() => {
|
|
|
|
|
setIsError(true)
|
|
|
|
|
return 'Не удалось получить информацию о файле'
|
|
|
|
|
},
|
2022-08-18 11:49:10 +05:00
|
|
|
|
{ actionName: 'Получение информации о файле' }
|
2022-06-29 16:45:38 +05:00
|
|
|
|
)
|
2022-10-17 18:19:13 +05:00
|
|
|
|
}, [idFile])
|
2022-06-29 16:45:38 +05:00
|
|
|
|
|
|
|
|
|
const download = useCallback(async () => {
|
2022-10-17 17:59:45 +05:00
|
|
|
|
if (!file || !await downloadFile(file))
|
2022-06-29 16:45:38 +05:00
|
|
|
|
setIsError(true)
|
|
|
|
|
}, [file])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Result
|
|
|
|
|
icon={<InfoCircleFilled style={{ color: '#1890ff' }} />}
|
|
|
|
|
title={(
|
|
|
|
|
<>
|
|
|
|
|
Вы перешли к странице загрузки файла!
|
|
|
|
|
<br />
|
2022-10-17 17:59:45 +05:00
|
|
|
|
Файл "{file?.name ?? ('№' + idFile)}", скважина "{well.caption ?? ('№' + idWell)}".
|
2022-06-29 16:45:38 +05:00
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
// subTitle={}
|
|
|
|
|
extra={(
|
|
|
|
|
<>
|
2022-10-17 17:59:45 +05:00
|
|
|
|
{isFirstOpenApp
|
|
|
|
|
? <Button type={'ghost'} onClick={() => navigate('/')}>Вернуться на главную</Button>
|
|
|
|
|
: <Button type={'ghost'} onClick={() => navigate(-1)}>Вернуться на страницу документов</Button>
|
|
|
|
|
}
|
2022-06-29 16:45:38 +05:00
|
|
|
|
<Button type={'primary'} onClick={download}>Загрузить</Button>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{isError && (
|
|
|
|
|
<div className={'desc'}>
|
|
|
|
|
<Paragraph>
|
|
|
|
|
<Text strong style={{ fontSize: 16 }}>Возможные причины ошибки при попытке скачивания файла:</Text>
|
|
|
|
|
</Paragraph>
|
|
|
|
|
<Paragraph>
|
|
|
|
|
<CloseCircleOutlined style={{ color: 'red' }} />
|
|
|
|
|
У вас отсутствует доступ к файлу.
|
|
|
|
|
<Typography.Link href={'mailto://support@digitaldrilling.ru'} target={'_blank'}>
|
|
|
|
|
Обратиться в поддержку >
|
|
|
|
|
</Typography.Link>
|
|
|
|
|
</Paragraph>
|
|
|
|
|
<Paragraph>
|
|
|
|
|
<CloseCircleOutlined style={{ color: 'red' }} />
|
|
|
|
|
Файла не существует.
|
|
|
|
|
<Link to={'#'} onClick={() => navigate(-1)}>Вернуться назад ></Link>
|
|
|
|
|
</Paragraph>
|
|
|
|
|
<Paragraph>
|
|
|
|
|
<CloseCircleOutlined style={{ color: 'red' }} />
|
|
|
|
|
Разрешения не обновились.
|
|
|
|
|
<Link to={'/login'}>Перезайти в аккаунт ></Link>
|
|
|
|
|
</Paragraph>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</Result>
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
FileDownload.displayName = 'FileDownloadMemo'
|
|
|
|
|
|
|
|
|
|
export default wrapPrivateComponent(FileDownload, {
|
|
|
|
|
requirements: ['File.get'],
|
2022-06-29 18:08:57 +05:00
|
|
|
|
route: 'file_download/:idWell/:idFile/*',
|
2022-06-29 16:45:38 +05:00
|
|
|
|
}, <AccessDenied />)
|