修改文档列表
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { postgrestGet, postgrestPut, postgrestPost, type PostgrestParams } from '../postgrest-client';
|
||||
import dayjs from 'dayjs';
|
||||
// import { API_BASE_URL } from '../client';
|
||||
|
||||
/**
|
||||
* 格式化日期
|
||||
@@ -39,6 +40,7 @@ function extractApiData<T>(responseData: unknown): T | null {
|
||||
|
||||
// 文档状态枚举
|
||||
export enum DocumentStatus {
|
||||
WAITING = "waiting",
|
||||
CUTTING = "Cutting",
|
||||
EXTRACTIONING = "extractioning",
|
||||
REVIEWING = "reviewing",
|
||||
@@ -80,6 +82,132 @@ export interface Document {
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
// 文件上传响应接口
|
||||
export interface FileUploadResponse {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将文件转换为二进制数据
|
||||
*/
|
||||
export async function uploadFileToBinary(file: File): Promise<ArrayBuffer> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
if (reader.result instanceof ArrayBuffer) {
|
||||
resolve(reader.result);
|
||||
} else {
|
||||
reject(new Error('文件读取失败'));
|
||||
}
|
||||
};
|
||||
reader.onerror = () => reject(new Error('文件读取失败'));
|
||||
reader.readAsArrayBuffer(file);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件到文档审核系统
|
||||
* @param binaryData 文件的二进制数据
|
||||
* @param fileName 文件名
|
||||
* @param fileType 文件类型
|
||||
* @param typeId 文档类型ID
|
||||
* @param priority 优先级
|
||||
* @param documentNumber 文档编号(可选)
|
||||
* @param remark 备注信息(可选)
|
||||
* @param isTestDocument 是否为测试文档
|
||||
* @returns 上传结果
|
||||
*/
|
||||
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<{data: FileUploadResponse; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
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));
|
||||
|
||||
console.log('上传信息:', {
|
||||
fileName,
|
||||
fileType,
|
||||
typeId: Number(typeId),
|
||||
priority,
|
||||
documentNumber: documentNumber || null,
|
||||
remark: remark || null,
|
||||
isTestDocument
|
||||
});
|
||||
|
||||
// 发送请求
|
||||
// const response = await fetch(`${API_BASE_URL}/admin/documents/upload`, {
|
||||
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 {
|
||||
error: `上传失败: ${response.status} ${response.statusText}`,
|
||||
status: response.status
|
||||
};
|
||||
}
|
||||
|
||||
const responseData = await response.json();
|
||||
const extractedData = extractApiData<FileUploadResponse>(responseData);
|
||||
|
||||
if (!extractedData) {
|
||||
return { error: '处理上传响应失败', status: 500 };
|
||||
}
|
||||
|
||||
return { data: extractedData };
|
||||
} catch (error) {
|
||||
console.error('上传错误:', error);
|
||||
return {
|
||||
error: error instanceof Error ? error.message : '上传失败',
|
||||
status: 500
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当天的文档列表
|
||||
* @returns 文档列表
|
||||
|
||||
Reference in New Issue
Block a user