From 86c4a36e6332bb2ef25e047dc8590b8b731ce56a Mon Sep 17 00:00:00 2001 From: Wren Date: Fri, 12 Sep 2025 11:16:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=94=AF=E6=8C=81PDF?= =?UTF-8?q?=E5=92=8CWord=E6=A0=BC=E5=BC=8F=E7=9A=84=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=EF=BC=8C=E4=BF=AE=E6=94=B9=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E9=80=89=E6=8B=A9=E5=99=A8=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=97=E6=A0=BC=E5=BC=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/routes/files.upload.tsx | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) 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} /> ) : (