feat(knowledge): restructure knowledge base pages and components

- Implement new setting and testing pages with breadcrumbs
This commit is contained in:
2025-10-14 18:06:12 +08:00
parent 7384ae36d0
commit 9f6785672f
12 changed files with 834 additions and 48 deletions

View File

@@ -37,7 +37,7 @@ const parserOptions = [
{ value: DOCUMENT_PARSER_TYPES.KnowledgeGraph, label: '知识图谱解析器', description: '构建知识图谱结构' },
];
interface ConfigFormData {
export interface ConfigFormData {
parser_id: DocumentParserType;
chunk_token_count?: number;
layout_recognize?: boolean;

View File

@@ -46,6 +46,12 @@ interface FileListComponentProps {
onRefresh: () => void;
rowSelectionModel: GridRowSelectionModel;
onRowSelectionModelChange: (model: GridRowSelectionModel) => void;
// 分页相关props
total: number;
page: number;
pageSize: number;
onPageChange: (page: number) => void;
onPageSizeChange: (pageSize: number) => void;
}
const getFileIcon = (type: string) => {
@@ -104,6 +110,11 @@ const FileListComponent: React.FC<FileListComponentProps> = ({
onRefresh,
rowSelectionModel,
onRowSelectionModelChange,
total,
page,
pageSize,
onPageChange,
onPageSizeChange,
}) => {
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const [selectedFileId, setSelectedFileId] = useState<string>('');
@@ -141,10 +152,15 @@ const FileListComponent: React.FC<FileListComponentProps> = ({
handleMenuClose();
};
// 过滤文件列表
const filteredFiles = files.filter(file =>
file.name.toLowerCase().includes(searchKeyword.toLowerCase())
);
// 处理分页变化
const handlePaginationModelChange = (model: { page: number; pageSize: number }) => {
if (model.page !== page - 1) { // DataGrid的page是0-based我们的是1-based
onPageChange(model.page + 1);
}
if (model.pageSize !== pageSize) {
onPageSizeChange(model.pageSize);
}
};
// DataGrid 列定义
const columns: GridColDef[] = [
@@ -278,7 +294,7 @@ const FileListComponent: React.FC<FileListComponentProps> = ({
{/* 文件列表 */}
<Paper sx={{ height: 600, width: '100%' }}>
<DataGrid
rows={filteredFiles}
rows={files}
columns={columns}
loading={loading}
checkboxSelection
@@ -286,11 +302,13 @@ const FileListComponent: React.FC<FileListComponentProps> = ({
rowSelectionModel={rowSelectionModel}
onRowSelectionModelChange={onRowSelectionModelChange}
pageSizeOptions={[10, 25, 50, 100]}
initialState={{
pagination: {
paginationModel: { page: 0, pageSize: 25 },
},
paginationMode="server"
rowCount={total}
paginationModel={{
page: page - 1,
pageSize: pageSize,
}}
onPaginationModelChange={handlePaginationModelChange}
localeText={getDataGridLocale().components.MuiDataGrid.defaultProps.localeText}
sx={{
'& .MuiDataGrid-cell:focus': {

View File

@@ -1,9 +1,10 @@
import React from 'react';
import { SpeedDial, SpeedDialAction } from '@mui/material';
import {
Settings as SettingsIcon,
Dashboard as DashboardIcon,
Search as TestIcon,
Settings as ConfigIcon,
} from '@mui/icons-material';
interface FloatingActionButtonsProps {
@@ -42,7 +43,7 @@ const FloatingActionButtons: React.FC<FloatingActionButtonsProps> = ({
},
},
}}
icon={<SettingsIcon />}
icon={<DashboardIcon />}
>
{actions.map((action) => (
<SpeedDialAction

View File

@@ -20,7 +20,7 @@ import {
Save as SaveIcon,
} from '@mui/icons-material';
interface BasicFormData {
export interface BasicFormData {
name: string;
description: string;
permission: string;

View File

@@ -0,0 +1,89 @@
import React from 'react';
import { useLocation, useNavigate, useParams } from 'react-router-dom';
import { Breadcrumbs, Link, Typography } from '@mui/material';
import type { IKnowledge } from '@/interfaces/database/knowledge';
interface KnowledgeBreadcrumbsProps {
knowledge?: IKnowledge | null;
sx?: object;
}
const KnowledgeBreadcrumbs: React.FC<KnowledgeBreadcrumbsProps> = ({ knowledge, sx }) => {
const location = useLocation();
const navigate = useNavigate();
const { id } = useParams<{ id: string }>();
// 解析当前路径
const pathSegments = location.pathname.split('/').filter(Boolean);
// 生成面包屑项
const breadcrumbItems = [];
// 第一层:知识库列表
breadcrumbItems.push({
label: '知识库',
path: '/knowledge',
isLast: false
});
// 第二层知识库详情如果有id
if (id && knowledge) {
const isDetailPage = pathSegments.length === 2; // /knowledge/:id
breadcrumbItems.push({
label: knowledge.name,
path: `/knowledge/${id}`,
isLast: isDetailPage
});
// 第三层:设置或测试页面
if (pathSegments.length === 3) {
const lastSegment = pathSegments[2];
let label = '';
switch (lastSegment) {
case 'setting':
label = '设置';
break;
case 'testing':
label = '测试';
break;
default:
label = lastSegment;
}
breadcrumbItems.push({
label,
path: location.pathname,
isLast: true
});
}
}
return (
<Breadcrumbs sx={{ mb: 2, ...sx }}>
{breadcrumbItems.map((item, index) => {
if (item.isLast) {
return (
<Typography key={index} color="text.primary">
{item.label}
</Typography>
);
}
return (
<Link
key={index}
component="button"
variant="body1"
onClick={() => navigate(item.path)}
sx={{ textDecoration: 'none' }}
>
{item.label}
</Link>
);
})}
</Breadcrumbs>
);
};
export default KnowledgeBreadcrumbs;