Merge branch 'dev' of http://59.110.10.99:53000/liuc/fe_supplier_frontend into dev
This commit is contained in:
@ -50,7 +50,7 @@ const FileUpload: React.FC<FileUploadProps> = ({
|
|||||||
listType = 'text',
|
listType = 'text',
|
||||||
buttonText,
|
buttonText,
|
||||||
disabled = false,
|
disabled = false,
|
||||||
accept,
|
accept = allowedTypes.map(type => `.${type}`).join(','),
|
||||||
showUploadList = true,
|
showUploadList = true,
|
||||||
isDragger = false,
|
isDragger = false,
|
||||||
tip,
|
tip,
|
||||||
@ -163,7 +163,7 @@ const FileUpload: React.FC<FileUploadProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const beforeUpload = (file: File) => {
|
const beforeUpload = (file: File) => {
|
||||||
return validateFileSize(file, maxSize, allowedTypes);
|
return validateFileSize(file, maxSize);
|
||||||
};
|
};
|
||||||
|
|
||||||
const UploadComponent = isDragger ? Upload.Dragger : Upload;
|
const UploadComponent = isDragger ? Upload.Dragger : Upload;
|
||||||
|
@ -4,33 +4,14 @@ import { message,Upload } from 'antd';
|
|||||||
// 参数说明:
|
// 参数说明:
|
||||||
// file: 上传的文件
|
// file: 上传的文件
|
||||||
// maxSize: 最大文件大小
|
// maxSize: 最大文件大小
|
||||||
// type: 文件类型,支持*表示所有类型
|
export const validateFileSize = (file: File, maxSize: number) => {
|
||||||
const FileTypeMap = {
|
|
||||||
'application/pdf': 'pdf',
|
|
||||||
'image/jpeg': 'jpg',
|
|
||||||
'image/png': 'png',
|
|
||||||
'application/msword': 'doc',
|
|
||||||
'application/zip': 'zip',
|
|
||||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx',
|
|
||||||
'application/vnd.ms-excel': 'xls',
|
|
||||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'xlsx',
|
|
||||||
'application/vnd.ms-powerpoint': 'ppt',
|
|
||||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation': 'pptx',
|
|
||||||
|
|
||||||
}
|
|
||||||
export const validateFileSize = (file: File, maxSize: number,type: string[]) => {
|
|
||||||
const { LIST_IGNORE } = Upload;
|
const { LIST_IGNORE } = Upload;
|
||||||
const isLtMaxSize = file.size / 1024 / 1024 < maxSize;
|
const isLtMaxSize = file.size / 1024 / 1024 < maxSize;
|
||||||
if (!isLtMaxSize) {
|
if (!isLtMaxSize) {
|
||||||
message.error(`文件大小不能超过${maxSize}MB!`);
|
message.error(`文件大小不能超过${maxSize}MB!`);
|
||||||
return LIST_IGNORE;
|
return LIST_IGNORE;
|
||||||
}
|
}
|
||||||
const isValidFormat = type.includes('*') || type.includes(FileTypeMap[file.type as keyof typeof FileTypeMap]);
|
return isLtMaxSize;
|
||||||
if (!isValidFormat) {
|
|
||||||
message.error(`只能上传${type.join(',')}格式文件!`);
|
|
||||||
return LIST_IGNORE;
|
|
||||||
}
|
|
||||||
return isValidFormat && isLtMaxSize;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user