<img className="thumbnail-img" src={imageUrl || '/images/default.png'}/>
<input id="file_load" type="file" accept="image/*" ref={file} onChange={upload} />
const AllowImgType = ["image/jpeg", "image/png", "image/bmp"];
const upload = useCallback(() => {
if (file?.current?.files) {
let data = file?.current?.files[0];
if (data) {
if (!AllowImgType.includes(data.type)) {
message.error("图片格式不符合要求");
return;
}
const isLt8M = data.size / 1024 / 1024 < 8;
if (!isLt8M) {
message.error("图片不能超过8m");
return;
}
let imgFile = new FileReader();
imgFile.readAsDataURL(data);
imgFile.onload = (res: any) => {
setImageUrl(res.target.result);
};
}
}
}, [file, form]);