修改文件类型上传校验

This commit is contained in:
linxd
2025-08-05 15:45:52 +08:00
parent e07e925c42
commit 23b0e5e801
3 changed files with 64 additions and 56 deletions

View File

@ -50,7 +50,7 @@ const FileUpload: React.FC<FileUploadProps> = ({
listType = 'text',
buttonText,
disabled = false,
accept = allowedTypes.map(type => `.${type}`).join(','),
accept = allowedTypes.map((type) => `.${type}`).join(','),
showUploadList = true,
isDragger = false,
tip,
@ -62,7 +62,6 @@ const FileUpload: React.FC<FileUploadProps> = ({
// 监听value变化
useEffect(() => {
// 处理字符串URL值这是关键修复
if (typeof value === 'string' && value) {
const file: Partial<UploadFile> = {
@ -144,12 +143,12 @@ const FileUpload: React.FC<FileUploadProps> = ({
const filteredList = newFileList.filter((file) => file.status !== 'error');
// 为每个文件添加正确的url
const processedList = filteredList.map(file => {
const processedList = filteredList.map((file) => {
if (file.status === 'done' && file.response && !file.url) {
return {
...file,
url: getFileUrl(file),
filePath: file?.response?.filePath || "filePath not found",
filePath: file?.response?.filePath || 'filePath not found',
};
}
return file;
@ -163,7 +162,7 @@ const FileUpload: React.FC<FileUploadProps> = ({
};
const beforeUpload = (file: File) => {
return validateFileSize(file, maxSize);
return validateFileSize(file, maxSize, allowedTypes);
};
const UploadComponent = isDragger ? Upload.Dragger : Upload;
@ -204,7 +203,12 @@ const FileUpload: React.FC<FileUploadProps> = ({
}
return (
<Button type="link" style={{ padding: 0, height: 'auto',marginTop: 6 }} icon={<UploadOutlined />} disabled={disabled}>
<Button
type="link"
style={{ padding: 0, height: 'auto', marginTop: 6 }}
icon={<UploadOutlined />}
disabled={disabled}
>
{buttonText || defaultButtonText}
</Button>
);