马一丁

Add automatic refresh functionality to GraphRAG in full-screen mode

@@ -578,23 +578,31 @@ @@ -578,23 +578,31 @@
578 let allNodes = []; 578 let allNodes = [];
579 let allEdges = []; 579 let allEdges = [];
580 let reportId = {{ report_id | tojson if report_id else 'null' }}; 580 let reportId = {{ report_id | tojson if report_id else 'null' }};
  581 + let graphReady = false;
  582 + let graphPollTimer = null;
  583 + const GRAPH_POLL_INTERVAL = 4000;
581 584
582 // 初始化 585 // 初始化
583 document.addEventListener('DOMContentLoaded', () => { 586 document.addEventListener('DOMContentLoaded', () => {
584 loadGraphData(); 587 loadGraphData();
  588 + startGraphPolling();
585 setupEventListeners(); 589 setupEventListeners();
586 }); 590 });
587 591
588 // 加载图谱数据 592 // 加载图谱数据
589 - async function loadGraphData() {  
590 - showLoading(true); 593 + async function loadGraphData(options = {}) {
  594 + const { fromPoll = false } = options;
  595 + // 仅在首次或未加载成功时展示大遮罩
  596 + if (!graphReady || !fromPoll) {
  597 + showLoading(true);
  598 + }
591 599
592 try { 600 try {
593 const url = reportId 601 const url = reportId
594 ? `/api/graph/${reportId}` 602 ? `/api/graph/${reportId}`
595 : '/api/graph/latest'; 603 : '/api/graph/latest';
596 604
597 - const response = await fetch(url); 605 + const response = await fetch(url, { cache: 'no-store' });
598 const data = await response.json(); 606 const data = await response.json();
599 607
600 if (data.success && data.graph) { 608 if (data.success && data.graph) {
@@ -604,18 +612,39 @@ @@ -604,18 +612,39 @@
604 updateStats(data.graph.stats); 612 updateStats(data.graph.stats);
605 renderGraph(); 613 renderGraph();
606 showLoading(false); 614 showLoading(false);
  615 + showEmpty(false);
  616 + graphReady = true;
  617 + stopGraphPolling();
607 } else { 618 } else {
608 - showEmpty(true); 619 + if (!graphReady) {
  620 + showEmpty(true);
  621 + }
609 showLoading(false); 622 showLoading(false);
610 } 623 }
611 } catch (error) { 624 } catch (error) {
612 console.error('加载图谱失败:', error); 625 console.error('加载图谱失败:', error);
613 showToast('加载图谱失败: ' + error.message); 626 showToast('加载图谱失败: ' + error.message);
614 - showEmpty(true); 627 + if (!graphReady) {
  628 + showEmpty(true);
  629 + }
615 showLoading(false); 630 showLoading(false);
616 } 631 }
617 } 632 }
618 633
  634 + function startGraphPolling() {
  635 + if (graphPollTimer) return;
  636 + graphPollTimer = setInterval(() => {
  637 + loadGraphData({ fromPoll: true });
  638 + }, GRAPH_POLL_INTERVAL);
  639 + }
  640 +
  641 + function stopGraphPolling() {
  642 + if (graphPollTimer) {
  643 + clearInterval(graphPollTimer);
  644 + graphPollTimer = null;
  645 + }
  646 + }
  647 +
619 // 渲染图谱 648 // 渲染图谱
620 function renderGraph() { 649 function renderGraph() {
621 const container = document.getElementById('network'); 650 const container = document.getElementById('network');