#41 feat: 实现行为记录版本化功能

Scalone
WuZiLong scala 1 commity/ów z FanYanPeng/feat/behavior_record_versioning do FanYanPeng/host-nju 4 miesięcy temu

+ 2 - 1
src/apis/behavior.ts

@@ -19,10 +19,11 @@ const bevaviorApis = {
             }
         })
     },
-    addBehaviorRecord: (assignmentId :number, file) => {
+    addBehaviorRecord: (assignmentId :number, file, recordType: string = 'STAGE') => {
         const formData = new FormData();
         formData.append("assignmentId", assignmentId.toString())
         formData.append('file', file);
+        formData.append('recordType', recordType);
         return axiosInstance.post(`${PREFIX}`, formData, {
             headers: {
                 'Content-Type': 'multipart/form-data'

+ 13 - 13
src/components/QuillEditor/QuillEditor.vue

@@ -39,9 +39,9 @@
   })
 
   // 点击暂存按钮时,触发行为记录保存
-  emitter.on('click-stage', () => {
-    if(changeRecordList.length > 0){
-      download()
+  emitter.on('click-stage', (payload: { isSubmit?: boolean } = {}) => {
+    if (changeRecordList.length > 0) {
+      download(payload.isSubmit ? 'SUBMIT' : 'STAGE')
       changeRecordList.length = 0
     }
   })
@@ -225,7 +225,7 @@ const isCtrlOrMeta = (event: KeyboardEvent) => event.ctrlKey === true || event.m
     emitter.emit('record-test', changeRecordList)
   }
 
-  const download = () => {
+  const download = (recordType: string = 'STAGE') => {
     // 将changeRecordList转换为JSON字符串
     const jsonData = JSON.stringify(changeRecordList)
 
@@ -236,15 +236,15 @@ const isCtrlOrMeta = (event: KeyboardEvent) => event.ctrlKey === true || event.m
 
     const filename = `行为记录.json`
     const file = new File([blob], filename, { type: blob.type })
-    if(assignmentId != null){
-      apis.addBehaviorRecord(assignmentId, file)
-          .then(res => {
-            // console.log(res.data.data)
-          })
-          .catch(err => {
-            ElMessage.error("行为记录异常,请联系老师处理!")
-            console.log(err)
-          })
+    if (assignmentId != null) {
+      apis.addBehaviorRecord(assignmentId, file, recordType)
+        .then(res => {
+          // console.log(res.data.data)
+        })
+        .catch(err => {
+          ElMessage.error("行为记录异常,请联系老师处理!")
+          console.log(err)
+        })
     }
   }
 

+ 16 - 16
src/views/Home/component/Edit/index.vue

@@ -129,8 +129,8 @@
     }
     console.log(props)
     try {
-      await handleStage();
-   } catch (e) {
+      await handleStage(true);
+    } catch (e) {
       ElMessage.error('暂存失败,无法提交!');
       return;
     }
@@ -141,22 +141,22 @@
       supplementarySubmission = true
     }
     apis.engagementSubmit(store.user.id, props.engagement.assignmentId, supplementarySubmission)
-    .then((_res: any) => {
-      success(_res.data.data);
-      emitter.emit('exam-mode-change', false);
-      emitter.emit('exam-submitted');
-      router.push("/home/myHomework").then(() => {
-        window.location.reload()
+      .then((_res: any) => {
+        success(_res.data.data);
+        emitter.emit('exam-mode-change', false);
+        emitter.emit('exam-submitted');
+        router.push("/home/myHomework").then(() => {
+          window.location.reload()
+        })
       })
-    })
-    .catch((error: any) => {
-      console.error('提交失败', error);
-      error('提交失败');
-    });
-   };
+      .catch((error: any) => {
+        console.error('提交失败', error);
+        error('提交失败');
+      });
+  };
 
   // 暂存操作
-  const handleStage = async () => {
+  const handleStage = async (isSubmit = false) => {
     if (aiEvalBusy.value || store.aiEvalBusy) {
       ElMessage.warning('智能批改进行中,请稍候再暂存')
       return
@@ -164,7 +164,7 @@
     try {
       console.log(props)
       const _res = await apis.engagementStage(store.user.id, props.engagement.assignmentId, JSON.stringify(getQuillContent), getText.value, getHTML.value);
-      emitter.emit('click-stage');
+      emitter.emit('click-stage', { isSubmit });
       emitter.emit('is-modified', false);
       // 通知 Silder 组件暂存成功,可以启用批改按钮
       emitter.emit('stage-success');