import { useEffect, useState, useRef } from 'react'; import { useTranslation } from 'react-i18next'; import { useNavigate } from 'react-router-dom' import { Row, Col, Radio, Button, List, Skeleton, Space } from 'antd'; import type { ColumnsType } from 'antd/es/table'; import type { RadioChangeEvent } from 'antd'; import { AppstoreOutlined, MenuOutlined } from '@ant-design/icons'; import Empty from '@/components/Empty' import type { Data, ConfigModalRef } from './types' import totalNum from '@/assets/images/memory/totalNum.svg' import onlineNum from '@/assets/images/memory/onlineNum.svg' import Table from '@/components/Table' import { getTotalEndUsers, userMemoryListUrl, getUserMemoryList } from '@/api/memory'; import ConfigModal from './components/ConfigModal'; import { useUser } from '@/store/user' const bgList = [ 'linear-gradient( 180deg, #F1F6FE 0%, #FBFDFF 100%)', 'linear-gradient( 180deg, #F1F9FE 0%, #FBFDFF 100%)', 'linear-gradient( 180deg, #FEFBF7 0%, #FBFDFF 100%)', 'linear-gradient( 180deg, #F1F9FE 0%, #FBFDFF 100%)', ] const countList = [ 'total_num', 'online_num', ] const IconList: Record = { total_num: totalNum, online_num: onlineNum, } export default function UserMemory() { const { t } = useTranslation(); const navigate = useNavigate() const { storageType } = useUser() const configModalRef = useRef(null) const [loading, setLoading] = useState(false); const [data, setData] = useState([]); const [countData, setCountData] = useState>({}); const [layout, setLayout] = useState<'card' | 'list'>('card'); // 获取数据 useEffect(() => { getCountData() getData() }, []); // 用户记忆统计 const getCountData = () => { getTotalEndUsers().then((res) => { setCountData(res as Record || {}) }) } const getData = () => { setLoading(true) getUserMemoryList().then((res) => { setData(res as Data[] || []) }) .finally(() => { setLoading(false) }) } console.log('storageType', storageType) const handleViewDetail = (id: string | number) => { switch (storageType) { case 'neo4j': navigate(`/user-memory/neo4j/${id}`) break; default: navigate(`/user-memory/${id}`) } } const handleChangeLayout = (e: RadioChangeEvent) => { const type = e.target.value setLayout(type) } // 表格列配置 const columns: ColumnsType = [ { title: t('userMemory.user'), dataIndex: 'end_user', key: 'end_user', render: (value) => value?.other_name && value?.other_name !== '' ? value?.other_name : value?.id || '-' }, { title: t('userMemory.knowledgeEntryCount'), dataIndex: 'memory_num', key: 'memory_num', render: (value) => value?.total || 0 }, { title: t('common.operation'), key: 'action', render: (_, record) => ( ), }, ]; return (
{countList.map(key => (
{countData[key] || 0}{key === 'avgInteractionTime' ? 's' : ''}
{t(`userMemory.${key}`)}
))}
{layout === 'card' && <> {loading ? : data.length > 0 ? ( { const { end_user, memory_num } = item as Data; const name = end_user?.other_name && end_user?.other_name !== '' ? end_user?.other_name : end_user?.id return (
handleViewDetail(end_user.id)} >
{name[0]}
{name || '-'}
{memory_num.total || 0}
{t(`userMemory.knowledgeEntryCount`)}
) }} /> ) : } } {layout === 'list' && } ); }