refactor: 重命名 API 文件并更新引用路径

- 重命名 13 个 API 文件,去掉 -api 后缀
  * src/api/auth-api.ts  auth.ts
  * src/api/codegen-api.ts  codegen.ts
  * src/api/file-api.ts  file.ts
  * src/api/system/*.ts (9个文件)

- 批量更新 50+ 处 API 引用路径
- 修复 websocket 和枚举导入路径
- 确保零编码问题(使用 UTF-8 编码)
This commit is contained in:
Ray.Hao
2025-12-12 14:02:07 +08:00
parent 9fb1942619
commit 23b52872c5
48 changed files with 56 additions and 53 deletions

64
src/api/file.ts Normal file
View File

@@ -0,0 +1,64 @@
import request from "@/utils/request";
const FileAPI = {
/** 上传文件 (传入 FormData上传进度回调 */
upload(formData: FormData, onProgress?: (percent: number) => void) {
return request<any, FileInfo>({
url: "/api/v1/files",
method: "post",
data: formData,
headers: { "Content-Type": "multipart/form-data" },
onUploadProgress: (progressEvent) => {
if (progressEvent.total) {
const percent = Math.round((progressEvent.loaded * 100) / progressEvent.total);
onProgress?.(percent);
}
},
});
},
/** 上传文件(传入 File */
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" },
});
},
/** 删除文件 */
delete(filePath?: string) {
return request({
url: "/api/v1/files",
method: "delete",
params: { filePath },
});
},
/** 下载文件 */
download(url: string, fileName?: string) {
return request({
url,
method: "get",
responseType: "blob",
}).then((res) => {
const blob = new Blob([res.data]);
const a = document.createElement("a");
const urlObject = window.URL.createObjectURL(blob);
a.href = urlObject;
a.download = fileName || "下载文件";
a.click();
window.URL.revokeObjectURL(urlObject);
});
},
};
export default FileAPI;
export interface FileInfo {
name: string;
url: string;
}