first commiit

This commit is contained in:
2025-02-08 10:15:06 +08:00
parent 6815bd083b
commit 262bf41379
242 changed files with 19959 additions and 1 deletions

81
src/api/file/index.ts Normal file
View File

@@ -0,0 +1,81 @@
import request from "@/utils/request";
const FileAPI = {
/**
* 上传文件
*
* @param formData
*/
upload(formData: FormData) {
return request<any, FileInfo>({
url: "/api/v1/files",
method: "post",
data: formData,
headers: {
"Content-Type": "multipart/form-data",
},
});
},
/**
* 上传文件
*/
uploadFile(file: File) {
const formData = new FormData();
formData.append("file", file);
return request<any, FileInfo>({
url: "/api/v1/files",
method: "post",
data: formData,
headers: {
"Content-Type": "multipart/form-data",
},
});
},
/**
* 删除文件
*
* @param filePath 文件完整路径
*/
delete(filePath?: string) {
return request({
url: "/api/v1/files",
method: "delete",
params: { filePath: filePath },
});
},
/**
* 下载文件
* @param url
* @param fileName
*/
download(url: string, fileName?: string) {
return request({
url: url,
method: "get",
responseType: "blob",
}).then((res) => {
const blob = new Blob([res.data]);
const a = document.createElement("a");
const url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName || "下载文件";
a.click();
window.URL.revokeObjectURL(url);
});
},
};
export default FileAPI;
/**
* 文件API类型声明
*/
export interface FileInfo {
/** 文件名 */
name: string;
/** 文件路径 */
url: string;
}