feat:完成上传文档时调整嵌入参数模块初版

This commit is contained in:
PingChuan
2025-12-02 22:29:32 +08:00
parent 1baf99fe28
commit 0f49426a2e
7 changed files with 2637 additions and 145 deletions
@@ -11,7 +11,6 @@ import {
message,
Empty,
Spin,
Upload,
} from 'antd';
import {
SearchOutlined,
@@ -28,7 +27,8 @@ import {
} from '@ant-design/icons';
import type { ColumnsType } from 'antd/es/table';
import type { Document, IndexingStatus } from '~/api/dify-dataset/type/documentTypes';
import { deleteDocument, toggleDocumentStatus, uploadDocument } from '~/api/dify-dataset/api/documentApi';
import { deleteDocument, toggleDocumentStatus } from '~/api/dify-dataset/api/documentApi';
import DocumentUpload from './document-upload';
import '../../styles/components/dify-dataset-manager/index.css';
interface DocumentListProps {
@@ -63,9 +63,11 @@ export default function DocumentList({
onViewDocument,
}: DocumentListProps) {
const [searchValue, setSearchValue] = useState('');
const [uploading, setUploading] = useState(false);
const [deletingId, setDeletingId] = useState<string | null>(null);
// 显示上传页面的状态
const [showUploadPage, setShowUploadPage] = useState(false);
/**
* 获取状态标签配置
*/
@@ -141,29 +143,29 @@ export default function DocumentList({
};
/**
* 处理文件上传
* 点击上传按钮,显示上传页面
*/
const handleUpload = async (file: File) => {
const handleUploadClick = () => {
if (!datasetId) {
message.error('请先选择知识库');
return false;
return;
}
setShowUploadPage(true);
};
setUploading(true);
try {
await uploadDocument(datasetId, file, (percent) => {
console.log('上传进度:', percent);
});
message.success('上传成功,正在处理...');
onRefresh();
} catch (err: any) {
console.error('上传文件失败:', err);
message.error(err.message || '上传失败');
} finally {
setUploading(false);
}
/**
* 关闭上传页面
*/
const handleUploadClose = () => {
setShowUploadPage(false);
};
return false;
/**
* 上传成功回调
*/
const handleUploadSuccess = () => {
setShowUploadPage(false);
onRefresh();
};
// 过滤文档
@@ -271,115 +273,114 @@ export default function DocumentList({
];
return (
<div className="document-list-page">
{/* 页面头部 */}
<div className="page-header">
<div className="header-left">
<h1></h1>
{/* <p className="page-description">
知识库的所有文件都在这里显示,整个知识库都可以被接到 Dify 引用或通过 Chat 插件进行索引。
</p> */}
</div>
<div className="header-actions">
<Tooltip title="刷新">
<Button
icon={<ReloadOutlined />}
onClick={onRefresh}
loading={loading}
/>
</Tooltip>
<Upload
beforeUpload={handleUpload}
showUploadList={false}
accept=".txt,.md,.pdf,.docx,.doc,.csv,.xlsx,.xls"
disabled={!datasetId}
>
<Button
type="primary"
icon={<CloudUploadOutlined />}
loading={uploading}
disabled={!datasetId}
>
</Button>
</Upload>
</div>
</div>
{/* 搜索栏 */}
<div className="document-search-bar">
<Input
placeholder="搜索文档..."
prefix={<SearchOutlined />}
value={searchValue}
onChange={(e) => setSearchValue(e.target.value)}
allowClear
style={{ width: 280 }}
<>
{/* 上传页面 */}
{showUploadPage ? (
<DocumentUpload
datasetId={datasetId}
onClose={handleUploadClose}
onSuccess={handleUploadSuccess}
/>
</div>
{/* 文档表格 */}
<div className="document-table-wrapper">
{loading && documents.length === 0 ? (
<div className="loading-state">
<Spin size="large" />
<div className="loading-text">...</div>
) : (
<div className="document-list-page">
{/* 页面头部 */}
<div className="page-header">
<div className="header-left">
<h1></h1>
</div>
<div className="header-actions">
<Tooltip title="刷新">
<Button
icon={<ReloadOutlined />}
onClick={onRefresh}
loading={loading}
/>
</Tooltip>
<Button
type="primary"
icon={<CloudUploadOutlined />}
onClick={handleUploadClick}
disabled={!datasetId}
>
</Button>
</div>
</div>
) : filteredDocuments.length === 0 ? (
<div className="empty-state">
<Empty description={searchValue ? '未找到匹配的文档' : '暂无文档'}>
{!searchValue && (
<Upload
beforeUpload={handleUpload}
showUploadList={false}
accept=".txt,.md,.pdf,.docx,.doc,.csv,.xlsx,.xls"
{/* 搜索栏 */}
<div className="document-search-bar">
<Input
placeholder="搜索文档..."
prefix={<SearchOutlined />}
value={searchValue}
onChange={(e) => setSearchValue(e.target.value)}
allowClear
style={{ width: 280 }}
/>
</div>
{/* 文档表格 */}
<div className="document-table-wrapper">
{loading && documents.length === 0 ? (
<div className="loading-state">
<Spin size="large" />
<div className="loading-text">...</div>
</div>
) : filteredDocuments.length === 0 ? (
<div className="empty-state">
<Empty description={searchValue ? '未找到匹配的文档' : '暂无文档'}>
{!searchValue && (
<Button
type="primary"
icon={<CloudUploadOutlined />}
onClick={handleUploadClick}
>
</Button>
)}
</Empty>
</div>
) : (
<Table
className="document-table"
columns={columns}
dataSource={filteredDocuments}
rowKey="id"
loading={loading}
pagination={false}
size="small"
scroll={{ x: 'max-content' }}
/>
)}
</div>
{/* 底部分页器 */}
{filteredDocuments.length > 0 && (
<div className="document-pagination">
<span className="pagination-total"> {total} </span>
<div className="pagination-controls">
<Button
size="small"
disabled={page <= 1}
onClick={() => onPageChange(page - 1)}
>
<Button type="primary" icon={<CloudUploadOutlined />}>
</Button>
</Upload>
)}
</Empty>
</div>
) : (
<Table
className="document-table"
columns={columns}
dataSource={filteredDocuments}
rowKey="id"
loading={loading}
pagination={false}
size="small"
scroll={{ x: 'max-content' }}
/>
)}
</div>
{/* 底部分页器 */}
{filteredDocuments.length > 0 && (
<div className="document-pagination">
<span className="pagination-total"> {total} </span>
<div className="pagination-controls">
<Button
size="small"
disabled={page <= 1}
onClick={() => onPageChange(page - 1)}
>
</Button>
<span className="pagination-info">
{page} / {Math.ceil(total / pageSize)}
</span>
<Button
size="small"
disabled={page >= Math.ceil(total / pageSize)}
onClick={() => onPageChange(page + 1)}
>
</Button>
</div>
</Button>
<span className="pagination-info">
{page} / {Math.ceil(total / pageSize)}
</span>
<Button
size="small"
disabled={page >= Math.ceil(total / pageSize)}
onClick={() => onPageChange(page + 1)}
>
</Button>
</div>
</div>
)}
</div>
)}
</div>
</>
);
}