From 1f9c3f86ff9dd67d70a6d93c55f17f5294a8144c Mon Sep 17 00:00:00 2001 From: wonder Date: Mon, 6 Apr 2026 14:43:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=83=BD=E5=A4=9F=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=B9=B6=E6=9F=A5=E7=9C=8B=E8=8A=82=E7=82=B9=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/KnowledgeGraph.tsx | 81 +++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 5 deletions(-) diff --git a/frontend/src/pages/KnowledgeGraph.tsx b/frontend/src/pages/KnowledgeGraph.tsx index e4adebd..9df7c00 100644 --- a/frontend/src/pages/KnowledgeGraph.tsx +++ b/frontend/src/pages/KnowledgeGraph.tsx @@ -1,4 +1,4 @@ -import { useMemo } from 'react'; +import { useMemo, useState } from 'react'; import GraphView from '../components/GraphView/index'; import SearchBar from '../components/SearchBar/index'; import NodePanel from '../components/NodePanel/index'; @@ -28,6 +28,7 @@ export const KnowledgeGraph = () => { } = useGraphData(); const { layout } = useGraphLayout(); + const [isExpanded, setIsExpanded] = useState(false); const legendData = useMemo(() => { if (!graphData || graphData.nodes.length === 0) { @@ -36,6 +37,11 @@ export const KnowledgeGraph = () => { return generateLegendData(graphData); }, [graphData]); + const propertiesList = useMemo(() => { + if (!hoveredNode?.properties) return []; + return Object.entries(hoveredNode.properties); + }, [hoveredNode]); + return (
{loading ? ( @@ -72,10 +78,75 @@ export const KnowledgeGraph = () => { /> {hoveredNode && ( -
-
{hoveredNode.label}
- {hoveredNode.type && ( -
{hoveredNode.type}
+
+ {!isExpanded ? ( +
+
+
{hoveredNode.label}
+
+ {hoveredNode.type && ( +
+ {hoveredNode.type} +
+ )} + {propertiesList.length > 0 && ( +
+ {propertiesList.slice(0, 2).map(([key, value]) => ( +
+ {key}: + + {typeof value === 'object' ? JSON.stringify(value) : String(value)} + +
+ ))} + {propertiesList.length > 2 && ( +
还有 {propertiesList.length - 2} 项属性...
+ )} +
+ )} + {propertiesList.length > 0 && ( + + )} +
+ ) : ( +
+
+
{hoveredNode.label}
+ +
+ {hoveredNode.type && ( +
+ {hoveredNode.type} +
+ )} + {propertiesList.length > 0 && ( +
+
+ 属性 ({propertiesList.length}) +
+
+ {propertiesList.map(([key, value]) => ( +
+ {key}: + + {typeof value === 'object' ? JSON.stringify(value) : String(value)} + +
+ ))} +
+
+ )} +
)}
)}