This commit is contained in:
huyt 2022-01-08 21:14:14 +07:00
parent 4a36e76620
commit eb1b39b9fe
5 changed files with 8422 additions and 7464 deletions

2
.gitignore vendored
View File

@ -1,7 +1,7 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/app/node_modules
/.pnp
.pnp.js

795
app/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -75,6 +75,7 @@ export default function ListItem() {
icon: 'success',
title: 'Thành công',
text: 'Xoá thành công',
timer: 1500,
buttons: false,
})
getData(activePage)
@ -84,6 +85,7 @@ export default function ListItem() {
swal("Thất bại", "Xoá thất bại!", "error");
}
} catch (error) {
setLoading(false)
console.log(error);
}
}
@ -139,7 +141,7 @@ export default function ListItem() {
var listImg
if (value.sample_images.length > 0) {
listImg = <img key={index} style={{ width: "80px", height: "80px" }} alt={value.sample_images.length > 0 ? value.sample_images[0] : ""} src={`${value.sample_images.length > 0 && value.image_host + value.sample_images[0]}`} />
listImg = <img key={index} style={{ width: "80px", height: "80px" }} alt="" src={`${value.sample_images.length > 0 && value.image_host + value.sample_images[0]}`} />
} else {
listImg = <Avatar shape="square" size={80} icon={<UserOutlined />} />
}
@ -166,7 +168,7 @@ export default function ListItem() {
// title: "Are you sure?",
text: "Bạn có chắc muốn xoá " + value.name,
icon: "warning",
buttons: true,
buttons: ["Huỷ", "Xoá"],
dangerMode: true,
})
.then(willDelete => {
@ -187,15 +189,14 @@ export default function ListItem() {
const onCloseModal = () => {
setShowModal(false)
setActivePage(activePage)
getData(1)
}
const reset = () => {
setDataSearch("")
getData(1)
}
if (!data) return <></>
return (
<div>
{showModal && <Modaledit data={dataEdit} onHide={onCloseModal} show={showModal} />}
@ -239,6 +240,8 @@ export default function ListItem() {
<div className="pl-3">
<button
onClick={() => {
setActivePage(1)
setDataSearch("")
reset()
}}
className="btn btn-secondary m-btn m-btn--icon" id="m_reset">
@ -283,7 +286,7 @@ export default function ListItem() {
<th>Thao tác</th>
</tr>
</thead>
<tbody>{tableRows(data)}</tbody>
<tbody>{data && tableRows(data)}</tbody>
</table>
<PulseLoader
// css={override}

View File

@ -18,7 +18,6 @@ const Modaledit = (props) => {
const [form] = Form.useForm()
const fileInput = useRef(null);
const [birthday, setBirthday] = useState(moment())
const [crrData, setCrrData] = useState(null);
@ -29,13 +28,14 @@ const Modaledit = (props) => {
const [disableBtn, setDisableBtn] = useState(true);
const [listImgUpload, setListImgUpload] = useState([]);
const [hostImg, setHostImg] = useState('');
useEffect(() => {
setCrrData(data);
setCrrImages(data.sample_images)
setBirthday(data.birthday !== "" ? moment(data.birthday) : null)
setDisableBtn(data._id ? false : true)
setHostImg(data.image_host)
return () => {
setCrrData(null);
}
@ -80,6 +80,7 @@ const Modaledit = (props) => {
icon: 'success',
title: 'Thành công',
text: 'Sửa thông tin thành công',
timer: 1500,
buttons: false,
})
} else {
@ -87,8 +88,10 @@ const Modaledit = (props) => {
icon: 'success',
title: 'Thành công',
text: 'Thêm mới thành công',
timer: 1500,
buttons: false,
})
setCrrData({...crrData, _id: result.data.data})
setDisableBtn(false)
}
} else if (result.data.status === 10004) {
@ -100,7 +103,7 @@ const Modaledit = (props) => {
const bulletedImg = crrImages.map((value, index) => {
let renderImg = value.includes("data:image") ? value : data.image_host + value
let renderImg = value.includes("data:image") ? value : hostImg + value
return (
<div className="img-res col-md-4 pl-0 mb-3" key={index + 1}>
<div style={{ 'height': 80 }}>
@ -125,58 +128,13 @@ const Modaledit = (props) => {
)
})
const onChangeFile = async (event) => {
const file = event.target.files[0]
const base64 = await convertBase64(file)
let imgUplpad = [...crrImages]
imgUplpad.push(base64)
setCrrImages(imgUplpad)
setCheckDeleteMulti(false)
}
const onClickUpload = () => {
if (crrImages.length >= 3) {
swal("Cảnh báo", "Số lượng ảnh tải lên tối đa là 3", "warning")
} else {
fileInput.current.click()
}
}
const handleChange = (event) => {
}
const onUpload = async (file) => {
console.log(file)
const base64 = await convertBase64(file)
let dataUploadImg = {
obj_id: crrData._id ? crrData._id : "",
base64_image_list: [base64.split(',')[1]]
}
fetch(`${HOST}/api/face_images/famous_person`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
// 'Authorization': token
},
body: JSON.stringify(dataUploadImg)
})
.then(res => res.json())
.then(data => {
console.log(data)
if (data.status === 10000) {
let listImg = [...crrImages]
listImg.unshift(data.data.toString())
setCrrImages(listImg)
setCheckDeleteMulti(false)
}
})
}
const uploadImage = async (options) => {
if (crrImages.length >= 3) {
swal("Cảnh báo", "Bạn chỉ được tải lên tối đa 3 ảnh!", "warning");
return
} else {
const { file } = options;
const base64 = await convertBase64(file)
@ -197,13 +155,15 @@ const Modaledit = (props) => {
.then(res => res.json())
.then(data => {
if (data.status === 10000) {
setHostImg(data.image_host)
let listImg = [...crrImages]
listImg.unshift(data.data.toString())
setCrrImages(listImg)
setCheckDeleteMulti(false)
}
})
};
}
};
@ -276,7 +236,7 @@ const Modaledit = (props) => {
<div className="row justify-content-center pb-3">
{
crrImages[crrIdx] ?
<Avatar shape="square" src={crrImages[crrIdx].includes("data:image") ? crrImages[crrIdx] : data.image_host + crrImages[crrIdx]} size={180} icon={<UserOutlined />} /> :
<Avatar shape="square" src={crrImages[crrIdx].includes("data:image") ? crrImages[crrIdx] : hostImg + crrImages[crrIdx]} size={180} icon={<UserOutlined />} /> :
<Avatar shape="square" size={180} icon={<UserOutlined />} />
}

File diff suppressed because it is too large Load Diff