1111
This commit is contained in:
@@ -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>) {
|
||||
|
||||
Reference in New Issue
Block a user