import { Card, Image as ImageAntd } from 'antd'; import Header from 'components/layouts/Header'; import Parser from 'html-react-parser'; import $ from 'jquery'; import React, { Component } from 'react'; import "react-datepicker/dist/react-datepicker.css"; import ReactFileReader from 'react-file-reader'; import Pagination from "react-js-pagination"; import { PulseLoader } from 'react-spinners'; import swal from 'sweetalert'; import { HOST } from '../../config/index'; import Store from '../../store'; class SearchImage extends Component { constructor(props) { super(props); this.state = { loading: false, listHistory: [], crrHistory: [], dataVerification: null, filesImagePerson: "", page_num: 1, page_size: 10, total_count: 0, valueRes: 100, threshold: 50, similarity: 70, value: 0, selectedEncoding: [], boxs: [], slides: [], encodings: [], plugins: [], nimages: [], showModal: false, crrdatainfo: null, offset: 0, showFirst: 0, showLast: 0, totalLength: 0, dataRole: Store.getState().role.role, isLogin: Store.getState().isLogin.isLogin, }; Store.subscribe(() => { this.setState({ isLogin: Store.getState().isLogin.isLogin, dataRole: Store.getState().role.role, }, () => { }); }); this.onchange = this.onchange.bind(this); this.closeModal = this.closeModal.bind(this); var itemsPerPage = 6; if ($(window).width() >= 1400 && $(window).width() < 1750) { itemsPerPage = 6 } else if ($(window).width() <= 1280 ) { itemsPerPage = 6 } else { itemsPerPage = 8 } this.itemsPerPage = itemsPerPage; } componentDidMount() { window.$('.carousel').carousel({ interval: false, wrap: false }).on('slid.bs.carousel', function () { var curSlide = window.$('.active'); if (curSlide.is(':first-child')) { window.$('.carousel-control-prev').hide(); window.$('.carousel-control-next').show(); } else if (curSlide.is(':last-child')) { window.$('.carousel-control-prev').show(); window.$('.carousel-control-next').hide(); } else { window.$('.carousel-control-prev').show(); window.$('.carousel-control-next').show(); } }); } onchange(value) { this.setState({ value }); } closeModal() { this.setState({ showModal: false, }) } handlePrevChange() { var index = this.state.value; index = index - 1 if (index >= 0) this.setState({ value: index, selectedEncoding: this.state.encodings[index], }) } handleNextChange() { var index = this.state.value; if (index < (this.state.encodings.length - 1)) index = index + 1 this.setState({ value: index, selectedEncoding: this.state.encodings[index], }) } changeFace(index) { this.setState({ value: index, selectedEncoding: this.state.encodings[index], }, () => { this.getPerson() }) } getPerson() { if (!this.state.valueRes || !this.state.threshold) { return swal('Cảnh báo!', 'Vui lòng điền đầy đủ các trường', 'warning'); } this.setState({ loading: true, }); fetch(`${HOST}/api/search_people`, { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': Store.getState().isLogin.access_token, }, body: JSON.stringify({ encodings: this.state.selectedEncoding, image: "", threshold: parseInt(this.state.threshold) / 100, result_number: this.state.valueRes, }) }).then((response) => { return response.json() }).then((rs) => { if (rs.status === 10000) { var data = rs.data; this.setState({ listHistory: data, loading: false, // total_count: rs.count, }); this.FilterSearch(this.state.page_num) } else if (rs.status === 10003) { if (rs.message === 'No face in image') { swal("Lỗi", "Ảnh không có khuôn mặt!", "error"); } else if (rs.message === 'Too many face') { swal("Lỗi", "Ảnh có quá nhiều khuôn mặt!", "error"); } else { swal("Lỗi", "Ảnh không đạt yêu cầu!", "error"); } this.setState({ listHistory: [], loading: false, }); } else if (rs.status === 10002) { swal("Lỗi", "Lỗi hệ thống!", "error"); this.setState({ listHistory: [], loading: false, }); } else { swal("Lỗi!", "Ảnh không hợp lệ!", "error"); this.setState({ listHistory: [], loading: false, }); } }).catch((error) => { if (error) { console.log(error) swal("Lỗi!", "Ảnh không hợp lệ!", "error"); this.setState({ listHistory: [], loading: false, total_count: 0, }); } }) } getFaces() { var image_base64; image_base64 = this.state.filesImagePerson.replace('data:image/png;base64,', ''); image_base64 = image_base64.replace('data:image/jpg;base64,', ''); image_base64 = image_base64.replace('data:image/jpeg;base64,', ''); fetch(`${HOST}/api/face_images/faces`, { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': Store.getState().isLogin.access_token, }, body: JSON.stringify({ image: image_base64 }) }).then((response) => { return response.json() }).then((rs) => { if (rs.status === 10000) { var boxs = [] var item = "" var encodings = [] rs.imgs.map((value, index) => { var item_active = "" // var item_inactive = "" if (index === 0) { item += "