2025-07-05 00:55:24 +08:00
|
|
|
|
import type { AxiosResponse } from '@vben/request';
|
|
|
|
|
|
|
|
|
|
|
|
import type { AxiosProgressEvent } from '#/api/infra/file';
|
2025-05-11 22:33:15 +08:00
|
|
|
|
|
|
|
|
|
|
export type UploadListType = 'picture' | 'picture-card' | 'text';
|
|
|
|
|
|
|
2025-07-05 00:55:24 +08:00
|
|
|
|
export type UploadStatus =
|
|
|
|
|
|
| 'error'
|
|
|
|
|
|
| 'fail'
|
|
|
|
|
|
| 'removed'
|
|
|
|
|
|
| 'success'
|
|
|
|
|
|
| 'uploading';
|
2025-05-11 22:33:15 +08:00
|
|
|
|
|
|
|
|
|
|
export enum UploadResultStatus {
|
|
|
|
|
|
ERROR = 'error',
|
|
|
|
|
|
REMOVED = 'removed',
|
|
|
|
|
|
SUCCESS = 'success',
|
|
|
|
|
|
UPLOADING = 'uploading',
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface CustomUploadFile {
|
|
|
|
|
|
uid: number;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
status: UploadStatus;
|
|
|
|
|
|
url?: string;
|
|
|
|
|
|
response?: any;
|
|
|
|
|
|
percentage?: number;
|
|
|
|
|
|
size?: number;
|
|
|
|
|
|
raw?: File;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function convertToUploadStatus(
|
|
|
|
|
|
status: UploadResultStatus,
|
|
|
|
|
|
): UploadStatus {
|
|
|
|
|
|
switch (status) {
|
|
|
|
|
|
case UploadResultStatus.ERROR: {
|
2025-07-05 00:55:24 +08:00
|
|
|
|
return 'fail';
|
2025-05-11 22:33:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
case UploadResultStatus.REMOVED: {
|
|
|
|
|
|
return 'removed';
|
|
|
|
|
|
}
|
2025-08-31 21:17:11 +08:00
|
|
|
|
case UploadResultStatus.SUCCESS: {
|
|
|
|
|
|
return 'success';
|
|
|
|
|
|
}
|
2025-05-11 22:33:15 +08:00
|
|
|
|
case UploadResultStatus.UPLOADING: {
|
|
|
|
|
|
return 'uploading';
|
|
|
|
|
|
}
|
|
|
|
|
|
default: {
|
|
|
|
|
|
return 'success';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-07-05 00:55:24 +08:00
|
|
|
|
|
|
|
|
|
|
export interface FileUploadProps {
|
|
|
|
|
|
// 根据后缀,或者其他
|
|
|
|
|
|
accept?: string[];
|
|
|
|
|
|
api?: (
|
|
|
|
|
|
file: File,
|
|
|
|
|
|
onUploadProgress?: AxiosProgressEvent,
|
|
|
|
|
|
) => Promise<AxiosResponse<any>>;
|
|
|
|
|
|
// 上传的目录
|
|
|
|
|
|
directory?: string;
|
|
|
|
|
|
disabled?: boolean;
|
|
|
|
|
|
helpText?: string;
|
|
|
|
|
|
listType?: UploadListType;
|
|
|
|
|
|
// 最大数量的文件,Infinity不限制
|
|
|
|
|
|
maxNumber?: number;
|
|
|
|
|
|
// 文件最大多少MB
|
|
|
|
|
|
maxSize?: number;
|
|
|
|
|
|
// 是否支持多选
|
|
|
|
|
|
multiple?: boolean;
|
|
|
|
|
|
// support xxx.xxx.xx
|
|
|
|
|
|
resultField?: string;
|
|
|
|
|
|
// 是否显示下面的描述
|
|
|
|
|
|
showDescription?: boolean;
|
|
|
|
|
|
value?: string | string[];
|
|
|
|
|
|
}
|