From 85f3f863950fa1d807697da437591062868e782c Mon Sep 17 00:00:00 2001
From: chengmw <chengmingwei_1984122@126.com>
Date: Thu, 26 Mar 2026 17:27:54 +0800
Subject: [PATCH] feat: 添加通话记录查看器功能模块

---
 web-app/src/components/common/OutboundCallWidget.jsx |   36 +++++++++++++++++++++++++++++++++++-
 1 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/web-app/src/components/common/OutboundCallWidget.jsx b/web-app/src/components/common/OutboundCallWidget.jsx
index 0bfa279..9bead7c 100644
--- a/web-app/src/components/common/OutboundCallWidget.jsx
+++ b/web-app/src/components/common/OutboundCallWidget.jsx
@@ -110,8 +110,14 @@
         }
       });
       
+      // 获取成功任务的 personId 集合
+      const successPersonIds = new Set(successJobs.map(job => job.personId));
+      
+      // 过滤掉已有成功任务的 personId 对应的失败任务(成功任务优先)
+      const filteredFailedJobs = uniqueFailedJobs.filter(job => !successPersonIds.has(job.personId));
+      
       // 合并所有任务
-      return [...successJobs, ...uniqueFailedJobs];
+      return [...successJobs, ...filteredFailedJobs];
     } catch (err) {
       console.error('读取外呼任务失败:', err);
       return [];
@@ -335,15 +341,38 @@
 
   // 定时轮询通话状态
   useEffect(() => {
+    // 组件挂载时设置为 true
+    isMountedRef.current = true;
+    
     // 初始加载
     fetchCallStatus();
     
     // 设置轮询定时器(10秒间隔)
     const interval = setInterval(fetchCallStatus, POLL_INTERVAL);
     
+    // 监听外呼任务更新事件(立即刷新)
+    const handleOutboundJobsUpdated = () => {
+      console.log('收到外呼任务更新事件,立即刷新');
+      fetchCallStatus();
+    };
+    window.addEventListener('outbound-jobs-updated', handleOutboundJobsUpdated);
+    
+    // 监听调解终止事件(关闭外呼气泡)
+    const handleMediationTerminated = () => {
+      console.log('收到调解终止事件,关闭外呼气泡');
+      setIsVisible(false);
+      setIsMinimized(true);
+      // 清空localStorage中的外呼任务
+      localStorage.removeItem(OUTBOUND_JOBS_KEY);
+      setCalls([]);
+    };
+    window.addEventListener('mediation-terminated', handleMediationTerminated);
+    
     // 清理函数
     return () => {
       clearInterval(interval);
+      window.removeEventListener('outbound-jobs-updated', handleOutboundJobsUpdated);
+      window.removeEventListener('mediation-terminated', handleMediationTerminated);
       isMountedRef.current = false;
     };
   }, [fetchCallStatus]);
@@ -385,6 +414,11 @@
     return true;
   });
 
+  // 如果没有活跃任务且不可见,不渲染任何内容
+  if (activeCalls.length === 0 && !isVisible) {
+    return null;
+  }
+
   // 如果最小化,显示AI客服图标
   if (isMinimized) {
     return (

--
Gitblit v1.8.0