This commit is contained in:
fuenmao
2026-08-28 11:09:20 +08:00
parent d0d7ca8e69
commit 14515ccdd6
8 changed files with 1073 additions and 254 deletions
+18 -2
View File
@@ -228,12 +228,28 @@ export const onboardingTaskApi = {
},
/** 使用后台登录令牌读取文件流,供入职材料下载和图片预览使用。 */
downloadFile(fileId: number) {
return fileHttp.get<any>(
async downloadFile(fileId: number) {
const response: any = await fileHttp.get<any>(
"download",
{ id: fileId },
{ responseType: "blob", loading: false, cancel: false }
);
const blob = response?.data;
const contentType = String(response?.headers?.["content-type"] || blob?.type || "");
if (blob instanceof Blob && contentType.toLowerCase().includes("application/json")) {
try {
const result = JSON.parse(await blob.text());
throw new Error(result?.msg || "文件下载失败");
} catch (error) {
if (error instanceof SyntaxError) {
throw new Error("文件下载失败");
}
throw error;
}
}
return response;
},
create(params: Record<string, unknown>) {