/** 上传进度 */ export type UploadProgress = { percent: number; } /** 上传报错信息 */ export type UploadError = { message: string; } export type UploadBaseData = { /** * 唯一标识符,没传时会自动生成 */ id: string /** * 文件状态 */ status: UploadStatus /** * 名称 */ name: string } /** 用于上传的文件 */ export type UploadFileData = UploadBaseData & { /** * 文件数据 */ file: File } /** 仅用于展示的文件 */ export type UploadDisplayData = UploadBaseData export type UploadData = UploadFileData | UploadDisplayData // 上传函数,必传,上传组件没有上传方法不合适 export type UploadFunction = (file: File, callbacks: UploadCallbacks) => StopUpload | void /** 文件上传的状态 */ export type UploadStatus = 'error' | 'success' | 'uploading' | 'stopped' | 'ready' export type UploadCallbacks = { onProgress: (progress: UploadProgress) => void onError: (error: UploadError) => void onComplete: () => void } /** 用于停止上传文件 */ export type StopUpload = () => void