forked from ddrilling/asb_cloud_front
CF2-33: Добавлена основа для новой вкладки 'Докумены'
This commit is contained in:
parent
abff5ad644
commit
87a7faa17f
@ -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 (
|
||||
<div>
|
||||
@ -127,15 +149,6 @@ export default function Documents() {
|
||||
name="fileInput"
|
||||
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}>
|
||||
<Button icon={<UploadOutlined />}>Загрузить файл</Button>
|
||||
</Upload>
|
||||
@ -144,7 +157,7 @@ export default function Documents() {
|
||||
<Button
|
||||
type="primary"
|
||||
htmlType="submit"
|
||||
disabled={fileList.length === 0}
|
||||
disabled={selectedFiles.length === 0}
|
||||
style={{marginLeft: '10px'}}
|
||||
>
|
||||
Отправить
|
||||
|
@ -1,8 +1,8 @@
|
||||
import Documents from "../components/Documents"
|
||||
|
||||
export default function Cementing() {
|
||||
export default function Cementing(id) {
|
||||
|
||||
return(
|
||||
<Documents />
|
||||
<Documents selectedFileCategory={id} />
|
||||
)
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
import Documents from "../components/Documents"
|
||||
|
||||
export default function DocumentsForWell() {
|
||||
export default function DocumentsForWell(id) {
|
||||
|
||||
return(
|
||||
<Documents />
|
||||
<Documents selectedFileCategory={id} />
|
||||
)
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
import Documents from "../components/Documents"
|
||||
|
||||
export default function FluidService() {
|
||||
export default function FluidService(id) {
|
||||
|
||||
return(
|
||||
<Documents />
|
||||
<Documents selectedFileCategory={id} />
|
||||
)
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
import Documents from "../components/Documents"
|
||||
|
||||
export default function Gti() {
|
||||
export default function Gti(id) {
|
||||
|
||||
return(
|
||||
<Documents />
|
||||
<Documents selectedFileCategory={id} />
|
||||
)
|
||||
}
|
@ -17,6 +17,7 @@ const openNotificationError = (message, title) => {
|
||||
|
||||
const setUser = (user) =>{
|
||||
OpenAPI.TOKEN = user.token
|
||||
localStorage['userId'] = user.id
|
||||
localStorage['token'] = user.token
|
||||
localStorage['login'] = user.login
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import Documents from "../components/Documents"
|
||||
|
||||
export default function Master() {
|
||||
export default function Master(id) {
|
||||
|
||||
return(
|
||||
<Documents />
|
||||
<Documents selectedFileCategory={id} />
|
||||
)
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
import Documents from "../components/Documents"
|
||||
|
||||
export default function Nnb() {
|
||||
export default function Nnb(id) {
|
||||
|
||||
return(
|
||||
<Documents />
|
||||
<Documents selectedFileCategory={id} />
|
||||
)
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
import Documents from "../components/Documents"
|
||||
|
||||
export default function Supervisor() {
|
||||
export default function Supervisor(id) {
|
||||
|
||||
return(
|
||||
<Documents />
|
||||
<Documents selectedFileCategory={id} />
|
||||
)
|
||||
}
|
@ -110,25 +110,25 @@ export default function Well() {
|
||||
<TelemetryView/>
|
||||
</Route>
|
||||
<Route path="/well/:id/fluidService">
|
||||
<FluidService/>
|
||||
<FluidService selectedFileCategory={1}/>
|
||||
</Route>
|
||||
<Route path="/well/:id/cementing">
|
||||
<Cementing/>
|
||||
<Cementing id={2}/>
|
||||
</Route>
|
||||
<Route path="/well/:id/nnb">
|
||||
<Nnb/>
|
||||
<Nnb id={3}/>
|
||||
</Route>
|
||||
<Route path="/well/:id/gti">
|
||||
<Gti/>
|
||||
<Gti id={4}/>
|
||||
</Route>
|
||||
<Route path="/well/:id/documentsForWell">
|
||||
<DocumentForWell/>
|
||||
<DocumentForWell id={5}/>
|
||||
</Route>
|
||||
<Route path="/well/:id/supervisor">
|
||||
<Supervisor/>
|
||||
<Supervisor id={6}/>
|
||||
</Route>
|
||||
<Route path="/well/:id/master">
|
||||
<Master/>
|
||||
<Master id={7}/>
|
||||
</Route>
|
||||
<Route path="/well/:id/lastData">
|
||||
<LastData/>
|
||||
|
@ -12,6 +12,8 @@ export type { DataSaubBaseDto } from './models/DataSaubBaseDto';
|
||||
export type { DatesRangeDto } from './models/DatesRangeDto';
|
||||
export type { DepositDto } from './models/DepositDto';
|
||||
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 { MessageDtoPaginationContainer } from './models/MessageDtoPaginationContainer';
|
||||
export type { OperationDto } from './models/OperationDto';
|
||||
@ -32,6 +34,7 @@ export { AuthService } from './services/AuthService';
|
||||
export { ClusterService } from './services/ClusterService';
|
||||
export { DataService } from './services/DataService';
|
||||
export { DepositService } from './services/DepositService';
|
||||
export { FileService } from './services/FileService';
|
||||
export { MessageService } from './services/MessageService';
|
||||
export { ReportService } from './services/ReportService';
|
||||
export { TelemetryService } from './services/TelemetryService';
|
||||
|
92
src/services/api/services/FileService.ts
Normal file
92
src/services/api/services/FileService.ts
Normal 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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user