feat(user): add user data management system with global state
- Implement user store with Zustand for global state management - Create UserDataProvider component to initialize user data on app load - Add useUserData hook for accessing and managing user data - Refactor knowledge base list page to use new hooks
This commit is contained in:
@@ -29,6 +29,9 @@ import {
|
||||
CheckCircle as CheckCircleIcon,
|
||||
} from '@mui/icons-material';
|
||||
import { styled } from '@mui/material/styles';
|
||||
import KnowledgeGridView from '@/components/KnowledgeGridView';
|
||||
import UserDataDebug from '@/components/UserDataDebug';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
const PageContainer = styled(Box)(({ theme }) => ({
|
||||
padding: '1.5rem',
|
||||
@@ -128,6 +131,96 @@ const mockRecentQueries = [
|
||||
|
||||
const Dashboard: React.FC = () => {
|
||||
const [timeRange, setTimeRange] = useState('24h');
|
||||
const navigate = useNavigate();
|
||||
|
||||
// 模拟知识库数据
|
||||
const mockKnowledgeBases = [
|
||||
{
|
||||
id: '1',
|
||||
name: '产品文档库',
|
||||
description: '包含所有产品相关的技术文档和用户手册',
|
||||
status: '1',
|
||||
doc_num: 156,
|
||||
chunk_num: 1240,
|
||||
size: 2400000000, // 2.4GB
|
||||
update_date: '2024-01-15',
|
||||
created_by: 'admin',
|
||||
nickname: '管理员',
|
||||
create_date: '2024-01-01',
|
||||
create_time: 1704067200,
|
||||
tenant_id: 'tenant1',
|
||||
token_num: 50000,
|
||||
parser_config: {},
|
||||
parser_id: 'parser1',
|
||||
pipeline_id: 'pipeline1',
|
||||
pipeline_name: 'Default Pipeline',
|
||||
pipeline_avatar: '',
|
||||
permission: 'read',
|
||||
similarity_threshold: 0.8,
|
||||
update_time: 1705305600,
|
||||
vector_similarity_weight: 0.7,
|
||||
embd_id: 'embd1',
|
||||
operator_permission: 1,
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
name: '客服FAQ',
|
||||
description: '常见问题解答和客服对话记录',
|
||||
status: '1',
|
||||
doc_num: 89,
|
||||
chunk_num: 670,
|
||||
size: 1100000000, // 1.1GB
|
||||
update_date: '2024-01-14',
|
||||
created_by: 'support',
|
||||
nickname: '客服团队',
|
||||
create_date: '2024-01-02',
|
||||
create_time: 1704153600,
|
||||
tenant_id: 'tenant1',
|
||||
token_num: 30000,
|
||||
parser_config: {},
|
||||
parser_id: 'parser1',
|
||||
pipeline_id: 'pipeline1',
|
||||
pipeline_name: 'Default Pipeline',
|
||||
pipeline_avatar: '',
|
||||
permission: 'read',
|
||||
similarity_threshold: 0.8,
|
||||
update_time: 1705219200,
|
||||
vector_similarity_weight: 0.7,
|
||||
embd_id: 'embd1',
|
||||
operator_permission: 1,
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
name: '法律合规',
|
||||
description: '法律条文、合规要求和相关政策文档',
|
||||
status: '0',
|
||||
doc_num: 234,
|
||||
chunk_num: 1890,
|
||||
size: 3700000000, // 3.7GB
|
||||
update_date: '2024-01-13',
|
||||
created_by: 'legal',
|
||||
nickname: '法务部',
|
||||
create_date: '2024-01-03',
|
||||
create_time: 1704240000,
|
||||
tenant_id: 'tenant1',
|
||||
token_num: 75000,
|
||||
parser_config: {},
|
||||
parser_id: 'parser1',
|
||||
pipeline_id: 'pipeline1',
|
||||
pipeline_name: 'Default Pipeline',
|
||||
pipeline_avatar: '',
|
||||
permission: 'read',
|
||||
similarity_threshold: 0.8,
|
||||
update_time: 1705132800,
|
||||
vector_similarity_weight: 0.7,
|
||||
embd_id: 'embd1',
|
||||
operator_permission: 1,
|
||||
},
|
||||
];
|
||||
|
||||
const handleSeeAllKnowledgeBases = () => {
|
||||
navigate('/knowledge');
|
||||
};
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
@@ -253,6 +346,30 @@ const Dashboard: React.FC = () => {
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
{/* 知识库概览 */}
|
||||
<Card sx={{ border: '1px solid #E5E5E5', mb: 3 }}>
|
||||
<CardContent>
|
||||
<Box display="flex" justifyContent="space-between" alignItems="center" mb={2}>
|
||||
<Typography variant="h6" fontWeight={600}>
|
||||
知识库概览
|
||||
</Typography>
|
||||
<Button
|
||||
variant="outlined"
|
||||
size="small"
|
||||
onClick={handleSeeAllKnowledgeBases}
|
||||
>
|
||||
查看全部
|
||||
</Button>
|
||||
</Box>
|
||||
<KnowledgeGridView
|
||||
knowledgeBases={mockKnowledgeBases}
|
||||
maxItems={3}
|
||||
showSeeAll={true}
|
||||
onSeeAll={handleSeeAllKnowledgeBases}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* 系统状态 */}
|
||||
<Grid container spacing={3} sx={{ mb: 3 }}>
|
||||
<Grid item xs={12} md={6}>
|
||||
@@ -362,6 +479,15 @@ const Dashboard: React.FC = () => {
|
||||
</TableContainer>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* 用户数据调试组件 - 仅在开发环境显示 */}
|
||||
{process.env.NODE_ENV === 'development' && (
|
||||
<Card sx={{ border: '1px solid #E5E5E5', mt: 3 }}>
|
||||
<CardContent>
|
||||
<UserDataDebug />
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user