7171 >
7272 <SearchOutlined v-if =" !loading" /> 加载图谱
7373 </a-button >
74- <a-button
75- type =" default"
76- size =" small"
77- :loading =" loading"
78- @click =" loadTestData"
79- :disabled =" !selectedDatabase"
80- style =" margin-left : 6px "
81- title =" 加载测试数据(用于演示图谱功能)"
82- >
83- <ReloadOutlined v-if =" !loading" /> 测试数据
84- </a-button >
8574 </div >
8675
87- <div v-if =" !props.hideStats" class =" stats-section" >
88- <a-tag color =" blue" size =" small" >节点: {{ stats.displayed_nodes || 0 }}</a-tag >
89- <a-tag color =" green" size =" small" >边: {{ stats.displayed_edges || 0 }}</a-tag >
90- <!-- <a-tag v-if="stats.is_truncated" color="red" size="small">已截断</a-tag> -->
91- </div >
9276 </div >
9377
9478 <!-- Sigma.js图可视化容器 -->
9882 :class =" { 'loading': loading }"
9983 ></div >
10084
85+ <div v-if =" !props.hideStats" class =" graph-overlay-stats" >
86+ <a-tag color =" blue" size =" small" >节点: {{ stats.displayed_nodes || 0 }}</a-tag >
87+ <a-tag color =" green" size =" small" >边: {{ stats.displayed_edges || 0 }}</a-tag >
88+ </div >
89+
10190 <!-- 节点详情面板 -->
10291 <div
10392 v-if =" selectedNodeData"
@@ -234,7 +223,6 @@ import { ref, reactive, onMounted, onUnmounted, computed, watch, nextTick } from
234223import { message } from ' ant-design-vue'
235224import {
236225 SearchOutlined ,
237- ReloadOutlined ,
238226 ClearOutlined ,
239227 CloseOutlined ,
240228 PlusOutlined ,
@@ -248,6 +236,7 @@ import { EdgeArrowProgram } from 'sigma/rendering'
248236
249237import { lightragApi } from ' @/apis/graph_api'
250238import { useGraphStore } from ' @/stores/graphStore'
239+ import { useDatabaseStore } from ' @/stores/database'
251240import ' @/assets/css/sigma.css'
252241
253242// 定义 props
@@ -283,6 +272,7 @@ const emit = defineEmits(['update:stats', 'refresh-graph', 'clear-graph'])
283272
284273// 状态管理
285274const graphStore = useGraphStore ()
275+ const databaseStore = useDatabaseStore ()
286276
287277// 响应式引用
288278const loading = ref (false )
@@ -714,9 +704,13 @@ const loadGraphData = async () => {
714704
715705 // 设置图数据
716706 graphStore.setRawGraph(rawGraph)
707+ // 更新 displayed 计数(当前视图)以及来自后端的 total 计数(整个库)
717708 graphStore.stats = {
718709 displayed_nodes: graphResponse.data.nodes.length,
719710 displayed_edges: graphResponse.data.edges.length,
711+ // 从 statsResponse 填充整个知识库的统计信息(后端返回 total_nodes/total_edges)
712+ total_nodes: statsResponse.data.total_nodes ?? graphStore.stats.total_nodes ?? 0,
713+ total_edges: statsResponse.data.total_edges ?? graphStore.stats.total_edges ?? 0,
720714 is_truncated: graphResponse.data.is_truncated
721715 }
722716
@@ -755,82 +749,6 @@ const loadGraphData = async () => {
755749 }
756750}
757751
758- // 加载测试数据
759- const loadTestData = async () => {
760- if (!selectedDatabase.value) {
761- message.warning('请先选择数据库')
762- return
763- }
764-
765- loading.value = true
766- loadingMessage.value = '加载测试数据中...'
767-
768- try {
769- const response = await fetch(` / api/ graph/ lightrag/ test- data? db_id= ${selectedDatabase .value }` , {
770- headers: {
771- 'Authorization': ` Bearer ${localStorage .getItem (' access_token' )}` ,
772- 'Content-Type': 'application/json'
773- }
774- })
775-
776- if (!response.ok) {
777- throw new Error(` HTTP ${response .status }: ${response .statusText }` )
778- }
779-
780- const testData = await response.json()
781-
782- if (testData.success) {
783- // 创建图数据
784- const rawGraph = graphStore.createGraphFromApiData(
785- testData.data.nodes,
786- testData.data.edges
787- )
788-
789- // 设置图数据
790- graphStore.setRawGraph(rawGraph)
791- graphStore.stats = {
792- displayed_nodes: testData.data.nodes.length,
793- displayed_edges: testData.data.edges.length,
794- is_truncated: testData.data.is_truncated
795- }
796-
797- console.log('Test graph created:', {
798- nodes: rawGraph.nodes.length,
799- edges: rawGraph.edges.length,
800- sampleNode: rawGraph.nodes[0],
801- sampleEdge: rawGraph.edges[0]
802- })
803-
804- // 创建Sigma图
805- const sigmaGraph = graphStore.createSigmaGraph(rawGraph)
806- graphStore.setSigmaGraph(sigmaGraph)
807-
808- // 应用布局
809- await applyLayout(sigmaGraph)
810-
811- // 更新Sigma实例
812- if (sigmaInstance) {
813- sigmaInstance.setGraph(sigmaGraph)
814- sigmaInstance.refresh()
815- } else {
816- await nextTick()
817- await initSigma()
818- }
819-
820- message.success(` 测试数据加载成功:${rawGraph .nodes .length } 个节点,${rawGraph .edges .length } 条边` )
821- } else {
822- throw new Error('Failed to load test data')
823- }
824-
825- } catch (error) {
826- console.error('加载测试数据失败:', error)
827- message.error('加载测试数据失败: ' + error.message)
828- } finally {
829- loading.value = false
830- loadingMessage.value = '加载图数据中...'
831- }
832- }
833-
834752// 加载完整图数据
835753const loadFullGraph = async () => {
836754 selectedLabel.value = '*'
@@ -1277,7 +1195,7 @@ defineExpose({
12771195
12781196.control-panel {
12791197 background: white;
1280- padding: 8px 0 ; /* Reduced from 16px */
1198+ padding: 6px 16px ; /* Reduced from 16px */
12811199 border-bottom: none;
12821200 display: flex;
12831201 gap: 12px; /* Reduced from 16px */
@@ -1301,9 +1219,9 @@ defineExpose({
13011219
13021220.sigma-container {
13031221 flex: 1;
1304- background: white;
1222+ // background: white;
13051223 position: relative; /* 确保子元素可以相对于此容器定位 */
1306- border: 1px solid var(--main-20);
1224+ // border: 1px solid var(--main-20);
13071225 border-radius: 8px;
13081226 overflow: hidden;
13091227
@@ -1312,6 +1230,16 @@ defineExpose({
13121230 }
13131231}
13141232
1233+ .graph-overlay-stats {
1234+ position: absolute;
1235+ left: 16px;
1236+ bottom: 16px;
1237+ display: flex;
1238+ gap: 8px;
1239+ pointer-events: none;
1240+ z-index: 1100;
1241+ }
1242+
13151243.detail-panel {
13161244 position: absolute;
13171245 width: 240px; /* Reduced from 300px */
@@ -1546,4 +1474,4 @@ defineExpose({
15461474 font-size: 12px; /* Added smaller font size */
15471475 }
15481476}
1549- </style>
1477+ </style>
0 commit comments