42 lines
898 B
TypeScript
42 lines
898 B
TypeScript
import type { AxiosRequestConfig } from '@vben/request';
|
|
|
|
import { requestClient } from '#/api/request';
|
|
|
|
/**
|
|
* Axios上传进度事件
|
|
*/
|
|
export type AxiosProgressEvent = AxiosRequestConfig['onUploadProgress'];
|
|
|
|
/**
|
|
* 默认上传结果
|
|
*/
|
|
export interface UploadResult {
|
|
url: string;
|
|
fileName: string;
|
|
ossId: string;
|
|
}
|
|
|
|
/**
|
|
* 通过单文件上传接口
|
|
* @param file 上传的文件
|
|
* @param otherData 其他请求参数 后端拓展可能会用到
|
|
* @param onUploadProgress 上传进度事件 非必传
|
|
* @returns 上传结果
|
|
*/
|
|
export function uploadApi(
|
|
file: Blob | File,
|
|
otherData?: Record<string, any>,
|
|
onUploadProgress?: AxiosProgressEvent,
|
|
) {
|
|
return requestClient.upload<UploadResult>(
|
|
'/resource/oss/upload',
|
|
{ file, ...otherData },
|
|
{ onUploadProgress, timeout: 60_000 },
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 上传api type
|
|
*/
|
|
export type UploadApi = typeof uploadApi;
|