fix & add

This commit is contained in:
huyt 2021-03-26 15:27:30 +07:00
parent f50c507d5e
commit a3a4c28fbf

View File

@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Avatar, Button, Input, Select, Table } from 'antd'; import { Avatar, Button, Input, Select, Table, Pagination, message, Spin,Image } from 'antd';
import axios from 'axios'; import axios from 'axios';
import moment from 'moment'; import moment from 'moment';
import DatePicker from "react-datepicker"; import DatePicker from "react-datepicker";
@ -7,16 +7,17 @@ import "react-datepicker/dist/react-datepicker.css";
import 'antd/dist/antd.css'; import 'antd/dist/antd.css';
const columns = [ const columns = [
{ {
title: 'Avt Origin', title: 'Avt Origin',
dataIndex: 'url_origin_img', dataIndex: 'url_origin_img',
render: (url_origin_img) => <Avatar src={url_origin_img} size={100} />, render: (url_origin_img) => <Image preview={false} src={url_origin_img} height={100} width={100} />,
width: '20%', width: '20%',
}, },
{ {
title: 'Avt Input', title: 'Avt Input',
dataIndex: 'url_input_img', dataIndex: 'url_input_img',
render: (url_input_img) => <Avatar src={url_input_img} size={100} />, render: (url_input_img) => <Image preview={false} src={url_input_img} height={100} width={100} />,
width: '20%', width: '20%',
}, },
{ {
@ -57,38 +58,81 @@ const Test = () => {
const [inputURL, setInputURL] = useState(); const [inputURL, setInputURL] = useState();
const [inputConfidence, setInputConfidence] = useState(); const [inputConfidence, setInputConfidence] = useState();
const [loading, setLoading] = useState(false);
const [dataCount, setDataCount] = useState(0)
const [itemPerPage, setItemPerPage] = useState(10) const [itemPerPage, setItemPerPage] = useState(10)
const onChange = page => { const onChangePage = page => {
setCurrentPage(page); setCurrentPage(page);
}; };
const handleChangePageSize = (e) => {
setItemPerPage(e)
}
const onChangeSize = (current, size) => {
setCurrentPage(current)
setItemPerPage(size)
}
useEffect(() => {
fetchData()
}, [currentPage, itemPerPage])
const fetchData = () => { const fetchData = () => {
if (inputCam) { if (inputCam) {
var splitCam = inputCam.split(','); var splitCam = inputCam.split(',');
} }
if (inputURL) {
setLoading(true)
fetch(`${inputURL}/api/statistic_histories`, { fetch(`${inputURL}/api/statistic_histories`, {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
'start_date': moment(startDate).format("YYYY-MM-DD 00:00:00"), 'start_date': moment(startDate).format("YYYY-MM-DD 00:00:00"),
'end_date': moment(endDate).format("YYYY-MM-DD 00:00:00"), 'end_date': moment(endDate).format("YYYY-MM-DD 00:00:00"),
'index': 1, 'index': currentPage,
'item_per_page': itemPerPage, 'item_per_page': itemPerPage,
'confidence': +inputConfidence, 'confidence': +inputConfidence,
"ids_camera": splitCam "ids_camera": splitCam
}) })
}) })
.then((response) => response.json()) .then((response) => response.json())
.then((data) => { .then((data) => {
setData(data.data) if (data.status === 10000) {
setData(data.data.histories)
setDataCount(data.data.count)
setLoading(false)
}
else {
message.error({
content: "FETCH DATA ERROR",
className: 'custom-class',
style: {
textAlign: "left",
},
}) })
setLoading(false)
}
})
.catch(error => {
message.error("FETCH DATA ERROR")
setLoading(false)
});
} else {
message.error({
content: "URL required",
duration: 1,
className: 'custom-class',
style: {
textAlign: "left",
},
})
}
} }
const onChangeInput = (e) => { const onChangeInput = (e) => {
@ -103,26 +147,14 @@ const Test = () => {
setInputConfidence(e.target.value) setInputConfidence(e.target.value)
} }
const handleChangePageSize = (e) => {
setItemPerPage(e)
console.log(itemPerPage)
}
useEffect(() => { useEffect(() => {
fetchData() fetchData()
}, [itemPerPage]) }, [currentPage])
console.log(itemPerPage)
const indexOfLastData = currentPage * itemPerPage;
const indexOfFirstData = indexOfLastData - itemPerPage;
const currentData = data.slice(indexOfFirstData, indexOfLastData)
const totalData = data.length;
console.log(currentData)
return ( return (
<div style={{ width: '100%' }}> <div style={{ width: '100%' }}>
@ -146,7 +178,7 @@ const Test = () => {
<div style={{ display: 'flex', justifyContent: 'center', marginTop: "30px" }}> <div style={{ display: 'flex', justifyContent: 'center', marginTop: "30px" }}>
<Input <Input
style={{ width: 500 }} style={{ width: 500 }}
placeholder="URL" placeholder="http://api.demo.beetai.com"
onChange={onChangeInputURL} onChange={onChangeInputURL}
/> />
</div> </div>
@ -194,18 +226,21 @@ const Test = () => {
) )
}) })
} */} } */}
<Spin spinning={loading}>
<Table <Table
columns={columns} columns={columns}
dataSource={currentData} dataSource={data}
pagination={false}
/> />
<Select defaultValue="10" style={{ width: 80, marginBottom: "30px" }} onChange={handleChangePageSize}> </Spin>
{/* <Select defaultValue="10" style={{ width: 80, marginBottom: "30px" }} onChange={handleChangePageSize}>
<Option value={10}>10</Option> <Option value={10}>10</Option>
<Option value={50}>50</Option> <Option value={50}>50</Option>
<Option value={100}>100</Option> <Option value={100}>100</Option>
<Option value={1000}>1000</Option> <Option value={1000}>1000</Option>
<Option value={5000}>5000</Option> <Option value={5000}>5000</Option>
</Select> </Select> */}
</div> </div>
</div> </div>
{/* <div className="right"> {/* <div className="right">
@ -213,11 +248,15 @@ const Test = () => {
</div> */} </div> */}
</div> </div>
<div style={{ display: 'flex', justifyContent: 'center', marginTop: "20px" }}> <div style={{ display: 'flex', justifyContent: 'center', marginTop: "20px" }}>
{/* <Pagination <Pagination
current={currentPage} current={currentPage}
onChange={onChange} onChange={onChangePage}
total={totalData} defaultPageSize={itemPerPage}
/> */} total={dataCount}
pageSizeOptions={[20, 50, 100, 500]}
onShowSizeChange={onChangeSize}
/>
{/* <Select defaultValue="10" style={{ width: 80 }} onChange={handleChangePageSize}> {/* <Select defaultValue="10" style={{ width: 80 }} onChange={handleChangePageSize}>
<Option value={10}>10</Option> <Option value={10}>10</Option>
<Option value={20}>20</Option> <Option value={20}>20</Option>