import { CloudUploadOutlined, DeleteOutlined, FileTextOutlined, ReloadOutlined, SearchOutlined, UnorderedListOutlined } from '@ant-design/icons'; import { Button, Empty, Input, Popconfirm, Space, Spin, Switch, Table, Tag, Tooltip, } from 'antd'; import type { ColumnsType } from 'antd/es/table'; import type { Document, IndexingStatus } from '~/api/dify-dataset/type/documentTypes'; import { useDocumentList } from '~/hooks/dify-dataset-manager/document-list'; import type { DocumentListProps } from '~/types/dify-dataset-manager/document-list'; import { usePermission } from '~/hooks/usePermission'; import '../../styles/components/dify-dataset-manager/index.css'; import DocumentUpload from './document-upload'; /** * 文档列表组件 */ export default function DocumentList({ datasetId, documents, loading, total, page, pageSize, onPageChange, onDocumentDeleted, onDocumentStatusChanged, onRefresh, onViewDocument, canEditDataset = true, }: DocumentListProps) { const { searchValue, setSearchValue, deletingId, showUploadPage, getStatusConfig, formatDate, formatNumber, handleDelete, handleToggleStatus, handleUploadClick, handleUploadClose, handleUploadSuccess, filterDocuments, } = useDocumentList(datasetId, onDocumentDeleted, onDocumentStatusChanged, onRefresh); const { hasPermission } = usePermission(); const canWrite = hasPermission('dify:document:manage') && canEditDataset; // 过滤文档 const filteredDocuments = filterDocuments(documents); // 表格列定义 const columns: ColumnsType = [ { title: '文档名称', dataIndex: 'name', key: 'name', ellipsis: true, render: (name: string) => (
{name}
), }, { title: '状态', dataIndex: 'indexing_status', key: 'indexing_status', width: 120, render: (status: IndexingStatus) => { const config = getStatusConfig(status); return ( {config.text} ); }, }, { title: '字数', dataIndex: 'word_count', key: 'word_count', width: 100, render: (count: number) => formatNumber(count), }, { title: '命中次数', dataIndex: 'hit_count', key: 'hit_count', width: 100, render: (count: number) => formatNumber(count), }, { title: '启用', dataIndex: 'enabled', key: 'enabled', width: 80, render: (enabled: boolean, record) => ( handleToggleStatus(record.id, checked)} /> ), }, { title: '创建时间', dataIndex: 'created_at', key: 'created_at', width: 160, render: (timestamp: number) => formatDate(timestamp), }, { title: '操作', key: 'action', width: 120, render: (_, record) => ( )} {/* 搜索栏 */}
} value={searchValue} onChange={(e) => setSearchValue(e.target.value)} allowClear style={{ width: 280 }} />
{/* 文档表格 */}
{loading && documents.length === 0 ? (
加载中...
) : filteredDocuments.length === 0 ? (
{!searchValue && ( )}
) : ( )} {/* 底部分页器 */} {filteredDocuments.length > 0 && (
共 {total} 条
第 {page} 页 / 共 {Math.ceil(total / pageSize)} 页
)} )} ); }