diff --git a/app/api/files/documents.ts b/app/api/files/documents.ts index 05c6017..f2d9ea0 100644 --- a/app/api/files/documents.ts +++ b/app/api/files/documents.ts @@ -45,6 +45,8 @@ export interface DocumentSearchParams { documentNumber?: string; documentType?: string; status?: string; + auditStatus?: string; + fileStatus?: string; dateFrom?: string; dateTo?: string; page?: number; @@ -123,7 +125,7 @@ async function convertToUIDocument(doc: Document): Promise { typeName: docType?.name || '未知类型', size: doc.file_size, auditStatus: doc.audit_status, - fileStatus: doc.file_status || 'Processed', // 默认为已处理 + fileStatus: doc.status || '', // 默认为'' issues: 0, // 固定为0 uploadTime: formatDate(doc.updated_at), fileType: getFileExtension(doc.name), @@ -173,20 +175,35 @@ export async function getDocuments(searchParams: DocumentSearchParams = {}): Pro filter['type_id'] = `eq.${searchParams.documentType}`; } - if (searchParams.status) { - filter['status'] = `eq.${searchParams.status}`; + if (searchParams.auditStatus) { + filter['audit_status'] = `eq.${searchParams.auditStatus}`; + } + + if (searchParams.fileStatus) { + filter['status'] = `eq.${searchParams.fileStatus}`; } // 处理日期范围 if (searchParams.dateFrom) { - filter['updated_at'] = `gte.${searchParams.dateFrom}`; + // 添加当天开始时间 00:00:00 + filter['created_at'] = `gte.'${searchParams.dateFrom} 00:00:00'`; } if (searchParams.dateTo) { - const dateToKey = searchParams.dateFrom ? 'and.updated_at.lte' : 'updated_at'; - filter[dateToKey] = `lte.${searchParams.dateTo}`; + // 如果有开始日期,使用and条件;否则直接设置结束日期 + const dateToKey = searchParams.dateFrom ? 'and' : 'created_at'; + + // 添加当天结束时间 23:59:59 + if (dateToKey === 'and') { + delete filter['created_at']; + // 使用OR操作符连接两个条件 + filter[dateToKey] = `(created_at.gte.'${dayjs(searchParams.dateFrom).format()}',created_at.lte.'${dayjs(searchParams.dateTo).format()}')`; + } else { + filter['created_at'] = `lte.'${dayjs(searchParams.dateTo).format()}'`; + } } + console.log('filter-----', filter); params.filter = filter; // 发送请求 @@ -204,7 +221,7 @@ export async function getDocuments(searchParams: DocumentSearchParams = {}): Pro // 转换为UI格式 const documents = await Promise.all(extractedData.map(convertToUIDocument)); - + // console.log('documentsItem',documents) // 获取总数 let totalCount = 0; const responseWithHeaders = response as { diff --git a/app/api/files/files-upload.ts b/app/api/files/files-upload.ts index f6ebb8c..0f9e0d6 100644 --- a/app/api/files/files-upload.ts +++ b/app/api/files/files-upload.ts @@ -40,11 +40,12 @@ function extractApiData(responseData: unknown): T | null { // 文档状态枚举 export enum DocumentStatus { - WAITING = "waiting", + WAITING = "Waiting", CUTTING = "Cutting", - EXTRACTIONING = "extractioning", - REVIEWING = "reviewing", - COMPLETED = "completed" + EXTRACTIONING = "Extractioning", + EVALUATIONING = "Evaluationing", + FAILED = "Failed", + PROCESSED = "Processed" } // 文档类型接口 diff --git a/app/routes/documents._index.tsx b/app/routes/documents._index.tsx index 19ff77f..01ae7e8 100644 --- a/app/routes/documents._index.tsx +++ b/app/routes/documents._index.tsx @@ -33,8 +33,9 @@ export const loader = async ({ request }: LoaderFunctionArgs) => { const url = new URL(request.url); const search = url.searchParams.get("search") || ""; const documentType = url.searchParams.get("documentType") || ""; - const status = url.searchParams.get("status") || ""; + const auditStatus = url.searchParams.get("auditStatus") || ""; const documentNumber = url.searchParams.get("documentNumber") || ""; + const fileStatus = url.searchParams.get("fileStatus") || ""; const dateFrom = url.searchParams.get("dateFrom") || ""; const dateTo = url.searchParams.get("dateTo") || ""; const page = parseInt(url.searchParams.get("page") || "1", 10); @@ -45,7 +46,8 @@ export const loader = async ({ request }: LoaderFunctionArgs) => { name: search || undefined, documentNumber: documentNumber || undefined, documentType: documentType || undefined, - status: status || undefined, + auditStatus: auditStatus || undefined, + fileStatus: fileStatus || undefined, dateFrom: dateFrom || undefined, dateTo: dateTo || undefined, page, @@ -58,8 +60,8 @@ export const loader = async ({ request }: LoaderFunctionArgs) => { throw new Error(documentsResponse.error); } - // 获取文档类型列表,用于筛选条件 - const typesResponse = await getDocumentTypes(); + // 获取文档类型列表,用于筛选条件,设置较大的pageSize确保获取所有数据 + const typesResponse = await getDocumentTypes({ pageSize: 500 }); const documentTypes = typesResponse.data?.types || []; const documentTypeOptions = documentTypes.map(type => ({ value: type.id, @@ -112,22 +114,33 @@ export const action = async ({ request }: ActionFunctionArgs) => { return Response.json({ success: false, message: "未知操作" }, { status: 400 }); }; -// 文档状态选项 -const documentStatusOptions = [ - { value: "waiting", label: "待审核" }, - { value: "processing", label: "审核中" }, - { value: "pass", label: "通过" }, - { value: "warning", label: "警告" }, - { value: "fail", label: "不通过" }, +// 审核状态筛选选项 +const auditStatusOptions = [ + // { value: "", label: "全部" }, + { value: "-1", label: "不通过" }, + { value: "0", label: "待审核" }, + { value: "1", label: "通过" }, + { value: "2", label: "警告" }, + { value: "3", label: "审核中" }, ]; // 文件处理状态选项 const fileProcessingStatusOptions = [ - { value: "Waiting", label: "上传中", icon: "ri-loader-line" }, - { value: "Cutting", label: "切分中", icon: "ri-loader-line" }, - { value: "Extractioning", label: "抽取中", icon: "ri-loader-line" }, - { value: "Evaluationing", label: "评查中", icon: "ri-loader-line" }, - { value: "Processed", label: "已完成", icon: "ri-check-line" }, + { value: "Waiting", label: "上传中", icon: "ri-loader-line", color: "blue" }, + { value: "Cutting", label: "切分中", icon: "ri-loader-line", color: "purple" }, + { value: "Extractioning", label: "抽取中", icon: "ri-loader-line", color: "cyan" }, + { value: "Evaluationing", label: "评查中", icon: "ri-loader-line", color: "teal" }, + { value: "Processed", label: "已完成", icon: "ri-check-line", color: "green" }, +]; + +// 文件状态筛选选项 +const fileStatusOptions = [ + // { value: "", label: "全部" }, + { value: "Waiting", label: "上传中" }, + { value: "Cutting", label: "切分中" }, + { value: "Extractioning", label: "抽取中" }, + { value: "Evaluationing", label: "评查中" }, + { value: "Processed", label: "已完成" }, ]; // 审核状态选项及样式 @@ -171,8 +184,9 @@ export default function DocumentsIndex() { // 从URL获取当前筛选条件 const search = searchParams.get("search") || ""; const documentType = searchParams.get("documentType") || ""; - const status = searchParams.get("status") || ""; + const auditStatus = searchParams.get("auditStatus") || ""; const documentNumber = searchParams.get("documentNumber") || ""; + const fileStatus = searchParams.get("fileStatus") || ""; const dateFrom = searchParams.get("dateFrom") || ""; const dateTo = searchParams.get("dateTo") || ""; const currentPage = parseInt(searchParams.get("page") || "1", 10); @@ -234,9 +248,9 @@ export default function DocumentsIndex() { const handleStatusChange = (e: React.ChangeEvent) => { const params = new URLSearchParams(searchParams); if (e.target.value) { - params.set("status", e.target.value); + params.set("auditStatus", e.target.value); } else { - params.delete("status"); + params.delete("auditStatus"); } params.set("page", "1"); // 重置页码 setSearchParams(params); @@ -332,7 +346,11 @@ export default function DocumentsIndex() { }; // 删除文档 - const handleDelete = (id: string, name: string) => { + const handleDelete = (id: string, name: string, fileStatus: string) => { + if (fileStatus !== 'Processed') { + alert('文档正在处理中,不能删除'); + return; + } if (window.confirm(`确认删除文档 "${name}"?`)) { // 使用fetcher提交表单 const formData = new FormData(); @@ -353,6 +371,16 @@ export default function DocumentsIndex() { return; } + // 检查是否有正在处理中的文件 + const hasProcessingFiles = documents.some((doc: DocumentUI) => + selectedRowKeys.includes(doc.id.toString()) && doc.fileStatus !== 'Processed' + ); + + if (hasProcessingFiles) { + alert('存在服务器未处理完成的文件,请重新选择需要删除的文件'); + return; + } + if (window.confirm(`确认删除选中的 ${selectedRowKeys.length} 个文档?`)) { // 使用fetcher提交表单 const formData = new FormData(); @@ -370,6 +398,18 @@ export default function DocumentsIndex() { } }; + // 处理文件状态变更 + const handleFileStatusChange = (e: React.ChangeEvent) => { + const params = new URLSearchParams(searchParams); + if (e.target.value) { + params.set("fileStatus", e.target.value); + } else { + params.delete("fileStatus"); + } + params.set("page", "1"); // 重置页码 + setSearchParams(params); + }; + // 表格列定义 const columns = [ { @@ -393,6 +433,7 @@ export default function DocumentsIndex() { { title: "文档名称", key: "name", + width:'20%', render: (_: unknown, record: DocumentUI) => (
-
- {record.name} +
+ {record.name}
( {record.documentNumber} ) @@ -431,18 +473,22 @@ export default function DocumentsIndex() { { title: "文件大小", key: "size", - width: "100px", + width: "10%", render: (_: unknown, record: DocumentUI) => formatFileSize(record.size) }, { title: "文件状态", key: "fileStatus", + width:'10%', render: (_: unknown, record: DocumentUI) => { - const status = fileProcessingStatusOptions.find(s => s.value === record.fileStatus) || - fileProcessingStatusOptions[0]; - const isSpinning = record.fileStatus !== "Processed"; + // 处理fileStatus为null或undefined的情况 + // console.log('fileStatus',record.fileStatus) + const fileStatus = record.fileStatus || "Processed"; + const status = fileProcessingStatusOptions.find(s => s.value === fileStatus) || + fileProcessingStatusOptions[0]; + const isSpinning = fileStatus !== "Processed"; return ( -
+
{status.label}
@@ -452,8 +498,11 @@ export default function DocumentsIndex() { { title: "审核状态", key: "auditStatus", + width:"10%", render: (_: unknown, record: DocumentUI) => { - const statusKey = record.auditStatus.toString(); + // 处理auditStatus为null或undefined的情况,默认为0(待审核) + const auditStatus = record.auditStatus != null ? record.auditStatus : 0; + const statusKey = auditStatus.toString(); const statusInfo = auditStatusMapping[statusKey] || auditStatusMapping["0"]; return (
@@ -466,7 +515,7 @@ export default function DocumentsIndex() { { title: "问题数量", key: "issues", - width:"60px", + width:"10%", render: (_: unknown, record: DocumentUI) => ( record.issues === null ? "-" : record.issues ) @@ -474,15 +523,16 @@ export default function DocumentsIndex() { { title: "上传时间", key: "uploadTime", + width:"10%", render: (_: unknown, record: DocumentUI) => record.uploadTime }, { title: "操作", key: "actions", - width: "280px", + width: "20%", render: (_: unknown, record: DocumentUI) => (
- {record.auditStatus === 0 ? ( + {(record.auditStatus === 0 || record.auditStatus == null) ? ( handleDelete(record.id.toString(), record.name)} + onClick={() => handleDelete(record.id.toString(), record.name, record.fileStatus)} > 删除 @@ -578,51 +628,56 @@ export default function DocumentsIndex() { } noActionDivider={true} > - +
+ - - - - - - - handleDateChange('dateFrom', value)} - onEndDateChange={(value) => handleDateChange('dateTo', value)} - className="flex-1" - simple={true} - /> + + + + + + + + + handleDateChange('dateFrom', value)} + onEndDateChange={(value) => handleDateChange('dateTo', value)} + simple={true} + /> +
diff --git a/app/routes/documents.edit.tsx b/app/routes/documents.edit.tsx index 29b5db0..2324fbc 100644 --- a/app/routes/documents.edit.tsx +++ b/app/routes/documents.edit.tsx @@ -71,7 +71,7 @@ export async function loader({ request }: LoaderFunctionArgs) { // 并行获取文档详情和文档类型列表 const [documentResponse, documentTypesResponse] = await Promise.all([ getDocument(id), - getDocumentTypes() + getDocumentTypes({ pageSize: 500 }) ]); if (documentResponse.error) { @@ -198,6 +198,8 @@ export default function DocumentEdit() { // 在新窗口打开文档预览 const openPreview = () => { // 假设有一个预览URL的格式,比如 /preview?path=xxx + console.log('documentstest', document); + const previewUrl = `/preview?path=${encodeURIComponent(document.path)}&name=${encodeURIComponent(document.name)}`; window.open(previewUrl, '_blank'); }; @@ -268,11 +270,12 @@ export default function DocumentEdit() {
-