import React, { useRef, useEffect } from 'react'; /** * 文件上传模态框组件 */ const FileUploadModal = ({ show, newFile, fileErrors, isSubmitting, onClose, onDescriptionChange, onFileChange, onFileDrop, onDragOver, onUploadAreaClick, onUpload, }) => { const fileInputRef = useRef(null); const modalRef = useRef(null); // 处理上传区域点击事件 const handleUploadAreaClick = () => { fileInputRef.current?.click(); }; // 处理拖拽事件 const handleDragOver = (e) => { e.preventDefault(); e.stopPropagation(); onDragOver?.(e); }; const handleDrop = (e) => { e.preventDefault(); e.stopPropagation(); onFileDrop?.(e); }; // 清理函数 useEffect(() => { return () => { // 确保在组件卸载时清理所有引用 if (fileInputRef.current) { fileInputRef.current.value = ''; } if (modalRef.current) { modalRef.current = null; } }; }, []); if (!show) return null; return (
已选择文件:
{newFile.file.name}
点击或拖拽文件到此处上传
支持 PDF, DOCX, TXT, CSV 等格式