<n-upload action="#" :custom-request="customRequest" :multiple="true" accept=".xls,.xlsx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document">
<n-button>批量导入</n-button>
</n-upload>
interface FileInfo {
id: string;
name: string;
batchId?: string | null;
percentage?: number | null;
status: 'pending' | 'uploading' | 'finished' | 'removed' | 'error';
url?: string | null;
file?: File | null;
thumbnailUrl?: string | null;
type?: string | null;
fullPath?: string | null;
}
interface UploadCustomRequestOptions {
file: FileInfo;
action?: string;
data?: Record<string, string> | (({ file }: { file: FileInfo }) => Record<string, string>);
withCredentials?: boolean;
headers?: Record<string, string> | (({ file }: { file: FileInfo }) => Record<string, string>);
onProgress: (e: { percent: number }) => void;
onFinish: () => void;
onError: () => void;
}
//上传
const customRequest = ({ file }: UploadCustomRequestOptions) => {
const formData = new FormData();
formData.append('file', file.file as File);
//上传接口
getFileUpload(formData).then((res) => {
reloadTable();//重新加载表格
});
};