更新文件上传功能,支持PDF和Word格式的文件验证,修改相关提示信息,优化文件选择器的接受格式。
This commit is contained in:
+24
-12
@@ -695,12 +695,18 @@ export default function FilesUpload() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (files.length > 0) {
|
if (files.length > 0) {
|
||||||
// 验证文件类型,只允许PDF文件
|
// 验证文件类型,支持PDF和Word
|
||||||
const validFiles: File[] = [];
|
const validFiles: File[] = [];
|
||||||
let hasInvalidFiles = false;
|
let hasInvalidFiles = false;
|
||||||
|
|
||||||
Array.from(files).forEach(file => {
|
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);
|
validFiles.push(file);
|
||||||
} else {
|
} else {
|
||||||
hasInvalidFiles = true;
|
hasInvalidFiles = true;
|
||||||
@@ -711,7 +717,7 @@ export default function FilesUpload() {
|
|||||||
if (hasInvalidFiles) {
|
if (hasInvalidFiles) {
|
||||||
// 显示错误提示
|
// 显示错误提示
|
||||||
console.error('【调试-handleContractMainFilesSelected】存在无效的文件类型');
|
console.error('【调试-handleContractMainFilesSelected】存在无效的文件类型');
|
||||||
messageService.error('只能上传PDF格式的文件', {
|
messageService.error('只支持PDF、Word格式的文件', {
|
||||||
title: '文件类型错误',
|
title: '文件类型错误',
|
||||||
confirmText: '确定',
|
confirmText: '确定',
|
||||||
cancelText: '',
|
cancelText: '',
|
||||||
@@ -746,12 +752,18 @@ export default function FilesUpload() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (files.length > 0) {
|
if (files.length > 0) {
|
||||||
// 验证文件类型,只允许PDF文件
|
// 验证文件类型,支持PDF和Word
|
||||||
const validFiles: File[] = [];
|
const validFiles: File[] = [];
|
||||||
let hasInvalidFiles = false;
|
let hasInvalidFiles = false;
|
||||||
|
|
||||||
Array.from(files).forEach(file => {
|
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);
|
validFiles.push(file);
|
||||||
} else {
|
} else {
|
||||||
hasInvalidFiles = true;
|
hasInvalidFiles = true;
|
||||||
@@ -762,7 +774,7 @@ export default function FilesUpload() {
|
|||||||
if (hasInvalidFiles) {
|
if (hasInvalidFiles) {
|
||||||
// 显示错误提示
|
// 显示错误提示
|
||||||
console.error('【调试-handleContractAttachmentFilesSelected】存在无效的文件类型');
|
console.error('【调试-handleContractAttachmentFilesSelected】存在无效的文件类型');
|
||||||
messageService.error('只能上传PDF格式的文件', {
|
messageService.error('只支持PDF、Word格式的文件', {
|
||||||
title: '文件类型错误',
|
title: '文件类型错误',
|
||||||
confirmText: '确定',
|
confirmText: '确定',
|
||||||
cancelText: '',
|
cancelText: '',
|
||||||
@@ -903,7 +915,7 @@ export default function FilesUpload() {
|
|||||||
attachmentMergeMode,
|
attachmentMergeMode,
|
||||||
true, // isReprocess
|
true, // isReprocess
|
||||||
attachmentRemark || undefined,
|
attachmentRemark || undefined,
|
||||||
loaderData.userInfo?.token
|
loaderData.userInfo?.token as string | undefined
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
@@ -973,7 +985,7 @@ export default function FilesUpload() {
|
|||||||
templateFile,
|
templateFile,
|
||||||
selectedDocumentId,
|
selectedDocumentId,
|
||||||
undefined, // comparisonId
|
undefined, // comparisonId
|
||||||
loaderData.userInfo?.token
|
loaderData.userInfo?.token as string | undefined
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
@@ -2082,8 +2094,8 @@ export default function FilesUpload() {
|
|||||||
onFilesSelected={handleContractMainFilesSelected}
|
onFilesSelected={handleContractMainFilesSelected}
|
||||||
ref={contractMainFileRef}
|
ref={contractMainFileRef}
|
||||||
multiple={false}
|
multiple={false}
|
||||||
accept=".pdf"
|
accept=".pdf,.doc,.docx"
|
||||||
tipText="请上传合同主文件,格式:PDF"
|
tipText="请上传合同主文件,格式:PDF/Word"
|
||||||
mainText="上传合同主文件"
|
mainText="上传合同主文件"
|
||||||
buttonText="选择主文件"
|
buttonText="选择主文件"
|
||||||
icon="ri-file-text-line"
|
icon="ri-file-text-line"
|
||||||
@@ -2102,8 +2114,8 @@ export default function FilesUpload() {
|
|||||||
onFilesSelected={handleContractAttachmentFilesSelected}
|
onFilesSelected={handleContractAttachmentFilesSelected}
|
||||||
ref={contractAttachmentFileRef}
|
ref={contractAttachmentFileRef}
|
||||||
multiple={false}
|
multiple={false}
|
||||||
accept=".pdf"
|
accept=".pdf,.doc,.docx"
|
||||||
tipText="请上传合同附件,格式:PDF"
|
tipText="请上传合同附件,格式:PDF/Word"
|
||||||
mainText="上传合同附件"
|
mainText="上传合同附件"
|
||||||
buttonText="选择附件"
|
buttonText="选择附件"
|
||||||
icon="ri-file-copy-line"
|
icon="ri-file-copy-line"
|
||||||
|
|||||||
Reference in New Issue
Block a user