修改文档列表
This commit is contained in:
@@ -67,6 +67,8 @@ export interface Document {
|
||||
is_test_document: boolean;
|
||||
evaluation_level: string;
|
||||
status: 'pass' | 'warning' | 'waiting' | 'processing' | 'fail';
|
||||
file_status: 'Waiting' | 'Cutting' | 'Extractioning' | 'Evaluationing' | 'Processed';
|
||||
audit_status: number; // -1: 不通过, 0: 待审核, 1: 通过, 2: 警告, 3: 审核中
|
||||
ocr_result: unknown;
|
||||
extracted_results: unknown;
|
||||
summary: unknown;
|
||||
@@ -85,7 +87,8 @@ export interface DocumentUI {
|
||||
type: string;
|
||||
typeName: string;
|
||||
size: number;
|
||||
status: string;
|
||||
auditStatus: number; // -1: 不通过, 0: 待审核, 1: 通过, 2: 警告, 3: 审核中
|
||||
fileStatus: string; // Waiting, Cutting, Extractioning, Evaluationing, Processed
|
||||
issues: number | null;
|
||||
uploadTime: string;
|
||||
fileType: string;
|
||||
@@ -119,7 +122,8 @@ async function convertToUIDocument(doc: Document): Promise<DocumentUI> {
|
||||
type: doc.type_id.toString(),
|
||||
typeName: docType?.name || '未知类型',
|
||||
size: doc.file_size,
|
||||
status: doc.status,
|
||||
auditStatus: doc.audit_status,
|
||||
fileStatus: doc.file_status || 'Processed', // 默认为已处理
|
||||
issues: 0, // 固定为0
|
||||
uploadTime: formatDate(doc.updated_at),
|
||||
fileType: getFileExtension(doc.name),
|
||||
@@ -332,13 +336,6 @@ export async function getFileDownloadUrl(filePath: string): Promise<{
|
||||
return { error: '文件路径不能为空', status: 400 };
|
||||
}
|
||||
|
||||
// 构建API请求参数
|
||||
const params: PostgrestParams = {
|
||||
filter: {
|
||||
'path': `eq.${filePath}`
|
||||
}
|
||||
};
|
||||
|
||||
// 这里应该调用获取文件下载链接的API
|
||||
// 假设后端有这样的端点:/api/files/generate-download-url?path=xxx
|
||||
// 实际项目中需要根据你的后端API调整
|
||||
@@ -387,8 +384,8 @@ export async function updateDocument(id: string, document: Partial<DocumentUI> &
|
||||
apiDocument.type_id = parseInt(document.type);
|
||||
}
|
||||
|
||||
if (document.status !== undefined) {
|
||||
apiDocument.status = document.status as 'pass' | 'warning' | 'waiting' | 'processing' | 'fail';
|
||||
if (document.auditStatus !== undefined) {
|
||||
apiDocument.audit_status = document.auditStatus;
|
||||
}
|
||||
|
||||
if (document.isTest !== undefined) {
|
||||
|
||||
@@ -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