import { useEffect, useState, forwardRef, useImperativeHandle } from 'react' import clsx from 'clsx' import { useTranslation } from 'react-i18next' import { useParams } from 'react-router-dom' import { Skeleton, Space } from 'antd'; import RbCard from '@/components/RbCard/Card' import Empty from '@/components/Empty'; import { getMemoryInsightReport, } from '@/api/memory' import type { MemoryInsightRef } from '../types' interface Data { memory_insight?: string; behavior_pattern?: string; key_findings?: string[]; growth_trajectory?: string; updated_at?: number; is_cached: boolean; } const MemoryInsight = forwardRef((_props, ref) => { const { t } = useTranslation() const { id } = useParams() const [loading, setLoading] = useState(false) const [data, setData] = useState({} as Data) useEffect(() => { if (!id) return getData() }, [id]) // 记忆洞察 const getData = () => { if (!id) return setLoading(true) getMemoryInsightReport(id).then((res) => { setData((res as Data) || {}) setLoading(false) }) .finally(() => { setLoading(false) }) } // 暴露给父组件的方法 useImperativeHandle(ref, () => ({ getData, })); return ( {loading ? : Object.keys(data).length > 0 ? {['memory_insight', 'key_findings', 'behavior_pattern', 'growth_trajectory'].map(key => { const value = data[key as keyof Data]; if (Array.isArray(value) && value.length > 0 || (!Array.isArray(value) && value)) { return (
{t(`userMemory.${key}`)}
{Array.isArray(data[key as keyof Data]) ? <> {(data[key as keyof Data] as string[])?.map((item: string, index: number) => (
- {item}
))} : data[key as keyof Data] as string }
) } return null })}
: }
) }) export default MemoryInsight