合并评查点新增代码

This commit is contained in:
2025-04-13 15:09:01 +08:00
parent 414fb8ebac
commit 60680cd4bf
11 changed files with 772 additions and 941 deletions
+79
View File
@@ -51,4 +51,83 @@ export async function uploadFileToServer(
} catch (error) {
return { success: false, error: error instanceof Error ? error.message : '上传失败' };
}
}
/**
* 上传文件到文档审核系统
*/
export async function uploadDocumentToServer(
binaryData: ArrayBuffer,
fileName: string,
fileType: string,
typeId: string | number,
priority: string,
documentNumber?: string | null,
remark?: string | null,
isTestDocument: boolean = false
): Promise<{
success: boolean;
result?: {
id: number;
file_name: string;
file_size: number;
file_url: string;
type_id: number;
type_description: string;
document_number: string | null;
storage_type: string;
is_test_document: boolean;
remark: string | null;
background_processing: boolean;
evaluation_level: string;
};
error: string | null;
}> {
try {
// 创建FormData对象
const formData = new FormData();
// 将二进制数据转换为Blob并添加到FormData
const blob = new Blob([binaryData], { type: fileType });
formData.append('file', blob, fileName);
// 将信息添加到一个JSON对象中
const uploadInfo = {
type_id: Number(typeId),
evaluation_level: priority,
document_number: documentNumber || null,
remark: remark || null,
is_test_document: isTestDocument
};
// 添加JSON字符串到FormData
formData.append('upload_info', JSON.stringify(uploadInfo));
// 发送请求
const response = await fetch('http://172.16.0.55:8000/admin/documents/upload', {
method: 'POST',
headers: {
'X-File-Name': encodeURIComponent(fileName)
},
body: formData
});
if (!response.ok) {
const errorText = await response.text();
console.error(`上传失败 (${response.status}): ${errorText}`);
return {
success: false,
error: `上传失败: ${response.status} ${response.statusText}`
};
}
const data = await response.json();
return data;
} catch (error) {
console.error('上传错误:', error);
return {
success: false,
error: error instanceof Error ? error.message : '上传失败'
};
}
}