From 87a7faa17f60bb9c9fd9e0ee5f84e189a9fae39e Mon Sep 17 00:00:00 2001 From: KharchenkoVV Date: Mon, 26 Jul 2021 11:12:20 +0500 Subject: [PATCH] =?UTF-8?q?CF2-33:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BE=D1=81=D0=BD=D0=BE=D0=B2=D0=B0=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B9=20=D0=B2?= =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D0=B4=D0=BA=D0=B8=20'=D0=94=D0=BE=D0=BA?= =?UTF-8?q?=D1=83=D0=BC=D0=B5=D0=BD=D1=8B'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Documents.jsx | 101 +++++++++++++---------- src/pages/Cementing.jsx | 4 +- src/pages/DocumentForWell.jsx | 4 +- src/pages/FluidService.jsx | 4 +- src/pages/Gti.jsx | 4 +- src/pages/Login.jsx | 1 + src/pages/Master.jsx | 4 +- src/pages/Nnb.jsx | 4 +- src/pages/Supervisor.jsx | 4 +- src/pages/Well.jsx | 14 ++-- src/services/api/index.ts | 3 + src/services/api/services/FileService.ts | 92 +++++++++++++++++++++ 12 files changed, 174 insertions(+), 65 deletions(-) create mode 100644 src/services/api/services/FileService.ts diff --git a/src/components/Documents.jsx b/src/components/Documents.jsx index db405b0..c758f90 100644 --- a/src/components/Documents.jsx +++ b/src/components/Documents.jsx @@ -1,11 +1,12 @@ -import {Table, DatePicker, Form, Button, Upload, ConfigProvider} from 'antd'; -import { UploadOutlined } from '@ant-design/icons'; -import MenuDocuments from "./MenuDocuments"; -import {useState, useEffect} from "react"; +import {Table, DatePicker, Form, Button, Upload, ConfigProvider} from 'antd' +import { UploadOutlined } from '@ant-design/icons' +import MenuDocuments from "./MenuDocuments" +import { FileService } from '../services/api' +import {useState, useEffect} from "react" import {useParams} from 'react-router-dom' import notify from './notify' import LoaderPortal from './LoaderPortal' -import locale from "antd/lib/locale/ru_RU"; +import locale from "antd/lib/locale/ru_RU" import moment from 'moment' const pageSize = 26 @@ -25,26 +26,26 @@ const columns = [ }, { title: 'Ф.И.О.', - key: 'name', - dataIndex: 'name', + key: 'userName', + dataIndex: 'userName', } ]; -export default function Documents() { +export default function Documents({selectedFileCategory}) { let {id} = useParams() const [page, setPage] = useState(1) const [range, setRange] = useState([]) const [pagination, setPagination] = useState(null) const [files, setFiles] = useState([]) + const [selectedFiles, setSelectedFiles] = useState([]) const [loader, setLoader] = useState(false) const submitFileFormProps = { - //action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76', onChange({ file, fileList }) { if (file.status !== 'uploading') { - console.log(file, fileList); + setSelectedFiles(fileList) } } } @@ -54,15 +55,33 @@ export default function Documents() { } const onFinish = (values) => { - console.log('Success:', values); + var fileList = values.fileInput.fileList + + if (fileList.length > 0) + { + const formData = new FormData(); + + fileList.forEach(val => { + formData.append('files', val.originFileObj) + }) + + fetch(`/api/files/${id}/files?idCategory=${selectedFileCategory}&idUser=${localStorage['userId']}`, { + headers: { + Authorization: 'Bearer ' + localStorage['token'] + }, + method: 'POST', + body: formData + }) + .then(async (response) => { + // refresh component to upload new files в зависимоть useEffect какую-то переменную, чтоб дергался снова запрос на всю инфу о файлах + }); + } } const onFinishFailed = (errorInfo) => { - console.log('Failed:', errorInfo); + notify(`Не удалось отправить файлы по скважине "${id}".`, 'error') } - const fileList = [] - useEffect(() => { const GetDocuments = async () => { setLoader(true) @@ -74,26 +93,29 @@ export default function Documents() { begin = range[0].toISOString() end = range[1].toISOString() } - // await AnalyticsService.getOperationsByWell( - // `${id}`, - // (page-1) * pageSize, - // pageSize, - // begin, - // end).then((paginatedFiles) => { - // setFiles(paginatedFiles?.items.map(f => { - // return { - // key: f.id, - // begin: f.date, - // ...f - // } - // })) + console.log(id) + await FileService.getFilesInfo( + `${id}`, + (page - 1) * pageSize, + pageSize, + selectedFileCategory, + begin, + end + ).then((paginatedFiles) => { + setFiles(paginatedFiles?.items.map(f => { + return { + key: f.id, + begin: f.date, + ...f + } + })) - // setPagination({ - // total: paginatedFiles?.count, - // current: Math.floor(paginatedFiles?.skip / pageSize), - // }) - // } - //) + setPagination({ + total: paginatedFiles?.count, + current: Math.floor(paginatedFiles?.skip / pageSize), + }) + } + ) } catch (ex) { notify(`Не удалось загрузить файлы по скважине "${id}"`, 'error') console.log(ex) @@ -101,7 +123,7 @@ export default function Documents() { setLoader(false) } GetDocuments() - }, [id, range]) + }, [id, selectedFileCategory, range]) return (
@@ -127,15 +149,6 @@ export default function Documents() { name="fileInput" rules={[{ required: true, message: 'Выберите файл' }]} > - {/* { - setFile(e.target.value) - files.push(e.target.value) - localStorage.setItem(e.target.value, file) - setFiles(files) - console.log(e.target.value) - } - }/> */} @@ -144,7 +157,7 @@ export default function Documents() {