CF2-33: Добавлена основа для новой вкладки 'Докумены'

This commit is contained in:
KharchenkoVV 2021-07-26 11:12:20 +05:00
parent abff5ad644
commit 87a7faa17f
12 changed files with 174 additions and 65 deletions

View File

@ -1,11 +1,12 @@
import {Table, DatePicker, Form, Button, Upload, ConfigProvider} from 'antd'; import {Table, DatePicker, Form, Button, Upload, ConfigProvider} from 'antd'
import { UploadOutlined } from '@ant-design/icons'; import { UploadOutlined } from '@ant-design/icons'
import MenuDocuments from "./MenuDocuments"; import MenuDocuments from "./MenuDocuments"
import {useState, useEffect} from "react"; import { FileService } from '../services/api'
import {useState, useEffect} from "react"
import {useParams} from 'react-router-dom' import {useParams} from 'react-router-dom'
import notify from './notify' import notify from './notify'
import LoaderPortal from './LoaderPortal' import LoaderPortal from './LoaderPortal'
import locale from "antd/lib/locale/ru_RU"; import locale from "antd/lib/locale/ru_RU"
import moment from 'moment' import moment from 'moment'
const pageSize = 26 const pageSize = 26
@ -25,26 +26,26 @@ const columns = [
}, },
{ {
title: 'Ф.И.О.', title: 'Ф.И.О.',
key: 'name', key: 'userName',
dataIndex: 'name', dataIndex: 'userName',
} }
]; ];
export default function Documents() { export default function Documents({selectedFileCategory}) {
let {id} = useParams() let {id} = useParams()
const [page, setPage] = useState(1) const [page, setPage] = useState(1)
const [range, setRange] = useState([]) const [range, setRange] = useState([])
const [pagination, setPagination] = useState(null) const [pagination, setPagination] = useState(null)
const [files, setFiles] = useState([]) const [files, setFiles] = useState([])
const [selectedFiles, setSelectedFiles] = useState([])
const [loader, setLoader] = useState(false) const [loader, setLoader] = useState(false)
const submitFileFormProps = { const submitFileFormProps = {
//action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
onChange({ file, fileList }) { onChange({ file, fileList }) {
if (file.status !== 'uploading') { if (file.status !== 'uploading') {
console.log(file, fileList); setSelectedFiles(fileList)
} }
} }
} }
@ -54,15 +55,33 @@ export default function Documents() {
} }
const onFinish = (values) => { 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) => { const onFinishFailed = (errorInfo) => {
console.log('Failed:', errorInfo); notify(`Не удалось отправить файлы по скважине "${id}".`, 'error')
} }
const fileList = []
useEffect(() => { useEffect(() => {
const GetDocuments = async () => { const GetDocuments = async () => {
setLoader(true) setLoader(true)
@ -74,26 +93,29 @@ export default function Documents() {
begin = range[0].toISOString() begin = range[0].toISOString()
end = range[1].toISOString() end = range[1].toISOString()
} }
// await AnalyticsService.getOperationsByWell( console.log(id)
// `${id}`, await FileService.getFilesInfo(
// (page-1) * pageSize, `${id}`,
// pageSize, (page - 1) * pageSize,
// begin, pageSize,
// end).then((paginatedFiles) => { selectedFileCategory,
// setFiles(paginatedFiles?.items.map(f => { begin,
// return { end
// key: f.id, ).then((paginatedFiles) => {
// begin: f.date, setFiles(paginatedFiles?.items.map(f => {
// ...f return {
// } key: f.id,
// })) begin: f.date,
...f
}
}))
// setPagination({ setPagination({
// total: paginatedFiles?.count, total: paginatedFiles?.count,
// current: Math.floor(paginatedFiles?.skip / pageSize), current: Math.floor(paginatedFiles?.skip / pageSize),
// }) })
// } }
//) )
} catch (ex) { } catch (ex) {
notify(`Не удалось загрузить файлы по скважине "${id}"`, 'error') notify(`Не удалось загрузить файлы по скважине "${id}"`, 'error')
console.log(ex) console.log(ex)
@ -101,7 +123,7 @@ export default function Documents() {
setLoader(false) setLoader(false)
} }
GetDocuments() GetDocuments()
}, [id, range]) }, [id, selectedFileCategory, range])
return ( return (
<div> <div>
@ -127,15 +149,6 @@ export default function Documents() {
name="fileInput" name="fileInput"
rules={[{ required: true, message: 'Выберите файл' }]} rules={[{ required: true, message: 'Выберите файл' }]}
> >
{/* <input type="file"
onChange={(e) => {
setFile(e.target.value)
files.push(e.target.value)
localStorage.setItem(e.target.value, file)
setFiles(files)
console.log(e.target.value)
}
}/> */}
<Upload {...submitFileFormProps}> <Upload {...submitFileFormProps}>
<Button icon={<UploadOutlined />}>Загрузить файл</Button> <Button icon={<UploadOutlined />}>Загрузить файл</Button>
</Upload> </Upload>
@ -144,7 +157,7 @@ export default function Documents() {
<Button <Button
type="primary" type="primary"
htmlType="submit" htmlType="submit"
disabled={fileList.length === 0} disabled={selectedFiles.length === 0}
style={{marginLeft: '10px'}} style={{marginLeft: '10px'}}
> >
Отправить Отправить

View File

@ -1,8 +1,8 @@
import Documents from "../components/Documents" import Documents from "../components/Documents"
export default function Cementing() { export default function Cementing(id) {
return( return(
<Documents /> <Documents selectedFileCategory={id} />
) )
} }

View File

@ -1,8 +1,8 @@
import Documents from "../components/Documents" import Documents from "../components/Documents"
export default function DocumentsForWell() { export default function DocumentsForWell(id) {
return( return(
<Documents /> <Documents selectedFileCategory={id} />
) )
} }

View File

@ -1,8 +1,8 @@
import Documents from "../components/Documents" import Documents from "../components/Documents"
export default function FluidService() { export default function FluidService(id) {
return( return(
<Documents /> <Documents selectedFileCategory={id} />
) )
} }

View File

@ -1,8 +1,8 @@
import Documents from "../components/Documents" import Documents from "../components/Documents"
export default function Gti() { export default function Gti(id) {
return( return(
<Documents /> <Documents selectedFileCategory={id} />
) )
} }

View File

@ -17,6 +17,7 @@ const openNotificationError = (message, title) => {
const setUser = (user) =>{ const setUser = (user) =>{
OpenAPI.TOKEN = user.token OpenAPI.TOKEN = user.token
localStorage['userId'] = user.id
localStorage['token'] = user.token localStorage['token'] = user.token
localStorage['login'] = user.login localStorage['login'] = user.login
} }

View File

@ -1,8 +1,8 @@
import Documents from "../components/Documents" import Documents from "../components/Documents"
export default function Master() { export default function Master(id) {
return( return(
<Documents /> <Documents selectedFileCategory={id} />
) )
} }

View File

@ -1,8 +1,8 @@
import Documents from "../components/Documents" import Documents from "../components/Documents"
export default function Nnb() { export default function Nnb(id) {
return( return(
<Documents /> <Documents selectedFileCategory={id} />
) )
} }

View File

@ -1,8 +1,8 @@
import Documents from "../components/Documents" import Documents from "../components/Documents"
export default function Supervisor() { export default function Supervisor(id) {
return( return(
<Documents /> <Documents selectedFileCategory={id} />
) )
} }

View File

@ -110,25 +110,25 @@ export default function Well() {
<TelemetryView/> <TelemetryView/>
</Route> </Route>
<Route path="/well/:id/fluidService"> <Route path="/well/:id/fluidService">
<FluidService/> <FluidService selectedFileCategory={1}/>
</Route> </Route>
<Route path="/well/:id/cementing"> <Route path="/well/:id/cementing">
<Cementing/> <Cementing id={2}/>
</Route> </Route>
<Route path="/well/:id/nnb"> <Route path="/well/:id/nnb">
<Nnb/> <Nnb id={3}/>
</Route> </Route>
<Route path="/well/:id/gti"> <Route path="/well/:id/gti">
<Gti/> <Gti id={4}/>
</Route> </Route>
<Route path="/well/:id/documentsForWell"> <Route path="/well/:id/documentsForWell">
<DocumentForWell/> <DocumentForWell id={5}/>
</Route> </Route>
<Route path="/well/:id/supervisor"> <Route path="/well/:id/supervisor">
<Supervisor/> <Supervisor id={6}/>
</Route> </Route>
<Route path="/well/:id/master"> <Route path="/well/:id/master">
<Master/> <Master id={7}/>
</Route> </Route>
<Route path="/well/:id/lastData"> <Route path="/well/:id/lastData">
<LastData/> <LastData/>

View File

@ -12,6 +12,8 @@ export type { DataSaubBaseDto } from './models/DataSaubBaseDto';
export type { DatesRangeDto } from './models/DatesRangeDto'; export type { DatesRangeDto } from './models/DatesRangeDto';
export type { DepositDto } from './models/DepositDto'; export type { DepositDto } from './models/DepositDto';
export type { EventDto } from './models/EventDto'; export type { EventDto } from './models/EventDto';
export type { FilePropertiesDto } from './models/FilePropertiesDto';
export type { FilePropertiesDtoPaginationContainer } from './models/FilePropertiesDtoPaginationContainer';
export type { MessageDto } from './models/MessageDto'; export type { MessageDto } from './models/MessageDto';
export type { MessageDtoPaginationContainer } from './models/MessageDtoPaginationContainer'; export type { MessageDtoPaginationContainer } from './models/MessageDtoPaginationContainer';
export type { OperationDto } from './models/OperationDto'; export type { OperationDto } from './models/OperationDto';
@ -32,6 +34,7 @@ export { AuthService } from './services/AuthService';
export { ClusterService } from './services/ClusterService'; export { ClusterService } from './services/ClusterService';
export { DataService } from './services/DataService'; export { DataService } from './services/DataService';
export { DepositService } from './services/DepositService'; export { DepositService } from './services/DepositService';
export { FileService } from './services/FileService';
export { MessageService } from './services/MessageService'; export { MessageService } from './services/MessageService';
export { ReportService } from './services/ReportService'; export { ReportService } from './services/ReportService';
export { TelemetryService } from './services/TelemetryService'; export { TelemetryService } from './services/TelemetryService';

View File

@ -0,0 +1,92 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { FilePropertiesDtoPaginationContainer } from '../models/FilePropertiesDtoPaginationContainer';
import { request as __request } from '../core/request';
export class FileService {
/**
* Сохраняет переданные файлы и информацию о них
* @param wellId id скважины
* @param idCategory id категории файла
* @param idUser id отправившего файл пользователя
* @param requestBody
* @returns number Success
* @throws ApiError
*/
public static async saveFiles(
wellId: number,
idCategory?: number,
idUser?: number,
requestBody?: any,
): Promise<number> {
const result = await __request({
method: 'POST',
path: `/api/files/${wellId}/files`,
query: {
'idCategory': idCategory,
'idUser': idUser,
},
body: requestBody,
});
return result.body;
}
/**
* Возвращает информацию о файлах для скважины в выбраной категории
* @param wellId id скважины
* @param skip для пагинации кол-во записей пропустить
* @param take для пагинации кол-во записей взять
* @param idCategory id категории файла
* @param begin дата начала
* @param end дата окончания
* @returns FilePropertiesDtoPaginationContainer Success
* @throws ApiError
*/
public static async getFilesInfo(
wellId: number,
skip: number,
take: number = 32,
idCategory: number,
begin?: string,
end?: string,
): Promise<FilePropertiesDtoPaginationContainer> {
const result = await __request({
method: 'GET',
path: `/api/files/${wellId}/filesInfo`,
query: {
'skip': skip,
'take': take,
'idCategory': idCategory,
'begin': begin,
'end': end,
},
});
return result.body;
}
/**
* Возвращает файл с диска на сервере
* @param wellId id скважины
* @param fileName
* @param fileId id запрашиваемого файла
* @returns string Success
* @throws ApiError
*/
public static async getFile(
wellId: number,
fileName: string,
fileId?: number,
): Promise<string> {
const result = await __request({
method: 'GET',
path: `/api/files/${wellId}/${fileName}`,
query: {
'fileId': fileId,
},
});
return result.body;
}
}