Преглед на файлове

终止问答和清除定时器

丸子 преди 3 месеца
родител
ревизия
25b9b3c102
променени са 3 файла, в които са добавени 28 реда и са изтрити 2 реда
  1. 2 2
      src/components/ai/image/TextToImage.vue
  2. 14 0
      src/components/ai/text/TextToText.vue
  3. 12 0
      src/views/laboratory/ExperimentalInterface.vue

+ 2 - 2
src/components/ai/image/TextToImage.vue

@@ -355,7 +355,7 @@ const refreshWatchImages = async () => {
     }
   })
   inProgressImageMap.value = newWatchImages
-  if (newWatchImages.size === 0) {
+  if (Object.keys(newWatchImages).length === 0) {
     inProgressTimerFun()
   }
 }
@@ -368,7 +368,7 @@ onMounted(async () => {
 
 /** 组件取消挂在的时候 */
 onUnmounted(async () => {
-  inProgressTimerFun()
+  inProgressTimerFun() // 组件取消挂在的时候,清除定时器
 })
 
 // 自动刷新 image 列表

+ 14 - 0
src/components/ai/text/TextToText.vue

@@ -409,6 +409,14 @@ const stopStream = async () => {
   conversationInProgress.value = false;
 };
 
+/** 清空消息列表 */
+const clearMessageList = () => {
+  activeMessageList.value = [];
+  prompt.value = "";
+  receiveMessageFullText.value = "";
+  receiveMessageDisplayedText.value = "";
+};
+
 /** 处理终止按钮点击 */
 const handleStopButtonClick = async () => {
   // 手动点击时停止语音播放
@@ -623,6 +631,12 @@ watch(
 onUnmounted(() => {
   stopPlayback();
 });
+
+// 暴露方法给父组件
+defineExpose({
+  stopStream,
+  clearMessageList
+});
 </script>
 
 <style scoped lang="scss">

+ 12 - 0
src/views/laboratory/ExperimentalInterface.vue

@@ -154,6 +154,8 @@ const CONSTANTS = {
 const router = useRouter() // 获取当前路由对象
 // 渲染页面标题
 const boxIconTitle = ref('')
+// AI组件refs
+const aiTextToText = ref(null)
 // 音频播放器实例
 const { stopPlayback } = useAudioPlayer();
 // 定义组件的props
@@ -221,6 +223,11 @@ const playPreviousVideo = () => {
     if (currentIndex > 0) {
       // 停止音频播放并清理资源
       stopPlayback();
+      // 终止AI问答流并清空消息列表
+      if (aiTextToText.value) {
+        aiTextToText.value.stopStream();
+        aiTextToText.value.clearMessageList();
+      }
       const previousCourse = props.courseList[currentIndex - 1]
       // 更新当前课程数据
       handleParentCourseData(previousCourse)
@@ -238,6 +245,11 @@ const playNextVideo = () => {
     if (currentIndex !== -1 && currentIndex < props.courseList.length - 1) {
       // 停止音频播放并清理资源
       stopPlayback();
+      // 终止AI问答流并清空消息列表
+      if (aiTextToText.value) {
+        aiTextToText.value.stopStream();
+        aiTextToText.value.clearMessageList();
+      }
       const nextCourse = props.courseList[currentIndex + 1]
       // 更新当前课程数据
       handleParentCourseData(nextCourse)