import { Modal } from '../ui/Modal';
import { Table } from '../ui/Table';
import { Button } from '../ui/Button';
import { FileIcon } from '../ui/FileIcon';
import { FileTypeTag } from '../ui/FileTypeTag';
import { StatusBadge } from '../ui/StatusBadge';
import { Pagination } from '../ui/Pagination';
import { LoadingIndicator } from '../ui/SkeletonScreen';
import { updateDocumentAuditStatus, type TaskDocument } from '~/api/cross-checking/cross-files'; // 更新导入
import { toastService } from '../ui/Toast';
import { formatDate } from '~/utils';
// 导出样式链接
export const links = () => [];
interface DocumentListModalProps {
isOpen: boolean;
onClose: () => void;
title: string;
files: TaskDocument[]; // 更新类型
onViewFile?: (fileId: string) => void;
loading?: boolean;
// 分页相关属性
currentPage?: number;
pageSize?: number;
total?: number;
onPageChange?: (page: number) => void;
onPageSizeChange?: (size: number) => void;
}
export function DocumentListModal({
isOpen,
onClose,
title,
files,
onViewFile,
loading = false,
// 分页属性,使用默认值
currentPage = 1,
pageSize = 10,
total = 0,
onPageChange,
onPageSizeChange
}: DocumentListModalProps) {
// 查看评查文件
const handleReviewFileClick = async (fileId: string, auditStatus: number | null) => {
// 检查audit_status是否为0,如果是则更新为2
if (auditStatus === 0 || auditStatus === null) {
try {
// TODO: 不需要传递userId,直接使用fileId找到对应文档,然后更新文档状态
// 更新文档状态
const updatedFile = await updateDocumentAuditStatus(fileId, 2);
console.log('更新后的文档状态:', updatedFile);
} catch (error) {
console.error('更新文件审核状态时出错:', error);
toastService.error(`更新文件审核状态时出错:${error instanceof Error ? error.message : '未知错误'}`);
return;
}
}
// 如果有自定义的查看处理函数,则调用它
if (onViewFile) {
onViewFile(fileId);
}
};
// 渲染问题摘要
const renderIssues = (file: TaskDocument) => {
// 如果文件有问题信息
if (file.issues && file.issues.length > 0) {
// 最多显示2个问题
const displayIssues = file.issues.slice(0, 2);
return (
{displayIssues.map((issue, index) => (
{issue.message}
))}
{file.issues.length > 2 && (
还有 {file.issues.length - 2} 个问题...
)}
);
}
// 如果没有问题信息,根据状态显示
if (file.evaluations_status === 1) {
return (
所有评查点均通过
);
}
// 其他状态显示占位符
return -
;
};
// 获取文件大小的友好显示
const formatFileSize = (bytes: number) => {
if (bytes === 0) return '0 B';
const k = 1024;
const sizes = ['B', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
};
// 定义表格列配置
const columns = [
{
title: "文件名称",
key: "fileName",
width: "30%",
render: (_: unknown, file: TaskDocument) => (
{file.file_name}
文件编号:{file.file_code}
大小:{formatFileSize(file.file_size)}
)
},
{
title: "文件类型",
key: "fileType",
width: "10%",
render: (_: unknown, file: TaskDocument) => (
)
},
{
title: "上传时间",
key: "uploadTime",
width: "12%",
render: (_: unknown, file: TaskDocument) => {
const uploadTime = formatDate(file.upload_time).split(' ');
const date = uploadTime[0];
const time = uploadTime[1];
return (
{date} {/* 2025-07-22 */}
{time} {/* 10:00:00 */}
);
}
},
{
title: "评查统计",
key: "reviewStatus",
width: "12%",
render: (_: unknown, file: TaskDocument) =>
// 要文件切分处理完之后,再显示评查统计
file.status === 'Processed' ? (
{file.pass_count > 0 && (
)}
{file.warning_count > 0 && (
)}
{file.fail_count > 0 && (
)}
{/* {file.manual_count > 0 && (
)} */}
) : (
-
)
},
{
title: "评查分数",
key: "score",
width: "8%",
render: (_: unknown, file: TaskDocument) => (
{file.final_score ? (
= 90 ? 'text-green-600' :
file.final_score >= 70 ? 'text-yellow-600' :
'text-red-600'
}`}>
{file.final_score}
) : (
-
)}
)
},
{
title: "问题摘要",
key: "issues",
width: "20%",
render: (_: unknown, file: TaskDocument) => renderIssues(file)
},
{
title: "操作",
key: "operation",
width: "auto",
render: (_: unknown, file: TaskDocument) => (
<>
>
)
}
];
return (
{loading ? (
// 显示loading状态
) : files.length === 0 ? (
// 无数据状态
暂无文档数据
) : (
// 有数据时显示表格和分页
<>
共
{total || files.length}
个文档
{/* 分页组件 - 只有在提供了分页回调函数且总数大于每页大小时才显示 */}
{onPageChange && total > 0 && (
{})}
onPageSizeChange={onPageSizeChange}
showTotal={true}
showPageSizeChanger={!!onPageSizeChange}
pageSizeOptions={[10, 20, 30, 50]}
/>
)}
>
)}
);
}