|
|
|
@ -199,20 +199,14 @@ const handleRemove = async (id?: number, type?: number) => {
|
|
|
|
|
|
|
|
|
|
const dateFormat = 'YYYYMMDD';
|
|
|
|
|
|
|
|
|
|
const getBase64 = (img: RcFile, callback: (url: string) => void) => {
|
|
|
|
|
const reader = new FileReader();
|
|
|
|
|
reader.addEventListener('load', () => callback(reader.result as string));
|
|
|
|
|
reader.readAsDataURL(img);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const beforeUpload = (file: RcFile) => {
|
|
|
|
|
const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
|
|
|
|
|
if (!isJpgOrPng) {
|
|
|
|
|
message.error('You can only upload JPG/PNG file!');
|
|
|
|
|
message.error('你只能上传JPG/PNG文件!');
|
|
|
|
|
}
|
|
|
|
|
const isLt2M = file.size / 1024 / 1024 < 2;
|
|
|
|
|
const isLt2M = file.size / 1024 / 1024 < 1;
|
|
|
|
|
if (!isLt2M) {
|
|
|
|
|
message.error('Image must smaller than 2MB!');
|
|
|
|
|
message.error('图片必须小于1MB!');
|
|
|
|
|
}
|
|
|
|
|
return isJpgOrPng && isLt2M;
|
|
|
|
|
};
|
|
|
|
@ -675,6 +669,8 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
|
|
|
|
const [imageUrl, setImageUrl] = useState<string>(props.values.employeeName && props.values.cardNo ? `http://localhost:8888/upload/${props.values.employeeName}_${props.values.cardNo}.jpg`:'');
|
|
|
|
|
|
|
|
|
|
const handleChange: UploadProps['onChange'] = (info: UploadChangeParam<UploadFile>) => {
|
|
|
|
|
console.log(info.file)
|
|
|
|
|
setFileList(info.fileList)
|
|
|
|
|
if (info.file.status === 'uploading') {
|
|
|
|
|
setLoading(true);
|
|
|
|
|
return;
|
|
|
|
@ -682,6 +678,15 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
|
|
|
|
if (info.file.status === 'done') {
|
|
|
|
|
console.log(info.file.response)
|
|
|
|
|
setLoading(false);
|
|
|
|
|
if (fileList.length > 0) {
|
|
|
|
|
let newFileList = [...fileList]
|
|
|
|
|
newFileList[0].status = 'done'
|
|
|
|
|
newFileList[0].url = info.file.response
|
|
|
|
|
newFileList[0].preview = info.file.response
|
|
|
|
|
newFileList[0].thumbUrl = info.file.response
|
|
|
|
|
console.log(newFileList)
|
|
|
|
|
setFileList(newFileList)
|
|
|
|
|
}
|
|
|
|
|
setImageUrl(info.file.response);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
@ -729,6 +734,8 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
|
|
|
|
// },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const [fileList, setFileList] = useState<UploadFile[]>([]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
@ -738,6 +745,14 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
|
|
|
|
getData(props.values.employeeNo, 3);
|
|
|
|
|
getData(props.values.employeeNo, 4);
|
|
|
|
|
}
|
|
|
|
|
if (props.values.employeeName && props.values.cardNo) {
|
|
|
|
|
setFileList([{
|
|
|
|
|
uid: '-1',
|
|
|
|
|
name: 'image.png',
|
|
|
|
|
status: 'done',
|
|
|
|
|
url: `http://localhost:8888/upload/${props.values.employeeName}_${props.values.cardNo}.jpg`
|
|
|
|
|
}])
|
|
|
|
|
}
|
|
|
|
|
}, [props.values.employeeNo]);
|
|
|
|
|
|
|
|
|
|
console.log(imageUrl)
|
|
|
|
@ -784,17 +799,18 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
|
|
|
|
name="file"
|
|
|
|
|
listType="picture-card"
|
|
|
|
|
className="avatar-uploader"
|
|
|
|
|
showUploadList={false}
|
|
|
|
|
fileList={fileList}
|
|
|
|
|
action="http://localhost:8888/api/employee/uploadImage"
|
|
|
|
|
beforeUpload={beforeUpload}
|
|
|
|
|
disabled={!!imageUrl}
|
|
|
|
|
onChange={handleChange}
|
|
|
|
|
>
|
|
|
|
|
{imageUrl ? <Image
|
|
|
|
|
{fileList.length > 0 ? null : uploadButton}
|
|
|
|
|
{/* <Image
|
|
|
|
|
style={{ objectFit: 'contain' }}
|
|
|
|
|
width={200}
|
|
|
|
|
height={200}
|
|
|
|
|
src={imageUrl}
|
|
|
|
|
fallback={EmptyImage}
|
|
|
|
|
/> : uploadButton}
|
|
|
|
|
/> */}
|
|
|
|
|
</Upload>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|