You've already forked DataMate
feat(knowledge-base): 实现知识库文件夹功能和优化文件管理
- 添加 datasetId 和 filePath 字段到 DatasetFile 接口 - 实现 resolveRelativeFileName 函数用于解析相对文件名 - 在 AddDataDialog 中使用 resolveRelativeFileName 处理文件名 - 添加文件夹浏览功能,支持目录导航和层级显示 - 实现文件夹删除功能,可批量删除目录下所有文件 - 集成 Folder 和 File 图标组件用于目录和文件区分 - 优化文件列表加载逻辑,使用分页和关键词搜索 - 添加文件夹状态显示和相应操作按钮 - 实现文件路径前缀管理和子目录过滤 - 重构文件列表渲染逻辑,支持目录和文件混合展示
This commit is contained in:
@@ -15,6 +15,7 @@ import { addKnowledgeBaseFilesUsingPost } from "../knowledge-base.api";
|
||||
import DatasetFileTransfer from "@/components/business/DatasetFileTransfer";
|
||||
import { DescriptionsItemType } from "antd/es/descriptions";
|
||||
import { DatasetFileCols } from "../knowledge-base.const";
|
||||
import type { DatasetFile } from "@/pages/DataManagement/dataset.model";
|
||||
|
||||
export default function AddDataDialog({ knowledgeBase, onDataAdded }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
@@ -25,6 +26,34 @@ export default function AddDataDialog({ knowledgeBase, onDataAdded }) {
|
||||
|
||||
const [selectedFilesMap, setSelectedFilesMap] = useState({});
|
||||
|
||||
const normalizePath = (value?: string) =>
|
||||
(value ?? "").replace(/\\/g, "/");
|
||||
|
||||
const resolveRelativeFileName = (file: DatasetFile) => {
|
||||
const normalizedName = normalizePath(file.fileName);
|
||||
if (normalizedName.includes("/")) {
|
||||
return normalizedName.replace(/^\/+/, "");
|
||||
}
|
||||
|
||||
const rawPath = normalizePath(file.path || file.filePath);
|
||||
const datasetId = String(file.datasetId || "");
|
||||
if (rawPath && datasetId) {
|
||||
const marker = `/${datasetId}/`;
|
||||
const index = rawPath.lastIndexOf(marker);
|
||||
if (index >= 0) {
|
||||
const relative = rawPath
|
||||
.slice(index + marker.length)
|
||||
.replace(/^\/+/, "");
|
||||
if (relative) {
|
||||
return relative;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const fallbackName = rawPath.split("/").pop();
|
||||
return fallbackName || file.fileName;
|
||||
};
|
||||
|
||||
// 定义分块选项
|
||||
const sliceOptions = [
|
||||
{ label: "默认分块", value: "DEFAULT_CHUNK" },
|
||||
@@ -129,7 +158,7 @@ export default function AddDataDialog({ knowledgeBase, onDataAdded }) {
|
||||
const requestData = {
|
||||
files: Object.values(selectedFilesMap).map((file) => ({
|
||||
id: String(file.id),
|
||||
fileName: file.fileName,
|
||||
fileName: resolveRelativeFileName(file as DatasetFile),
|
||||
})),
|
||||
processType: newKB.processType,
|
||||
chunkSize: Number(newKB.chunkSize), // 确保是数字类型
|
||||
|
||||
Reference in New Issue
Block a user