对上传文件进行限制,只能是 JPG, PNG ,Word,Xlsx或Pdf 文件
上传 下载 回显
const UploadProps: UploadProps = {
name: 'file',
listType: 'text',
action: `${environment.baseUrl}/api/Files/UploadFile/EmailAttach`,
headers: {
Authorization: getAuthority(),
},
maxCount: 1,
beforeUpload(file) {
const isJpgOrPng =
file.type === 'image/jpeg' ||
file.type === 'image/png' ||
file.type === 'application/pdf' ||
file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' ||
file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
;
if (!isJpgOrPng) {
message.error('附件只能是 JPG, PNG ,Word,Xlsx或Pdf 文件!');
return Upload.LIST_IGNORE;
}
const isLt2M = file.size / 1024 / 1024 < 3;
if (!isLt2M) {
message.error('文件大小必须小于3MB!');
return Upload.LIST_IGNORE;
}
return isJpgOrPng && isLt2M;
},
onChange(info) {
if (info.file.status === 'uploading') {
return;
}
if (info.file.status === 'done') {
setAttachFilePath(info.file.response.ResData);
}
},
};
const UploadBtns = () => {
if (dataItem?.AppendixUrl) {
return (
<>
<div className="appendix_url">
<a href={`${baseUrl}${dataItem?.AppendixUrl}`} target="_blank">
<Tooltip title="Click to download the file">
<div style={{ width: '10%' }}>
<img src={wordImg} alt="" />
<span>Sick leave</span>
</div>
</Tooltip>
</a>
</div>
</>
)
} else if (!dataItem?.AppendixUrl && !action) {
return (
<>
<div className="upload_btn">
<Form.Item name="AppendixUrl"
rules={[
{
required: true,
message: 'Please upload the resignation letter',
}
]}
>
<Upload {...UploadProps}>
<Button
className="add_appendix"
icon={<PlusOutlined />}
size="large"
>
Add appendix
</Button>
</Upload>
</Form.Item>
</div>
</>
)
}
}