修改文档列表
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@ export type QueryParams = Record<string, string | number | boolean | undefined>;
|
||||
// 获取 API 基础 URL
|
||||
// const API_BASE_URL = '172.18.0.100:3000';
|
||||
// const API_BASE_URL = '172.16.0.119:9000/admin';
|
||||
const API_BASE_URL = 'http://nas.7bm.co:3000';
|
||||
export const API_BASE_URL = 'http://nas.7bm.co:3000';
|
||||
|
||||
// 是否使用模拟数据(开发环境使用)
|
||||
const USE_MOCK_DATA = false; // 设置为true使用模拟数据,避免API连接问题
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
import { apiRequest } from './client';
|
||||
import { FileType, Priority } from '~/types/enums';
|
||||
|
||||
/**
|
||||
* 将文件转换为二进制数据
|
||||
*/
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件到服务器
|
||||
*/
|
||||
export async function uploadFileToServer(
|
||||
binaryData: ArrayBuffer,
|
||||
fileName: string,
|
||||
fileType: string,
|
||||
documentType: FileType,
|
||||
priority: Priority
|
||||
): Promise<{ success: boolean; fileId?: string; message?: string; error?: string }> {
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', new Blob([binaryData], { type: fileType }), fileName);
|
||||
formData.append('documentType', documentType);
|
||||
formData.append('priority', priority);
|
||||
|
||||
const response = await apiRequest<{ success: boolean; fileId?: string; message?: string }>(
|
||||
'/api/files/upload',
|
||||
{
|
||||
method: 'POST',
|
||||
body: formData
|
||||
}
|
||||
);
|
||||
|
||||
if (response.error) {
|
||||
return { success: false, error: response.error };
|
||||
}
|
||||
|
||||
return { success: true, fileId: response.data?.fileId, message: response.data?.message };
|
||||
} 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 : '上传失败'
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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 文档列表
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
import { apiRequest, buildUrl, type PaginatedResponse } from './base';
|
||||
import type { File, DocumentType } from '~/models/file';
|
||||
|
||||
/**
|
||||
* 文件API服务
|
||||
*/
|
||||
|
||||
interface FileFilterParams {
|
||||
documentTypeId?: string;
|
||||
status?: string;
|
||||
reviewStatus?: string;
|
||||
keyword?: string;
|
||||
startDate?: string;
|
||||
endDate?: string;
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
}
|
||||
|
||||
// 获取文件列表
|
||||
export async function getFiles(params?: FileFilterParams): Promise<PaginatedResponse<File>> {
|
||||
const url = buildUrl('/api/files', params);
|
||||
return apiRequest<PaginatedResponse<File>>(url);
|
||||
}
|
||||
|
||||
// 获取单个文件
|
||||
export async function getFile(id: string): Promise<File> {
|
||||
const url = buildUrl(`/api/files/${id}`);
|
||||
return apiRequest<File>(url);
|
||||
}
|
||||
|
||||
// 上传文件
|
||||
export async function uploadFile(formData: FormData): Promise<File> {
|
||||
const url = buildUrl('/api/files/upload');
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json();
|
||||
throw new Error(error.message || '文件上传失败');
|
||||
}
|
||||
|
||||
return response.json().then(data => data.data);
|
||||
}
|
||||
|
||||
// 删除文件
|
||||
export async function deleteFile(id: string): Promise<void> {
|
||||
const url = buildUrl(`/api/files/${id}`);
|
||||
return apiRequest<void>(url, 'DELETE');
|
||||
}
|
||||
|
||||
// 获取文档类型列表
|
||||
export async function getDocumentTypes(): Promise<DocumentType[]> {
|
||||
const url = buildUrl('/api/document-types');
|
||||
return apiRequest<DocumentType[]>(url);
|
||||
}
|
||||
|
||||
// 获取单个文档类型
|
||||
export async function getDocumentType(id: string): Promise<DocumentType> {
|
||||
const url = buildUrl(`/api/document-types/${id}`);
|
||||
return apiRequest<DocumentType>(url);
|
||||
}
|
||||
|
||||
// 创建文档类型
|
||||
// 请使用 ~/api/document-types/document-types.ts 中的实现
|
||||
/*
|
||||
export async function createDocumentType(documentType: Omit<DocumentType, 'id' | 'createdAt' | 'updatedAt'>): Promise<DocumentType> {
|
||||
const url = buildUrl('/api/document-types');
|
||||
return apiRequest<DocumentType>(url, 'POST', documentType);
|
||||
}
|
||||
*/
|
||||
|
||||
// 更新文档类型
|
||||
// 请使用 ~/api/document-types/document-types.ts 中的实现
|
||||
/*
|
||||
export async function updateDocumentType(id: string, documentType: Partial<Omit<DocumentType, 'id' | 'createdAt' | 'updatedAt'>>): Promise<DocumentType> {
|
||||
const url = buildUrl(`/api/document-types/${id}`);
|
||||
return apiRequest<DocumentType>(url, 'PUT', documentType);
|
||||
}
|
||||
*/
|
||||
|
||||
// 删除文档类型
|
||||
export async function deleteDocumentType(id: string): Promise<void> {
|
||||
const url = buildUrl(`/api/document-types/${id}`);
|
||||
return apiRequest<void>(url, 'DELETE');
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
import { apiRequest, buildUrl, type PaginatedResponse } from './base';
|
||||
import type { Rule, RuleGroup } from '~/models/rule';
|
||||
|
||||
/**
|
||||
* 评查规则API服务
|
||||
*/
|
||||
|
||||
interface RuleFilterParams {
|
||||
ruleType?: string;
|
||||
groupId?: string;
|
||||
isActive?: boolean;
|
||||
keyword?: string;
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
}
|
||||
|
||||
// 获取评查点列表
|
||||
export async function getRules(params?: RuleFilterParams): Promise<PaginatedResponse<Rule>> {
|
||||
const url = buildUrl('/api/rules', params);
|
||||
return apiRequest<PaginatedResponse<Rule>>(url);
|
||||
}
|
||||
|
||||
// 获取单个评查点
|
||||
export async function getRule(id: string): Promise<Rule> {
|
||||
const url = buildUrl(`/api/rules/${id}`);
|
||||
return apiRequest<Rule>(url);
|
||||
}
|
||||
|
||||
// 创建评查点
|
||||
export async function createRule(rule: Omit<Rule, 'id' | 'createdAt' | 'updatedAt'>): Promise<Rule> {
|
||||
const url = buildUrl('/api/rules');
|
||||
return apiRequest<Rule>(url, 'POST', rule);
|
||||
}
|
||||
|
||||
// 更新评查点
|
||||
export async function updateRule(id: string, rule: Partial<Omit<Rule, 'id' | 'createdAt' | 'updatedAt'>>): Promise<Rule> {
|
||||
const url = buildUrl(`/api/rules/${id}`);
|
||||
return apiRequest<Rule>(url, 'PUT', rule);
|
||||
}
|
||||
|
||||
// 删除评查点
|
||||
export async function deleteRule(id: string): Promise<void> {
|
||||
const url = buildUrl(`/api/rules/${id}`);
|
||||
return apiRequest<void>(url, 'DELETE');
|
||||
}
|
||||
|
||||
// 获取评查点分组列表
|
||||
export async function getRuleGroups(): Promise<RuleGroup[]> {
|
||||
const url = buildUrl('/api/rule-groups');
|
||||
return apiRequest<RuleGroup[]>(url);
|
||||
}
|
||||
|
||||
// 获取单个评查点分组
|
||||
export async function getRuleGroup(id: string): Promise<RuleGroup> {
|
||||
const url = buildUrl(`/api/rule-groups/${id}`);
|
||||
return apiRequest<RuleGroup>(url);
|
||||
}
|
||||
|
||||
// 创建评查点分组
|
||||
export async function createRuleGroup(group: Omit<RuleGroup, 'id' | 'createdAt' | 'updatedAt'>): Promise<RuleGroup> {
|
||||
const url = buildUrl('/api/rule-groups');
|
||||
return apiRequest<RuleGroup>(url, 'POST', group);
|
||||
}
|
||||
|
||||
// 更新评查点分组
|
||||
export async function updateRuleGroup(id: string, group: Partial<Omit<RuleGroup, 'id' | 'createdAt' | 'updatedAt'>>): Promise<RuleGroup> {
|
||||
const url = buildUrl(`/api/rule-groups/${id}`);
|
||||
return apiRequest<RuleGroup>(url, 'PUT', group);
|
||||
}
|
||||
|
||||
// 删除评查点分组
|
||||
export async function deleteRuleGroup(id: string): Promise<void> {
|
||||
const url = buildUrl(`/api/rule-groups/${id}`);
|
||||
return apiRequest<void>(url, 'DELETE');
|
||||
}
|
||||
Reference in New Issue
Block a user