diff --git a/app/routes/files.upload.tsx b/app/routes/files.upload.tsx index ce7d8f0..5940339 100644 --- a/app/routes/files.upload.tsx +++ b/app/routes/files.upload.tsx @@ -608,12 +608,18 @@ export default function FilesUpload() { // 处理文件选择 const handleFilesSelected = (files: FileList) => { if (files.length > 0) { - // 验证文件类型,只允许PDF文件 + // 验证文件类型,支持PDF和Word文件 const validFiles: File[] = []; let hasInvalidFiles = false; Array.from(files).forEach(file => { - if (file.type === 'application/pdf' || file.name.toLowerCase().endsWith('.pdf')) { + const fileName = file.name.toLowerCase(); + const isValidType = + file.type === 'application/pdf' || fileName.endsWith('.pdf') || + file.type === 'application/msword' || fileName.endsWith('.doc') || + file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' || fileName.endsWith('.docx'); + + if (isValidType) { validFiles.push(file); } else { hasInvalidFiles = true; @@ -622,7 +628,7 @@ export default function FilesUpload() { if (hasInvalidFiles) { // 显示错误提示 - messageService.error('只能上传PDF格式的文件', { + messageService.error('只支持PDF、Word格式的文件', { title: '文件类型错误', confirmText: '确定', cancelText: '', @@ -1157,13 +1163,18 @@ export default function FilesUpload() { } // 再次验证所有文件类型,确保只有PDF文件 - const invalidFiles = files.filter(file => - file.type !== 'application/pdf' && !file.name.toLowerCase().endsWith('.pdf') - ); + const invalidFiles = files.filter(file => { + const fileName = file.name.toLowerCase(); + const isValidType = + file.type === 'application/pdf' || fileName.endsWith('.pdf') || + file.type === 'application/msword' || fileName.endsWith('.doc') || + file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' || fileName.endsWith('.docx'); + return !isValidType; + }); if (invalidFiles.length > 0) { console.error('【调试-startUpload】文件类型验证失败:', invalidFiles.map(f => f.name)); - throw new Error('只能上传PDF格式的文件'); + throw new Error('只支持PDF、Word格式的文件'); } setUploadStage("uploading"); @@ -2081,8 +2092,8 @@ export default function FilesUpload() { ref={uploadAreaRef} onFilesSelected={handleFilesSelected} multiple={true} - accept=".pdf" - tipText="支持单个或多个pdf文件上传,文件格式:PDF" + accept=".pdf,.doc,.docx" + tipText="支持单个或多个文件上传,文件格式:PDF/Word" shouldPreventFileSelect={!fileType} /> ) : (