This commit is contained in:
oneao committed 2026-03-30 17:27:19 +08:00
1 parent f9eaacf02a
commit 69eda8b8ad
27 files changed
+2797 -616

No files matched your search

+22 -4
View File
@@ -1,7 +1,5 @@
import { httpPost, httpUpload } from ".";
// 登录
export function loginApi(orgid, userid, password) {
return httpPost(`/auth/login`, {
@@ -190,11 +188,31 @@ export function insertFileApi(params) {
return httpPost("/file/insert", params);
}
// export function deleteFileApi(subid) {
// return httpPost("/file/delete", {
// subid,
// tableName: "bf_file",
// bucketName: import.meta.env.PUBLIC_ALIYUN_BUCKET,
// });
// }
export function deleteFileApi(subid) {
return httpPost("/file/delete", {
subid,
tableName: "bf_file",
bucketName: import.meta.env.PUBLIC_ALIYUN_BUCKET,
});
}
export function uploadContainerFileApi(filePath, { jobId, containerNo, fileName }) {
return httpUpload("/file/uploadContainer", filePath, {
jobId,
containerNo,
fileName,
});
}
export function uploadCommonFileApi(filePath, { fileName }) {
return httpUpload("/file/uploadCommon", filePath, {
fileName,
});
}
// ============================= file =============================
@@ -120,19 +120,17 @@ export function httpPost(url, data, config) {
* @param {Object} config - axios 配置(可选)
* @returns {Promise<any>}
*/
export function httpUpload(url, file, extraData = {}, config = {}) {
export async function httpUpload(url, file, extraData = {}, config = {}) {
const formData = new FormData();
// 兼容单文件 & 多文件
if (Array.isArray(file)) {
file.forEach((f) => {
formData.append("file", f);
});
for (const f of file) {
await appendFile(formData, f);
}
} else {
formData.append("file", file);
await appendFile(formData, file);
}
// 追加额外参数
Object.keys(extraData).forEach((key) => {
formData.append(key, extraData[key]);
});
@@ -147,6 +145,24 @@ export function httpUpload(url, file, extraData = {}, config = {}) {
.then((res) => res.data);
}
async function appendFile(formData, file) {
// ✅ 已经是 File / Blob
if (file instanceof File || file instanceof Blob) {
formData.append("file", file);
return;
}
// ✅ 处理 blob:http://xxx
if (typeof file === "string" && file.startsWith("blob:")) {
const blob = await fetch(file).then((res) => res.blob());
formData.append("file", blob);
return;
}
throw new Error("不支持的文件类型:" + typeof file);
}
export function reset401Flag() {
hasShown401 = false;
}