feat: 1. 实现一键替换。
2. 优化追加附件和模板上传的样式。
This commit is contained in:
@@ -791,21 +791,34 @@ export default function DocumentsIndex() {
|
||||
const handleAttachmentFilesSelected = (files: FileList) => {
|
||||
try {
|
||||
console.log('【附件追加】开始处理附件文件选择, 文件数量:', files.length);
|
||||
|
||||
|
||||
if (files.length > 0) {
|
||||
// 检查主文件类型
|
||||
const selectedDocument = documents.find(doc => doc.id === selectedDocumentId);
|
||||
const isMainFileDocx = selectedDocument?.path.toLowerCase().endsWith('.docx');
|
||||
|
||||
// 验证文件类型,支持PDF、Word、ZIP、RAR
|
||||
const validFiles: File[] = [];
|
||||
let hasInvalidFiles = false;
|
||||
|
||||
let hasPdfForDocx = false;
|
||||
|
||||
Array.from(files).forEach(file => {
|
||||
const fileName = file.name.toLowerCase();
|
||||
const isValidType =
|
||||
file.type === 'application/pdf' || fileName.endsWith('.pdf') ||
|
||||
file.type === 'application/msword' || fileName.endsWith('.doc') ||
|
||||
const isPdf = file.type === 'application/pdf' || fileName.endsWith('.pdf');
|
||||
const isValidType =
|
||||
isPdf ||
|
||||
// file.type === 'application/msword' || fileName.endsWith('.doc') ||
|
||||
file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' || fileName.endsWith('.docx') ||
|
||||
file.type === 'application/zip' || fileName.endsWith('.zip') ||
|
||||
file.type === 'application/x-rar-compressed' || fileName.endsWith('.rar');
|
||||
|
||||
|
||||
// 如果主文件是docx,不允许上传pdf附件
|
||||
if (isMainFileDocx && isPdf) {
|
||||
hasPdfForDocx = true;
|
||||
console.error(`【附件追加】主文件为DOCX格式时不允许上传PDF附件: ${file.name}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isValidType) {
|
||||
validFiles.push(file);
|
||||
} else {
|
||||
@@ -813,15 +826,21 @@ export default function DocumentsIndex() {
|
||||
console.error(`【附件追加】无效的文件类型: ${file.name}, 类型: ${file.type}`);
|
||||
}
|
||||
});
|
||||
|
||||
if (hasInvalidFiles) {
|
||||
|
||||
if (hasPdfForDocx) {
|
||||
messageService.error('主文件为DOCX格式时,附件不可以是PDF格式', {
|
||||
title: '文件类型限制',
|
||||
confirmText: '确定',
|
||||
cancelText: '',
|
||||
});
|
||||
} else if (hasInvalidFiles) {
|
||||
messageService.error('只支持PDF、Word、ZIP、RAR格式的文件', {
|
||||
title: '文件类型错误',
|
||||
confirmText: '确定',
|
||||
cancelText: '',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (validFiles.length > 0) {
|
||||
setAttachmentFiles(validFiles);
|
||||
console.log('【附件追加】有效文件数量:', validFiles.length);
|
||||
@@ -887,14 +906,14 @@ export default function DocumentsIndex() {
|
||||
const fileName = file.name.toLowerCase();
|
||||
const isValidType =
|
||||
file.type === 'application/pdf' || fileName.endsWith('.pdf') ||
|
||||
file.type === 'application/msword' || fileName.endsWith('.doc') ||
|
||||
// file.type === 'application/msword' || fileName.endsWith('.doc') ||
|
||||
file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' || fileName.endsWith('.docx');
|
||||
|
||||
if (isValidType) {
|
||||
setTemplateFile(file);
|
||||
console.log('【合同模板上传】有效文件:', file.name);
|
||||
} else {
|
||||
messageService.error('只支持PDF、Word格式的文件', {
|
||||
messageService.error('只支持.pdf、.docx格式的文件', {
|
||||
title: '文件类型错误',
|
||||
confirmText: '确定',
|
||||
cancelText: '',
|
||||
@@ -1584,7 +1603,7 @@ export default function DocumentsIndex() {
|
||||
目标文档ID: <span className="font-medium">{selectedDocumentId}</span>
|
||||
</p>
|
||||
<p className="text-xs text-gray-500 mt-1">
|
||||
支持PDF、Word、ZIP、RAR格式,ZIP/RAR内仅合并其中的PDF文件
|
||||
支持.pdf、.docx、ZIP、RAR格式。ZIP/RAR内需要保证文件格式一致,否则报错
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -1732,7 +1751,7 @@ export default function DocumentsIndex() {
|
||||
目标文档ID: <span className="font-medium">{selectedDocumentId}</span>
|
||||
</p>
|
||||
<p className="text-xs text-gray-500 mt-1">
|
||||
支持PDF、Word格式,用于与合同文档进行结构对比
|
||||
支持.pdf、.docx格式,用于与合同文档进行结构对比
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -1744,7 +1763,7 @@ export default function DocumentsIndex() {
|
||||
<div className="border-2 border-dashed border-gray-300 rounded-lg p-6 text-center hover:border-gray-400 transition-colors">
|
||||
<input
|
||||
type="file"
|
||||
accept=".pdf,.doc,.docx"
|
||||
accept=".pdf,.docx"
|
||||
onChange={(e) => e.target.files && handleTemplateFileSelected(e.target.files)}
|
||||
className="hidden"
|
||||
id="template-file-input"
|
||||
@@ -1752,7 +1771,7 @@ export default function DocumentsIndex() {
|
||||
<label htmlFor="template-file-input" className="cursor-pointer">
|
||||
<i className="ri-file-copy-line text-3xl text-gray-400 mb-2 block"></i>
|
||||
<p className="text-sm text-gray-600">点击选择文件或拖拽文件到此处</p>
|
||||
<p className="text-xs text-gray-500 mt-1">支持PDF、Word格式</p>
|
||||
<p className="text-xs text-gray-500 mt-1">支持.pdf、.docx格式</p>
|
||||
</label>
|
||||
</div>
|
||||
{templateFile && (
|
||||
|
||||
Reference in New Issue
Block a user