Переглянути джерело

feat: 新增操作记录接口并记录幻灯片操作耗时和AI聊天记录

新增addPPTOp2接口用于记录操作记录,在学生端作业提交时记录进入作业页面的耗时,在AI聊天时记录聊天内容
lsc 1 тиждень тому
батько
коміт
2cea645d3f

+ 12 - 0
src/services/course.ts

@@ -243,6 +243,17 @@ export const addPPTOp = (params: any): Promise<any> => {
   return axios.post(`${API_URL}addPPTOp`, [params])
 }
 
+/**
+ * 
+ * 新增操作记录
+ * @param any id VARCHAR(3000),userid VARCHAR(36), type VARCHAR(36), `index` INT, `json` LONGTEXT
+ * @returns Promise<any>
+ */
+
+export const addPPTOp2 = (params: any): Promise<any> => {
+  return axios.post(`${API_URL}addPPTOp2`, [params])
+}
+
 
 export default {
   getCourseDetail,
@@ -266,5 +277,6 @@ export default {
   getClassById,
   selectPPTOp,
   addPPTOp,
+  addPPTOp2,
 }
 

+ 17 - 3
src/views/Student/components/aiChat.vue

@@ -3,7 +3,7 @@
     <div class="fullscreen-spin mask2" v-if="agentlistloading">
       <div class="spin">
         <div class="spinner"></div>
-        <div class="text">加载中...</div>
+        <div class="text">loading...</div>
       </div>
     </div>
     <!-- 弹窗头部 -->
@@ -117,7 +117,7 @@ import { chat_no_stream, chat_stream, getAgentModel, chat_no_stream2, getAgentCh
 import { useSlidesStore } from '@/store'
 import { lang } from '@/main'
 import MarkdownIt from 'markdown-it'
-import { getWorkPageId, getClassById } from '@/services/course'
+import { getWorkPageId, getClassById, addPPTOp2 } from '@/services/course'
 import FileInput from '@/components/FileInput2.vue'
 import axios from '@/services/config'
 import message from '@/utils/message'
@@ -172,12 +172,14 @@ const props = withDefaults(defineProps<{
   workJson?: any
   visible?: boolean
   cid?: string | null
+  courseid?: string | null
 }>(), {
   userid: null,
   position: () => ({ x: 0, y: 0 }),
   workJson: () => ({}),
   visible: false,
-  cid: null
+  cid: null,
+  courseid: null
 })
 
 const emit = defineEmits(['close'])
@@ -310,6 +312,16 @@ const sendMessage = () => {
   if (chatLoading.value) {
     return
   }
+
+  addPPTOp2({
+    id: props.courseid,
+    userid: props.userid || '',
+    type: '2',
+    index: currentSlide.value.id, // 获取当前ppt页面的id
+    data: inputText.value
+  }).then(res => {
+    console.log('res', res)
+  })
   // 检查是否有文件正在处理中
   const hasProcessingFile = files.value.some(file => file.isProcessing)
   if (hasProcessingFile) {
@@ -592,6 +604,8 @@ const addChat = () => {
 
 import useCreateElement from '@/hooks/useCreateElement'
 import useSlideHandler from '@/hooks/useSlideHandler'
+import { storeToRefs } from 'pinia'
+const { slides, slideIndex, currentSlide, viewportSize, viewportRatio } = storeToRefs(slidesStore)
 const { createSlide } = useSlideHandler()
 const { createFrameElement } = useCreateElement()
 

+ 18 - 1
src/views/Student/index.vue

@@ -93,7 +93,7 @@
             <IconComment class="aiBtn-icon" />
             <span>{{ lang.ssAiChat }}</span>
           </div>
-          <aiChat v-show="visibleAIChat" :position="aiBtnPosition" @close="visibleAIChat = false" :userid="props.userid" :workJson="myWork" :visible="visibleAIChat" :cid="props.cid"/>
+          <aiChat v-show="visibleAIChat" :position="aiBtnPosition" @close="visibleAIChat = false" :userid="props.userid" :workJson="myWork" :visible="visibleAIChat" :cid="props.cid" :courseid="props.courseid"/>
          <!--  -->
           <div class="viewport" v-if="false">
             <div class="background" :style="backgroundStyle"></div>
@@ -573,6 +573,8 @@ const timerInterval = ref<number | null>(null)
 
 // 作业提交状态
 const isSubmitting = ref(false)
+// 进入当前幻灯片(作业页)的时间戳,用于计算作业提交耗时(秒)
+const slideEnterTime = ref(0)
 
 // 控制组件显示的开关
 const showSlideList = ref(true)
@@ -1198,6 +1200,10 @@ watch(() => slideIndex.value, () => {
 
 // 监听 currentSlide 变化,确保刷新后能获取到画图状态
 watch(() => currentSlide.value?.id, (newSlideId, oldSlideId) => {
+  // 记录进入当前幻灯片的时间戳(immediate 保证刷新后 slides 加载完成也能记录)
+  if (newSlideId && newSlideId !== oldSlideId) {
+    slideEnterTime.value = Date.now()
+  }
   // 只在学生端且跟随模式下检查
   if (props.type == '2' && isFollowModeActive.value && yWritingBoardState.value && newSlideId) {
     const snap = yWritingBoardState.value.toJSON()
@@ -2518,6 +2524,17 @@ const handleHomeworkSubmit = async () => {
     if (!hasSubmitWork) {
       message.info(lang.ssHwNoFunc)
     }
+    else {
+      api.addPPTOp2({
+        id: props.courseid,
+        userid: props.userid || '',
+        type: '3',
+        index: currentSlide.value.id, // 获取当前ppt页面的id
+        data: String(Math.max(0, Math.round((Date.now() - slideEnterTime.value) / 1000))), // 进入作业页面到提交的耗时(秒)
+      }).then(res => {
+        console.log('res', res)
+      })
+    }
     isSubmitting.value = false
 
   }