Browse Source

清除计时器

dangdang 1 week ago
parent
commit
595a00b8c3
1 changed files with 9 additions and 12 deletions
  1. 9 12
      src/views/ChatTts.vue

+ 9 - 12
src/views/ChatTts.vue

@@ -28,7 +28,7 @@ const currentRate = ref(0);
 const currentRound = computed(() => {
   const filteredMessages = chatList.value.filter(
     (message) =>
-      message.text !== "我没有听清,麻烦在重复一下。" && message.text !== ""
+      message.text !== "我没有听清,麻烦在重复一下。" && message.text !== "" && message.text !== "还有事儿吗?没事儿就挂了~"
   );
   return Math.floor(filteredMessages.length / 2);
 });
@@ -41,19 +41,16 @@ function startInactivityTimer() {
     const diff = (Date.now() - lastMessageTime.value) / 1000; // 单位: 秒
     console.log(diff,"开始计时1");
     //diff >= 180 && diff < 300
-    if (diff >= 30 && diff < 60 && !warned) {
+    if (diff >= 180 && diff < 300 && !warned) {
       console.log("开始计时3");
       // 超过 3 分钟没消息 -> 提示
       console.log("超过3分钟但小于5分钟,发送提示消息");
       const text = "还有事儿吗?没事儿就挂了~";
       pushTimeoutMessage(text);
-      // const text = "还有事儿吗?没事儿就挂了~";
-      // updateChatList(text, false);
-      // queue.add(async () => await splitMessage(text));
       warned = true;
     }
     // console.log("开始计时2");
-    if (diff >= 60 && !ended) {
+    if (diff >= 300 && !ended) {
       ended = true;               // 🔑 立即标记已结束
       clearInterval(inactivityTimer); // 🔑 停止定时器
       inactivityTimer = null;
@@ -66,12 +63,6 @@ function startInactivityTimer() {
       } catch (err) {
         console.error("[Timer] 会话结束接口出错:", err);
       }
-      // const res = await fetchTaskEnd(conversationId.value);
-      // if (res.code === 200) {
-      //   taskStatus.value = true
-      // }
-      // ended = true;
-      // clearInterval(inactivityTimer);
     }
   }, 1000);
 }
@@ -575,6 +566,12 @@ const handleTaskStatus = async () => {
   if (res.code == 200) {
     taskStatus.value = res.body
     localStorage.setItem("status", res.body);
+    // 🔑 任务结束时清理定时器
+    if (taskStatus.value && inactivityTimer) {
+      clearInterval(inactivityTimer);
+      inactivityTimer = null;
+      console.log("任务已结束,停止计时器");
+    }
   }
 }