瀏覽代碼

feat: 接入预定义问题

zhouyuhao 6 月之前
父節點
當前提交
d9d89bc97e
共有 2 個文件被更改,包括 13 次插入7 次删除
  1. 10 6
      src/views/AIRobotChat/src/AIRobotChat.vue
  2. 3 1
      src/views/Layout/src/LayoutView.vue

+ 10 - 6
src/views/AIRobotChat/src/AIRobotChat.vue

@@ -69,9 +69,9 @@ const messages = ref<MessageItem[]>([
   }
 ])
 messages.value = JSON.parse(sessionStorage.getItem('AIChat')) || messages.value
-onMounted(() => {
+const handleOpen = () => {
   scrollToBottom()
-})
+}
 
 watch(
   () => messages.value,
@@ -121,15 +121,17 @@ const parseHtmlString = (data) => {
 
 const progressInterval = ref()
 const serial_no = ref()
+const is_FixedAnswer = ref(true) // 是否为预设问题 true是自由问题 false是预设问题
 const aiChat = (question, isPresetQuestion) => {
   serial_no.value = userStore.userInfo?.uname + Date.now().toString()
   $api
     .aiChat({
       serial_no: serial_no.value,
       prompt: sessionStorage.getItem('prompt'),
-      // question_type: isPresetQuestion ? 'Predefined Question' : 'Free Question',
+      // question_type: isPresetQuestion || !is_FixedAnswer ? 'Predefined Question' : 'Free Question',
       question_type: 'Free Question',
-      question_content: question
+      question_content: question,
+      fixed_faq: !is_FixedAnswer ? messages.value[messages.value.length - 2].content : ''
     })
     .then((res) => {
       if (isPause.value) {
@@ -250,6 +252,7 @@ const handlePause = () => {
     .then((res) => {
       if (res.code === 200) {
         clearInterval(progressInterval.value)
+        is_FixedAnswer.value = true
         queryTime.value = -1
         messages.value[messages.value.length - 1].isCancel = true
         messages.value[messages.value.length - 1].content = progressStatus.cancel
@@ -279,12 +282,13 @@ const handleFeedback = (index, feedback) => {
 const emit = defineEmits(['close'])
 // 关闭聊天窗口
 const handleClose = () => {
-  progressInterval.value && clearInterval(progressInterval.value)
+  // progressInterval.value && clearInterval(progressInterval.value)
   emit('close')
 }
 
 defineExpose({
-  handleSend
+  handleSend,
+  handleOpen
 })
 </script>
 

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

@@ -18,10 +18,12 @@ const handleMenuCollapse = (val: boolean) => {
 const isShowAIRobotChat = ref(false)
 const handleColseRobotChat = () => {
   isShowAIRobotChat.value = false
+  AIRobotChatref.value?.handleOpen()
 }
 
 const AvatarClick = () => {
   isShowAIRobotChat.value = true
+  AIRobotChatref.value?.handleOpen()
 }
 
 const AIRobotChatref = ref()
@@ -76,7 +78,7 @@ onMounted(() => {
     <AIRobot @AvatarClick="AvatarClick" @handelClickAIDefault="handelClickAIDefault"></AIRobot>
     <AIRobotChat
       ref="AIRobotChatref"
-      v-if="isShowAIRobotChat"
+      v-show="isShowAIRobotChat"
       @close="handleColseRobotChat"
     ></AIRobotChat>
     <ScoringGrade></ScoringGrade>