From 5f8738d1bf3e95ac6f5ff0205c536b159d2eb408 Mon Sep 17 00:00:00 2001 From: KharchenkoVV Date: Mon, 26 Jul 2021 15:21:35 +0500 Subject: [PATCH] =?UTF-8?q?CF2-33:=20=D0=A4=D0=B8=D0=BA=D1=81=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B8=20=D1=84=D0=B0=D0=B9?= =?UTF-8?q?=D0=BB=D0=BE=D0=B2=20=D0=B8=20=D0=BC=D0=B5=D0=BD=D1=8E=20=D0=BA?= =?UTF-8?q?=D0=B0=D1=82=D0=B5=D0=B3=D0=BE=D1=80=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Documents.jsx | 137 +++++++++++++++-------- src/components/MenuDocuments.jsx | 10 ++ src/pages/Cementing.jsx | 4 +- src/pages/DocumentForWell.jsx | 4 +- src/pages/FluidService.jsx | 4 +- src/pages/Gti.jsx | 4 +- src/pages/Master.jsx | 4 +- src/pages/Nnb.jsx | 4 +- src/pages/Supervisor.jsx | 4 +- src/pages/Well.jsx | 12 +- src/services/api/services/FileService.ts | 9 +- 11 files changed, 124 insertions(+), 72 deletions(-) diff --git a/src/components/Documents.jsx b/src/components/Documents.jsx index c758f90..e3bbda3 100644 --- a/src/components/Documents.jsx +++ b/src/components/Documents.jsx @@ -9,27 +9,9 @@ import LoaderPortal from './LoaderPortal' import locale from "antd/lib/locale/ru_RU" import moment from 'moment' -const pageSize = 26 +const pageSize = 12 const {RangePicker} = DatePicker; -const columns = [ - { - title: 'Документ', - key: 'document', - dataIndex: 'name', - }, - { - title: 'Дата загрузки', - key: 'uploadDate', - dataIndex: 'uploadDate', - render: (item) => moment.utc(item).local().format('DD MMM YYYY, HH:mm:ss') - }, - { - title: 'Ф.И.О.', - key: 'userName', - dataIndex: 'userName', - } -]; export default function Documents({selectedFileCategory}) { let {id} = useParams() @@ -39,10 +21,71 @@ export default function Documents({selectedFileCategory}) { const [pagination, setPagination] = useState(null) const [files, setFiles] = useState([]) const [selectedFiles, setSelectedFiles] = useState([]) + const [isTableUpdating, setTableUpdating] = useState(false) const [loader, setLoader] = useState(false) + const [form] = Form.useForm(); + + const handleFileNameCLick = async (event, row) => { + const element = event.target + + if(!element.href.length) { + try { + setLoader(true) + + await fetch(`/api/files/${id}/${row.id}`, { + 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() + }; + setLoader(false) + }); + } catch (error) { + notify(`Не удалось скачать файл ${row}`, 'error') + console.log(error) + } + } + } + + const columns = [ + { + title: 'Документ', + key: 'document', + dataIndex: 'name', + render: (name, row) => + handleFileNameCLick(ev, row)} download={name}>{name} + }, + { + title: 'Дата загрузки', + key: 'uploadDate', + dataIndex: 'uploadDate', + render: (item) => moment.utc(item).local().format('DD MMM YYYY, HH:mm:ss') + }, + { + title: 'Ф.И.О.', + key: 'userName', + dataIndex: 'userName', + } + ]; const submitFileFormProps = { + progress: { + strokeColor: { + '0%': '#108ee9', + '100%': '#87d068', + }, + strokeWidth: 3, + format: percent => `${parseFloat(percent.toFixed(2))}%`, + }, onChange({ file, fileList }) { if (file.status !== 'uploading') { setSelectedFiles(fileList) @@ -54,11 +97,12 @@ export default function Documents({selectedFileCategory}) { setRange(range) } - const onFinish = (values) => { + const onFinish = (values, form) => { var fileList = values.fileInput.fileList if (fileList.length > 0) { + setLoader(true) const formData = new FormData(); fileList.forEach(val => { @@ -73,7 +117,9 @@ export default function Documents({selectedFileCategory}) { body: formData }) .then(async (response) => { - // refresh component to upload new files в зависимоть useEffect какую-то переменную, чтоб дергался снова запрос на всю инфу о файлах + setLoader(false) + form.resetFields() + setTableUpdating(true) }); } } @@ -93,7 +139,7 @@ export default function Documents({selectedFileCategory}) { begin = range[0].toISOString() end = range[1].toISOString() } - console.log(id) + await FileService.getFilesInfo( `${id}`, (page - 1) * pageSize, @@ -114,37 +160,40 @@ export default function Documents({selectedFileCategory}) { total: paginatedFiles?.count, current: Math.floor(paginatedFiles?.skip / pageSize), }) + + setTableUpdating(false) + setLoader(false) } ) } catch (ex) { notify(`Не удалось загрузить файлы по скважине "${id}"`, 'error') console.log(ex) } - setLoader(false) } GetDocuments() - }, [id, selectedFileCategory, range]) + }, [id, range, selectedFileCategory, isTableUpdating]) return (
-
-

Фильтр документов:

- - - -
- -
 
-
-
+
+

Фильтр документов:

+ + + +
+ +
 
+ onFinish(values, form)} + onFinishFailed={onFinishFailed} + style={{width: '300px'}} + > Отправить - -
-
+ +
 
{ + setSelectedItem({ current: e.key }); + }; + return( <> }> Растворный сервис diff --git a/src/pages/Cementing.jsx b/src/pages/Cementing.jsx index 72c3f99..2f08b27 100644 --- a/src/pages/Cementing.jsx +++ b/src/pages/Cementing.jsx @@ -1,8 +1,8 @@ import Documents from "../components/Documents" -export default function Cementing(id) { +export default function Cementing({selectedFileCategory}) { return( - + ) } \ No newline at end of file diff --git a/src/pages/DocumentForWell.jsx b/src/pages/DocumentForWell.jsx index bab1b6a..62255c3 100644 --- a/src/pages/DocumentForWell.jsx +++ b/src/pages/DocumentForWell.jsx @@ -1,8 +1,8 @@ import Documents from "../components/Documents" -export default function DocumentsForWell(id) { +export default function DocumentsForWell({selectedFileCategory}) { return( - + ) } \ No newline at end of file diff --git a/src/pages/FluidService.jsx b/src/pages/FluidService.jsx index 4f2135c..2022289 100644 --- a/src/pages/FluidService.jsx +++ b/src/pages/FluidService.jsx @@ -1,8 +1,8 @@ import Documents from "../components/Documents" -export default function FluidService(id) { +export default function FluidService({selectedFileCategory}) { return( - + ) } \ No newline at end of file diff --git a/src/pages/Gti.jsx b/src/pages/Gti.jsx index a822c5f..c51aa47 100644 --- a/src/pages/Gti.jsx +++ b/src/pages/Gti.jsx @@ -1,8 +1,8 @@ import Documents from "../components/Documents" -export default function Gti(id) { +export default function Gti({selectedFileCategory}) { return( - + ) } \ No newline at end of file diff --git a/src/pages/Master.jsx b/src/pages/Master.jsx index 9ec37c7..6c15e0c 100644 --- a/src/pages/Master.jsx +++ b/src/pages/Master.jsx @@ -1,8 +1,8 @@ import Documents from "../components/Documents" -export default function Master(id) { +export default function Master({selectedFileCategory}) { return( - + ) } \ No newline at end of file diff --git a/src/pages/Nnb.jsx b/src/pages/Nnb.jsx index c3b674c..c5d1227 100644 --- a/src/pages/Nnb.jsx +++ b/src/pages/Nnb.jsx @@ -1,8 +1,8 @@ import Documents from "../components/Documents" -export default function Nnb(id) { +export default function Nnb({selectedFileCategory}) { return( - + ) } \ No newline at end of file diff --git a/src/pages/Supervisor.jsx b/src/pages/Supervisor.jsx index 5a670a4..52bf0b8 100644 --- a/src/pages/Supervisor.jsx +++ b/src/pages/Supervisor.jsx @@ -1,8 +1,8 @@ import Documents from "../components/Documents" -export default function Supervisor(id) { +export default function Supervisor({selectedFileCategory}) { return( - + ) } \ No newline at end of file diff --git a/src/pages/Well.jsx b/src/pages/Well.jsx index df55594..293b95f 100644 --- a/src/pages/Well.jsx +++ b/src/pages/Well.jsx @@ -113,22 +113,22 @@ export default function Well() { - + - + - + - + - + - + diff --git a/src/services/api/services/FileService.ts b/src/services/api/services/FileService.ts index 5ba7110..8200338 100644 --- a/src/services/api/services/FileService.ts +++ b/src/services/api/services/FileService.ts @@ -69,22 +69,17 @@ end?: string, /** * Возвращает файл с диска на сервере * @param wellId id скважины - * @param fileName * @param fileId id запрашиваемого файла * @returns string Success * @throws ApiError */ public static async getFile( wellId: number, -fileName: string, -fileId?: number, +fileId: number, ): Promise { const result = await __request({ method: 'GET', - path: `/api/files/${wellId}/${fileName}`, - query: { - 'fileId': fileId, - }, + path: `/api/files/${wellId}/${fileId}`, }); return result.body; }