import { useState, useRef } from "react"; import { Modal } from "@arco-design/web-react"; import { IconUpload, IconFile, IconDelete } from "@arco-design/web-react/icon"; import toast from "@/components/Toast"; import "./index.css"; const UploadModal = ({ visible, onClose }) => { const [isDragging, setIsDragging] = useState(false); const [uploadedFile, setUploadedFile] = useState(null); const fileInputRef = useRef(null); const handleDragOver = (e) => { e.preventDefault(); setIsDragging(true); }; const handleDragLeave = (e) => { e.preventDefault(); setIsDragging(false); }; const handleDrop = (e) => { e.preventDefault(); setIsDragging(false); const files = e.dataTransfer.files; if (files.length > 0) { handleFileSelect(files[0]); } }; const handleFileSelect = (file) => { // 验证文件类型 const allowedTypes = [ 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'text/plain', 'text/markdown', 'text/x-markdown' ]; const allowedExtensions = ['.pdf', '.doc', '.docx', '.txt', '.md', '.markdown']; const fileExtension = file.name.toLowerCase().match(/\.[^.]+$/)?.[0]; if (!allowedTypes.includes(file.type) && !allowedExtensions.includes(fileExtension)) { toast.error("请上传 PDF、Word、Markdown 或 TXT 格式的文件"); return; } // 验证文件大小(限制为10MB) if (file.size > 10 * 1024 * 1024) { toast.error("文件大小不能超过10MB"); return; } setUploadedFile(file); toast.success(`文件 ${file.name} 已选择`); }; const handleFileInputChange = (e) => { const file = e.target.files[0]; if (file) { handleFileSelect(file); } }; const handleUploadClick = () => { fileInputRef.current?.click(); }; const handleSubmit = () => { if (!uploadedFile) { toast.error("请先选择要上传的文件"); return; } // 这里可以添加实际的上传逻辑 toast.success("文件上传成功"); setUploadedFile(null); onClose(); }; const handleCancel = () => { setUploadedFile(null); onClose(); }; return (

选择文件上传

请选择您的项目文档进行上传,支持批量上传多个文件

{uploadedFile ? (

{uploadedFile.name}

{(uploadedFile.size / 1024 / 1024).toFixed(2)} MB 准备上传

) : (

点击选择文件或将文件拖拽至此处

支持 PDF、Word、Markdown、TXT 格式,单个文件不超过 10MB

)}
); }; export default UploadModal;