lsc 3 هفته پیش
والد
کامیت
f5d5767d8d
2فایلهای تغییر یافته به همراه214 افزوده شده و 6 حذف شده
  1. 25 1
      src/services/course.ts
  2. 189 5
      src/views/Student/components/DialoguePanel.vue

+ 25 - 1
src/services/course.ts

@@ -149,6 +149,28 @@ export const insertChat = (params: any): Promise<any> => {
 export const getChatList = (params: any): Promise<any> => {
   return axios.post(`https://gpt4.cocorobo.cn/get_agent_park_chat`, params)
 }
+/**
+ * 
+ * 获取对话内容
+ * @param any 用户id
+ * @returns Promise<any>
+ */
+
+export const getAgentData = (params: any): Promise<any> => {
+  return axios.get(`https://appapi.cocorobo.cn/api/agents/agent/${params.id}`)
+}
+/**
+ * 
+ * 获取对话内容
+ * @param any 用户id
+ * @returns Promise<any>
+ */
+
+export const clearDialogue = (params: any): Promise<any> => {
+  return axios.delete(`https://appapi.cocorobo.cn/api/agentchats/clear_thread_context`, { data: params })
+}
+
+
 
 
 
@@ -166,6 +188,8 @@ export default {
   yweb_socket,
   getUser,
   insertChat,
-  getChatList
+  getChatList,
+  getAgentData,
+  clearDialogue,
 }
 

+ 189 - 5
src/views/Student/components/DialoguePanel.vue

@@ -31,6 +31,50 @@
         </div>
 			</div>
 		</div>
+		<!-- 清空聊天记录按钮区域 -->
+		<div class="dp_clearArea">
+			<div class="dp_clear_btn" 
+					v-if="!sendMessageLoading && !dialogueLoading"
+					@click.stop="clearChatHistory"
+					title="清空聊天记录">
+				  <svg
+              width="20"
+              height="20"
+              viewBox="0 0 20 20"
+              fill="none"
+              xmlns="http://www.w3.org/2000/svg"
+            >
+              <path
+                fill-rule="evenodd"
+                clip-rule="evenodd"
+                d="M2.5 3.125C2.5 2.77982 2.77982 2.5 3.125 2.5H16.875C17.2202 2.5 17.5 2.77982 17.5 3.125V8.02715C17.5 8.37233 17.2202 8.65215 16.875 8.65215C16.5298 8.65215 16.25 8.37233 16.25 8.02715V3.75H3.75V16.25H8.125C8.47018 16.25 8.75 16.5298 8.75 16.875C8.75 17.2202 8.47018 17.5 8.125 17.5H3.125C2.77982 17.5 2.5 17.2202 2.5 16.875V3.125Z"
+                fill="black"
+                fill-opacity="0.6"
+              />
+              <path
+                fill-rule="evenodd"
+                clip-rule="evenodd"
+                d="M5.625 6.1521C5.625 5.80692 5.90482 5.5271 6.25 5.5271H13.125C13.4702 5.5271 13.75 5.80692 13.75 6.1521C13.75 6.49728 13.4702 6.7771 13.125 6.7771H6.25C5.90482 6.7771 5.625 6.49728 5.625 6.1521Z"
+                fill="black"
+                fill-opacity="0.6"
+              />
+              <path
+                fill-rule="evenodd"
+                clip-rule="evenodd"
+                d="M5.625 9.2771C5.625 8.93192 5.90482 8.6521 6.25 8.6521H9.37496C9.72014 8.6521 9.99996 8.93192 9.99996 9.2771C9.99996 9.62228 9.72014 9.9021 9.37496 9.9021H6.25C5.90482 9.9021 5.625 9.62228 5.625 9.2771Z"
+                fill="black"
+                fill-opacity="0.6"
+              />
+              <path
+                fill-rule="evenodd"
+                clip-rule="evenodd"
+                d="M12.465 11.507L15.9141 14.9048C16.1279 14.5365 16.25 14.1088 16.25 13.6521C16.25 12.2714 15.1307 11.1521 13.75 11.1521C13.2799 11.1521 12.8406 11.2815 12.465 11.507ZM15.0374 15.7957L11.5873 12.397C11.3726 12.7659 11.25 13.1944 11.25 13.6521C11.25 15.0328 12.3693 16.1521 13.75 16.1521C14.2211 16.1521 14.6613 16.0222 15.0374 15.7957ZM11.0797 11.0192C11.759 10.3303 12.7051 9.9021 13.75 9.9021C15.8211 9.9021 17.5 11.581 17.5 13.6521C17.5 14.6767 17.0882 15.6064 16.4226 16.2827C15.7431 16.9729 14.7961 17.4021 13.75 17.4021C11.6789 17.4021 10 15.7232 10 13.6521C10 12.6263 10.4127 11.6957 11.0797 11.0192Z"
+                fill="black"
+                fill-opacity="0.6"
+              />
+            </svg>
+			</div>
+		</div>
 		<div class="dp_inputArea">
 			<div class="dp_ia_bottom">
 				<div class="dp_ia_b_left">
@@ -44,6 +88,7 @@
 					</div>
 				</div>
 				<div class="dp_ia_b_right">
+					<!-- 清空聊天记录按钮 -->
 					<div
 						class="dp_ia_b_r_btn"
 						v-if="!sendMessageLoading"
@@ -108,6 +153,7 @@ import { ref, reactive, onMounted, computed } from 'vue'
 import { fetchEventSource } from '@microsoft/fetch-event-source'
 import MarkdownIt from 'markdown-it'
 import api from '../../../services/course'
+import message from '@/utils/message'
 
 
 
@@ -162,6 +208,9 @@ const curRequestController = ref<AbortController | null>(null)
 // 用户名称
 const userName = ref<string>('')
 
+// 清空聊天记录loading
+const agentData = ref<any>({})
+
 const htmlContent = computed(() => {
   const md = new MarkdownIt()
   return (_md:string) => {
@@ -288,7 +337,7 @@ const insertChat = async (uid: string) => {
       userName: userName.value
         ? userName.value
         : await getUserName(props.userid),
-      groupId: `602def61-005d-11ee-91d8-005056b8q12w`,
+      groupId: `${props.courseid?.slice(0, 31)}${props.userid?.slice(0, 5)}`,
       answer: _msg.aiContent,
       problem: _msg.userContent,
       file_id: '',
@@ -320,7 +369,7 @@ const getMessageList = () => {
     dialogueLoading.value = true
     const params = {
       userid: props.userid,
-      groupid: `602def61-005d-11ee-91d8-005056b8q12w`,
+      groupid: `${props.courseid?.slice(0, 31)}${props.userid?.slice(0, 5)}`,
       session_name: `${props.userid}_${props.courseid}_pptCourse`,
     }
     api.getChatList(params).then((res: any) => {
@@ -346,9 +395,74 @@ const getMessageList = () => {
   }
 }
 
+// 清空聊天记录
+const clearChatHistory = async () => {
+  if (dialogueLoading.value) return
+  console.log(agentData.value)
+    
+  // 确认对话框
+  if (!confirm('确定要清空所有聊天记录吗?此操作不可恢复。')) {
+    return
+  }
+  
+  dialogueLoading.value = true
+  
+  try {
+    const params = {
+      model: 'open-gpt-4.1',
+      thread_id: agentData.value.thread_id,
+      groupid: `${props.courseid?.slice(0, 31)}${props.userid?.slice(0, 5)}`,
+      userid: props.userid
+    }
+    
+    const response = await api.clearDialogue(params)
+    
+    if (response) {
+      // 清空本地消息列表,只保留初始欢迎消息
+      messageList.splice(1) // 保留第一个欢迎消息
+      
+      // 重置消息列表为初始状态
+      messageList[0] = {
+        id: '1',
+        userContent: '',
+        aiContent: '你好!我是你的学习助手,有什么可以帮助你的吗?',
+        createTime: new Date().toLocaleString().replace(/\//g, '-'),
+        userName: '老师',
+        aiName: 'AI助手',
+        loading: false,
+      }
+      
+      console.log('聊天记录清空成功')
+      message.success('聊天记录已清空')
+    }
+    else {
+      throw new Error(`HTTP error! status: ${response.status}`)
+    }
+  }
+  catch (error) {
+    console.error('清空聊天记录失败:', error)
+    message.error('清空聊天记录失败,请重试')
+  }
+  finally {
+    dialogueLoading.value = false
+  }
+}
+
+const getAgentData = () => {
+  dialogueLoading.value = true
+  api.getAgentData({
+    id: '978252d7-a26e-4e70-8d75-3336497abac1',
+  }).then((res: any) => {
+    console.log(res)
+    agentData.value = {source: 'agent', ...res}
+    getMessageList()
+  })
+}
+
 onMounted(() => {
   getUserName(props.userid)
-  getMessageList()
+  
+  getAgentData()
 })
 
 </script>
@@ -362,7 +476,7 @@ onMounted(() => {
   position: relative;
 	.dp_messageList {
 		width: 100%;
-		height: calc(100% - 60px - 10px);
+		height: calc(100% - 60px - 40px - 10px); // 减去输入框和清空按钮的高度
     overflow: auto;
 		.dp_ml_item{
       width: 100%;
@@ -511,4 +625,74 @@ onMounted(() => {
     z-index: 1000;
   }
 }
-</style>
+
+// 清空按钮区域样式
+.dp_clearArea {
+    width: 100%;
+    height: 40px;
+    display: flex;
+    align-items: center;
+    justify-content: flex-start;
+    padding: 0;
+    border-bottom: 1px solid #f0f0f0;
+    
+    .dp_clear_btn {
+        display: flex;
+        align-items: center;
+        gap: 8px;
+        padding: 5px;
+        border: .5px solid #e0eafb;
+        border-radius: 6px;
+        background-color: #fff;
+        color: #fff;
+        cursor: pointer;
+        transition: all 0.3s ease;
+        font-size: 14px;
+        
+        &:hover {
+            transform: translateY(-1px);
+        }
+        
+        .icon {
+            width: 20px;
+            height: 20px;
+            flex-shrink: 0;
+        }
+        
+        .loading-icon {
+            animation: spin 1s linear infinite;
+        }
+        
+        .clear-text {
+            font-weight: 500;
+            white-space: nowrap;
+        }
+    }
+}
+
+// 清空按钮样式
+.clear-btn {
+  margin-right: 8px;
+  background-color: #fff;
+  border: 1px solid #ff4d4f;
+  transition: all 0.3s ease;
+  
+  &:hover {
+    background-color: #ff4d4f;
+    transform: scale(1.05);
+    
+    .icon {
+      fill: #fff;
+    }
+  }
+  
+  .loading-icon {
+    animation: spin 1s linear infinite;
+  }
+}
+
+@keyframes spin {
+  0% { transform: rotate(0deg); }
+  100% { transform: rotate(360deg); }
+}
+</style>