封装的功能包括:
- 文件类型检查
- 文件大小检查
- 文件数量检查
- 文件预览
供参考
import React, {
ReactNode, useState } from 'react';
import {
Upload, Button, Modal, message } from 'antd';
import {
UploadProps } from 'antd/lib/upload/Upload';
import {
UploadChangeParam } from 'antd/lib/upload';
import {
UploadFile } from 'antd/es/upload/interface';
import CenterImage from '@/components/CenterImage/CenterImage';
const accetpMap = {
zip: 'application/zip,application/x-zip,application/x-zip-compressed',
pdf: 'application/pdf',
excel:
'application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
image: 'image/jpeg,image/bmp,image/png,image/gif,image/svg',
word:
'.doc,.docx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document',
csv: '.csv',
normal: 'image/jpeg,image/png',
normalAndSvg: 'image/jpeg,image/png,image/svg+xml'
};
interface FileProps {
onChange?: (file: any) => void;
value?: any[];
children?: ReactNode;
extra?: string | ReactNode;
amount?: number;
size?: number;
accept?:
| 'zip'
| 'excel'
| 'pdf'
| 'image'
| 'word'
| 'csv'
| 'normal'
| 'normalAndSvg'
| Partial<'zip' | 'excel' | 'pdf' | 'image' | 'word' | 'csv'>[];
otherProps?: UploadProps;
}
export default function Index(