Merge pull request 'them tinh nang test, va chia nho file api import image' (#6) from feature/test-page into dev

Reviewed-on: huyt/fsi_project#6
This commit is contained in:
huyt 2022-01-12 16:01:27 +00:00
commit b52defc64f
4 changed files with 87 additions and 37 deletions

View File

@ -21,7 +21,8 @@ function App() {
<Header />
<MenuBar />
<div>
<Redirect exact from='/' to='/search-image' />
{/* <Redirect exact from='/' to='/search-image' /> */}
<Route exact path='/' component={SearchImage} />
<Route path='/login' component={Login} />
<Route path='/import-image' component={ImportImage} />
<Route path='/search-image' component={SearchImage} />

View File

@ -249,14 +249,14 @@ class ImportImage extends Component {
data-col-index={0}
/>
</div>
<div className="form-group m-form__group col-xl-2">
{/* <div className="form-group m-form__group col-xl-2">
<Select
placeholder={'Loại ảnh'}
value={this.state.valueSelected}
onChange={this.changeHandleFilter}
options={this.state.optionSelect}
/>
</div>
</div> */}
<div className="pl-3">
<button
onClick={() => {

View File

@ -18,43 +18,64 @@ const ModalUpload = (props) => {
const [loading, setLoading] = useState(false);
const handleDrop = async acceptedFiles => {
let formData = new FormData()
const fileObjects = acceptedFiles.map(file => {
formData.append('files', file, file.name)
})
setLoading(true)
try {
let result = await axios
.post(`${HOST}/api/files_face_import`, formData, {
headers: {
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJjbGFzc2lmeS9sb2dpbiJdLCJleHAiOjE2NDE5NzQ5NjV9.2F2PAUKjpfjPJKzgvzgCDtyBuTXDRl86EnJJGdYgWTM'
}
})
console.log(result)
if (result.data.status === 10000) {
swal({
text: "Tải ảnh lên thành công",
icon: "success",
// buttons: ["Thử lại", "Huỷ"],
let promises = [];
let arrCheck = []
let quantity_per_part = 1
let separate_total = (acceptedFiles.length/quantity_per_part) + 1
for (let i = 0; i < separate_total; i++) {
let start = i*quantity_per_part
let end = (i+1)*quantity_per_part
let arr = acceptedFiles.slice(start, end)
arrCheck.push(arr)
let formData = new FormData()
if (arr.length > 0) {
const fileObjects = arr.map(file => {
formData.append('files', file, file.name)
})
.then(willTry => {
if (willTry) {
onHide()
promises.push(
axios
.post(`${HOST}/api/files_face_import`, formData, {
headers: {
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/x-www-form-urlencoded",
}
})
} else if (result.data.status === 10002) {
swal("Thất bại", "Lỗi hệ thống!", "error")
} else if (result.data.status === 10003) {
swal("Thất bại", "Không có quyền!", "error")
)
}
} catch (error) {
console.log(error)
swal("Thất bại", "Tải ảnh lên thất bại!", "error")
}
await Promise.all(promises)
.then((data) => {
let success = false
for (let i = 0; i < data.length; i++) {
const element = data[i];
if (element.data.status === 10000) {
success = true
} else (
success = false
)
}
if (success) {
swal({
text: "Tải ảnh lên thành công",
icon: "success",
// buttons: ["Thử lại", "Huỷ"],
})
.then(willTry => {
if (willTry) {
onHide()
}
})
} else {
swal("Thất bại", "Lỗi hệ thống!", "error")
}
console.log(data)
})
.catch((err) => {
console.log(err)
});
setLoading(false)
}

View File

@ -11,9 +11,29 @@ import swal from 'sweetalert';
import { useLocation } from 'react-router-dom';
export default function Test() {
const [text, setText] = useState("")
const [loading, setLoading] = useState(false)
const test = () => {
setLoading(true)
try {
let result = axios.get(`${HOST}/api/test_accuracy`)
.then(response => {
console.log(response)
setText(response.data.data)
})
.catch(error => {
console.log(error);
});
} catch (error) {
console.log(error);
}
setLoading(false)
}
return (
<div>
@ -28,14 +48,22 @@ export default function Test() {
</div>
</div>
<div className="m-portlet__body pt-2">
<div className="pb-4 pt-4">
<button type="button" onClick={() => test()} className="btn btn-success">Test</button>
</div>
<PulseLoader
// css={override}
sizeUnit={"px"}
size={12}
margin={'2px'}
color={'#36D7B7'}
// loading={loading}
loading={loading}
/>
{text.length > 0 && text.map((item, index) => {
return (
<p>{item}</p>
)
})}
</div>
</div>