修改文件类型上传校验
This commit is contained in:
@ -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>
|
||||
);
|
||||
|
Reference in New Issue
Block a user