Explorar el Código

fix: 修复退出时不能正确清空 ai 对话内容bug

zhouyuhao hace 6 meses
padre
commit
9f7b80b263
Se han modificado 2 ficheros con 27 adiciones y 2 borrados
  1. 14 1
      src/views/AIRobotChat/src/AIRobotChat.vue
  2. 13 1
      src/views/Layout/src/LayoutView.vue

+ 14 - 1
src/views/AIRobotChat/src/AIRobotChat.vue

@@ -297,9 +297,22 @@ const handleClose = () => {
   emit('close')
 }
 
+const clearData = () => {
+  messages.value = [
+    {
+      type: 'robot',
+      isShowFeedback: false,
+      content: 'You can click on Frequently Asked Questions above or type your own question'
+    }
+  ]
+  progressInterval.value && clearInterval(progressInterval.value)
+  sessionStorage.removeItem('AIChat')
+}
+
 defineExpose({
   handleSend,
-  handleOpen
+  handleOpen,
+  clearData
 })
 </script>
 

+ 13 - 1
src/views/Layout/src/LayoutView.vue

@@ -7,7 +7,9 @@ import ScoringGrade from '@/components/ScoringGrade'
 import AIRobot from '@/components/AIRobot'
 import AIRobotChat from '@/views/AIRobotChat/src/AIRobotChat.vue'
 import LogoMenu from './images/logo_menu.png'
+import { useUserStore } from '@/stores/modules/user'
 
+const userStore = useUserStore()
 const leftAsideWidth = ref('232px')
 const isCollapse = ref(false)
 const handleMenuCollapse = (val: boolean) => {
@@ -36,6 +38,14 @@ const handelClickAIDefault = async (item: any) => {
   }
 }
 
+watch(
+  () => userStore.isLogin,
+  (newVal) => {
+    if (!newVal) {
+      AIRobotChatref.value?.clearData()
+    }
+  }
+)
 const getPrompt = () => {
   $api.getPrompt().then((res) => {
     if (res.code === 200) {
@@ -44,7 +54,9 @@ const getPrompt = () => {
   })
 }
 onMounted(() => {
-  getPrompt()
+  if (userStore.isLogin) {
+    getPrompt()
+  }
 })
 </script>
 <template>