import type { UploadFile, UploadProps as AntdUploadProps } from 'antd/es/upload'; /** 上传阶段 */ export type UploadPhase = 'idle' | 'hashing' | 'preparing' | 'uploading' | 'paused' | 'merging' | 'done' | 'error'; /** 分片信息 */ export interface ChunkInfo { chunk: Blob; index: number; start: number; end: number; } /** 上传文件对象 */ export interface SliceUploadFile extends Omit { response?: { fileId?: string; fileUrl: string; [key: string]: any; }; } /** 通用响应结构 */ export interface ApiResponse { success: boolean; data?: T; message?: string; } /** 获取上传ID的参数 */ export interface GetUploadIdParams { fileName: string; fileSize: number; fileMd5: string; } /** 获取上传ID的返回 */ export interface GetUploadIdResult { uploadId: string; key?: string; /** 已上传的分片索引(用于断点续传) */ uploaded?: number[]; } /** 上传分片的参数 */ export interface UploadChunkParams { uploadId: string; key?: string; chunk: Blob; chunkIndex: number; totalChunks: number; fileName: string; } /** 合并分片的参数 */ export interface MergeChunksParams { uploadId: string; key?: string; fileName: string; fileSize: number; totalChunks: number; fileMd5: string; } /** 合并分片的返回 */ export interface MergeChunksResult { fileId?: string; fileUrl: string; fileName?: string; [key: string]: any; } /** 组件 Props */ export interface SliceUploadProps extends Omit { /** 受控值 */ value?: SliceUploadFile[] | string[]; /** 值变化回调 */ onChange?: (fileList: SliceUploadFile[]) => void; /** 分片大小,默认 20MB */ chunkSize?: number; /** 最大文件大小,默认 200MB */ maxFileSize?: number; /** 并发上传数,默认 3 */ concurrent?: number; /** * 获取上传ID * 用于初始化分片上传,返回 uploadId 和可选的 key */ getUploadId: (params: GetUploadIdParams) => Promise>; /** * 上传单个分片 */ uploadChunk: (params: UploadChunkParams) => Promise; /** * 合并分片 * 所有分片上传完成后调用,返回最终文件信息 */ mergeChunks: (params: MergeChunksParams) => Promise>; /** 是否显示进度弹窗,默认 true */ showProgress?: boolean; /** 上传成功回调 */ onSuccess?: (file: SliceUploadFile, fileList: SliceUploadFile[]) => void; /** 上传失败回调 */ onError?: (error: Error, file: File) => void; /** 进度回调 */ onProgress?: (percent: number, file: File) => void; /** * 解析文件URL * 用于将服务端返回的相对路径转换为可访问的完整URL */ parseFileUrl?: (url: string) => string; } /** 组件 Ref */ export interface SliceUploadRef { /** 中止上传 */ abort: () => void; /** 暂停上传 */ pause: () => void; /** 恢复上传 */ resume: () => void; /** 获取文件列表 */ getFileList: () => SliceUploadFile[]; /** 清空文件列表 */ clear: () => void; }