Просмотр исходного кода

feat: 优化学生端写作作业提交和暂存功能,修改批改页面按钮布局,修改切换逻辑,完善非空评价提交处理

stupig-zcx 1 год назад
Родитель
Сommit
9dbfa615f4

+ 3 - 2
src/apis/axios.config.ts

@@ -1,9 +1,10 @@
 import axios from "axios";
 
 // const BASEURL = 'http://47.111.23.171:8081'
-// const BASEURL = 'http://localhost:8080'
+const BASEURL = 'http://localhost:8080'
 // const BASEURL = 'http://8.130.126.86:8080'
-const BASEURL = 'https://air.seec.seecoder.cn/'
+// const BASEURL = 'https://air.seec.seecoder.cn/'
+
 
 const axiosInstance = axios.create({
     baseURL: BASEURL,

+ 69 - 41
src/views/AiSpeakingPage/SpeakingRecord.vue

@@ -253,18 +253,28 @@
           </div>
           <div class="correction-actions">
             <div class="button-container">
-              <el-button 
-                style="background-color:#597D3B;color:white;width:300px" 
-                @click="submitComment" 
-                class="submit-button"
-                :loading="submitting"
-              >
-                提交评语
-              </el-button>
+              <div class="left-buttons">
+                <el-button 
+                  style="background-color:#597D3B;color:white;width:200px" 
+                  @click="submitComment" 
+                  class="submit-button"
+                  :loading="submitting"
+                >
+                  提交评语
+                </el-button>
+                
+                <el-button
+                  style="background-color:#597D3B;color:white;width:200px;margin-top:50px"
+                  @click="handleNext"
+                  :disabled="isAllCorrected"
+                >
+                  下一个
+                </el-button>
+              </div>
               
-              <!-- 批改进度数字显示 -->
+              <!-- 批改进度显示 -->
               <div class="progress-numbers">
-                {{ correctionStats.correctNumber }}/{{ correctionStats.engageNumber }}
+                已批改/未批改:{{ correctionStats.correctNumber }}/{{ uncorrectedNumber }}
               </div>
             </div>
           </div>
@@ -349,6 +359,16 @@ const progressPercentage = computed(() => {
   return Math.round((correctionStats.value.correctNumber / correctionStats.value.engageNumber) * 100);
 });
 
+// 计算未批改数量
+const uncorrectedNumber = computed(() => {
+  return correctionStats.value.engageNumber - correctionStats.value.correctNumber;
+});
+
+// 判断是否全部批改完成
+const isAllCorrected = computed(() => {
+  return uncorrectedNumber.value === 0;
+});
+
 // 获取批改进度统计
 const fetchCorrectionStats = async () => {
   try {
@@ -422,7 +442,27 @@ const createEmotionPieChart = (emotionList) => {
   window.addEventListener("resize", () => emotionChartInstance.resize());
 };
 
-// 提交评语
+// 处理下一个按钮点击
+const handleNext = async () => {
+  const nextStudentId = await getNextStudentAssignment();
+  if (nextStudentId) {
+    router.push({
+      path: `/home/assignment/${props.assignmentId}/airecord`,
+      query: {
+        userId: nextStudentId,
+        assignmentId: props.assignmentId,
+        assignmentName: props.assignmentName
+      }
+    }).then(() => {
+      window.location.reload();
+    });
+    ElMessage.success("已自动跳转到下一个学生");
+  } else {
+    ElMessage.info("没有下一个学生");
+  }
+};
+
+// 修改提交评语函数,移除跳转逻辑
 const submitComment = async () => {
   if (!engagement.value.remark || engagement.value.score === 0) {
     ElMessage.warning("请填写评语和评分");
@@ -431,7 +471,6 @@ const submitComment = async () => {
   
   submitting.value = true;
   try {
-    // 调用 API 提交评语和评分
     const response = await engagementApis.engagementCorrect(
       props.userId,
       props.assignmentId,
@@ -442,32 +481,7 @@ const submitComment = async () => {
     );
     if (response.data.code === 200) {
       ElMessage.success("评语提交成功");
-      
-      // 获取下一个学生作业ID
-      const nextStudentId = await getNextStudentAssignment();
       await fetchCorrectionStats();
-      
-      if (correctionStats.value.correctNumber === correctionStats.value.engageNumber) {
-        router.push(`/home/myCorrect/assignment/${props.assignmentId}`);
-        ElMessage.info("批改完成,已返回列表页");
-      }
-      else if (nextStudentId) {
-        // 跳转到下一个学生的作业
-        router.push({
-          path: `/home/assignment/${props.assignmentId}/airecord`,
-          query: {
-            userId: nextStudentId,
-            assignmentId: props.assignmentId,
-            assignmentName: props.assignmentName
-          }
-        });
-        ElMessage.success("已自动跳转到下一个学生");
-      } 
-      // else {
-      //   // 没有下一个学生,跳转到作业列表
-      //   router.push(`/home/myCorrect/assignment/${props.assignmentId}`);
-      //   ElMessage.info("已是最后一个学生,批改完成");
-      // }
     } else {
       ElMessage.error("评语提交失败");
     }
@@ -1204,12 +1218,26 @@ onMounted(async () => {
   flex-direction: column;
   align-items: center;
   gap: 8px;
+  width: 100%;
+}
+
+.left-buttons {
+  display: flex;
+  gap: 20px;
+  margin-bottom: 10px;
+}
+
+.left-buttons .el-button.is-disabled {
+  background-color: #a8a8a8 !important;
+  border-color: #a8a8a8 !important;
+  color: #ffffff !important;
+  cursor: not-allowed;
 }
 
 .progress-numbers {
-  font-size: 13px;
-  color: #999;
-  font-weight: 400;
-  margin-left: 0;
+  font-size: 16px;
+  color: #666;
+  font-weight: 700;
+  margin-top: 10px;
 }
 </style>

+ 0 - 4
src/views/CorrectPage/CorrectPage.vue

@@ -30,10 +30,6 @@
       <div class="my-correct-remark">
         <Remark :studentId="studentId" :assignmentId="assignmentId" />
       </div>
-
-      <div class="my-correct-goback">
-        <el-button color="#597D3B" @click="goBack">返回</el-button>
-      </div>
     </div>
   </div>
 

+ 1 - 0
src/views/CorrectPage/index.scss

@@ -4,6 +4,7 @@
     height: calc(100vh - 40px);
     display: flex;
     gap: 20px;
+    overflow: auto;
     //border: 1px solid black;
 
     .my-correct-goback{

+ 32 - 33
src/views/Home/component/Edit/index.vue

@@ -81,48 +81,47 @@
   };
 
   // 提交操作
-  const handleSubmit = () => {
-    // 内容已保存,则可以点击提交
-    if (hasStage.value == true) {
-      const endTime = dayjs(data.assignment.endTime); // 假设截止时间在 assignment 的 endTime 属性中
-      const currentTime = dayjs();
-      if (currentTime.isAfter(endTime)) {
-        ElMessage.error('作业已截止,无法提交!');
-        return;
-      }
-      hasStage.value = false
-      apis.engagementSubmit(store.user.id, props.engagement.assignmentId, )
-          .then((_res: any) => {
-            success(_res.data.data);
-            router.push("/home/myHomework")
-          })
-          .catch((error: any) => {
-            console.error('提交失败', error);
-            error('提交失败');
-          });
-    } else {
-      ElMessage.error('编辑内容未保存,请保存后提交!');
+  const handleSubmit = async () => {
+    const endTime = dayjs(data.assignment.endTime);
+    const currentTime = dayjs();
+    if (currentTime.isAfter(endTime)) {
+      ElMessage.error('作业已截止,无法提交!');
+      return;
+    }
+    
+    try {
+      // 先进行暂存操作
+      await apis.engagementStage(store.user.id, props.engagement.assignmentId, JSON.stringify(getQuillContent), getText.value, getHTML.value);
+      emitter.emit('click-stage');
+      
+      // 暂存成功后进行提交
+      hasStage.value = false;
+      const submitRes = await apis.engagementSubmit(store.user.id, props.engagement.assignmentId);
+      success(submitRes.data.data);
+      router.push("/home/myHomework");
+    } catch (error: any) {
+      console.error('操作失败', error);
+      error('操作失败,请稍后重试');
     }
   };
 
   // 暂存操作
-  const handleStage = () => {
-    const endTime = dayjs(data.assignment.endTime); // 假设截止时间在 assignment 的 endTime 属性中
+  const handleStage = async () => {
+    const endTime = dayjs(data.assignment.endTime);
     const currentTime = dayjs();
     if (currentTime.isAfter(endTime)) {
       ElMessage.error('作业已截止,无法暂存!');
       return;
     }
-    apis.engagementStage(store.user.id, props.engagement.assignmentId, JSON.stringify(getQuillContent), getText.value, getHTML.value)
-        .then((_res: any) => {
-          // 存储行为数据
-          emitter.emit('click-stage')
-          success(_res.data.data);
-        })
-        .catch((error: any) => {
-          console.error('暂存失败', error);
-          error('暂存失败');
-        });
+    
+    try {
+      await apis.engagementStage(store.user.id, props.engagement.assignmentId, JSON.stringify(getQuillContent), getText.value, getHTML.value);
+      emitter.emit('click-stage');
+      success('暂存成功');
+    } catch (error: any) {
+      console.error('暂存失败', error);
+      error('暂存失败,请稍后重试');
+    }
   };
 
   // window.onbeforeunload = function(event) {

+ 126 - 46
src/views/Home/component/Remark/Remark.vue

@@ -11,31 +11,48 @@
     </div>
 
     <div class="correction-actions">
-      <div class="button-with-progress">
-        <el-button 
-          color="#597D3B" 
-          @click="handleCorrect" 
-          v-if="!isStudent"
-          :loading="submitting"
-        >
-          提交批改
-        </el-button>
-        
-        <!-- 批改进度数字显示 -->
-        <span class="progress-numbers" v-if="!isStudent">
-          {{ correctionStats.correctNumber }}/{{ correctionStats.engageNumber }}
-        </span>
+      <div class="button-group">
+        <div class="left-buttons">
+          <el-button 
+            color="#597D3B" 
+            @click="handleCorrect" 
+            v-if="!isStudent"
+            :loading="submitting"
+          >
+            提交批改
+          </el-button>
+          
+          <el-button
+            color="#597D3B"
+            @click="handleNext"
+            v-if="!isStudent"
+            :disabled="isAllCorrected"
+          >
+            下一个
+          </el-button>
+
+          <!-- 批改进度显示 -->
+          <span class="progress-text" v-if="!isStudent">
+            已批改/未批改:{{ correctionStats.correctNumber }}/{{ uncorrectedNumber }}
+          </span>
+          
+          <!-- 批改进度条显示 -->
+          <div class="correction-progress" v-if="!isStudent">
+            <el-progress 
+              :percentage="progressPercentage" 
+              :stroke-width="6"
+              color="#597D3B"
+              class="progress-bar"
+            />
+          </div>
+
+        </div>
+
+        <div class="right-buttons">
+          <el-button color="#597D3B" @click="goBack">返回</el-button>
+        </div>
       </div>
       
-      <!-- 批改进度条显示 -->
-      <div class="correction-progress" v-if="!isStudent">
-        <el-progress 
-          :percentage="progressPercentage" 
-          :stroke-width="6"
-          color="#597D3B"
-          class="progress-bar"
-        />
-      </div>
     </div>
   </div>
 </template>
@@ -83,6 +100,16 @@ export default defineComponent({
       return Math.round((correctionStats.value.correctNumber / correctionStats.value.engageNumber) * 100);
     });
 
+    // 计算未批改数量
+    const uncorrectedNumber = computed(() => {
+      return correctionStats.value.engageNumber - correctionStats.value.correctNumber;
+    });
+
+    // 判断是否全部批改完成
+    const isAllCorrected = computed(() => {
+      return uncorrectedNumber.value === 0;
+    });
+
     // 获取批改进度统计
     const fetchCorrectionStats = async () => {
       const apis = useApis();
@@ -118,6 +145,7 @@ export default defineComponent({
     const getNextStudentAssignment = async () => {
       const apis = useApis();
       try {
+        console.log(props.assignmentId, props.studentId);
         const res = await apis.getNextStudentAssignment(props.assignmentId, props.studentId);
         if (res.data.code === 200) {
           return res.data.data;
@@ -134,6 +162,15 @@ export default defineComponent({
     });
 
     const handleCorrect = async () => {
+      console.log(correction.value.score, correction.value.remark);
+      if (!correction.value.score) {
+        ElMessage.error("请先评分");
+        return;
+      }
+      if (!correction.value.remark) {
+        ElMessage.error("请先输入评语");
+        return;
+      }
       if (isStudent.value) {
         ElMessage.error("学生不能提交批改");
         return;
@@ -145,29 +182,7 @@ export default defineComponent({
             .then(async (res) => {
               if (res.data.code === 200) {
                 ElMessage.success("批改成功");
-                
-                const nextStudentId = await getNextStudentAssignment();
                 await fetchCorrectionStats();
-
-                if (correctionStats.value.correctNumber === correctionStats.value.engageNumber) {
-                  // 如果已批改数量等于总数量,说明批改完成
-                  router.push(`/home/myCorrect/assignment/${props.assignmentId}`);
-                  ElMessage.info("批改完成,已返回列表页");
-                } 
-                else if (nextStudentId) {
-                    // 跳转到下一个学生的作业
-                    router.push({
-                      name: 'correct',
-                      params: { assignmentId: props.assignmentId },
-                      query: { studentId: nextStudentId }
-                    });
-                    ElMessage.success("已自动跳转到下一个学生");
-                  } 
-                // else {
-                //   // 没有下一个学生,跳转到作业列表
-                //   router.push(`/home/myCorrect/assignment/${props.assignmentId}`);
-                //   ElMessage.info("接收参数异常");
-                // }
               } else {
                 ElMessage.error("批改异常" + res.data.msg);
               }
@@ -181,14 +196,79 @@ export default defineComponent({
       }
     };
 
+    const handleNext = async () => {
+      if (isStudent.value) {
+        ElMessage.error("学生不能跳转到下一个学生");
+        return;
+      } else {
+        const nextStudentId = await getNextStudentAssignment();
+        if (nextStudentId) {
+          router.push({
+            name: 'correct',
+            params: { assignmentId: props.assignmentId },
+            query: { studentId: nextStudentId }
+          }).then(() => {
+            // 强制刷新页面以重新加载数据
+            window.location.reload();
+          });
+          ElMessage.success("已自动跳转到下一个学生");
+        } else {
+          ElMessage.info("没有下一个学生");
+        }
+      }
+    };
+
+    const goBack = () => {
+      router.go(-1);
+    };
+
     return {
       correction,
       handleCorrect,
+      handleNext,
       isStudent,
       submitting,
       correctionStats,
-      progressPercentage
+      progressPercentage,
+      uncorrectedNumber,
+      isAllCorrected,
+      goBack
     };
   }
 });  
 </script>
+
+<style lang="scss" scoped>
+.correction-actions {
+  margin-top: 20px;
+  
+  .button-group {
+    display: flex;
+    align-items: center;
+    justify-content: space-between;
+    margin-bottom: 10px;
+    width: 100%;
+
+    .left-buttons {
+      display: flex;
+      gap: 10px;
+    }
+
+    .progress-text {
+      color: #666;
+      font-size: 16px;
+      flex: 1;
+      text-align: center;
+    }
+
+    .right-buttons {
+      display: flex;
+      gap: 10px;
+    }
+  }
+
+  .correction-progress {
+    margin-top: 10px;
+  }
+}
+</style>

+ 8 - 6
src/views/Home/component/Remark/index.scss

@@ -69,17 +69,19 @@ textarea {
   }
 }
 
+.progress-text {
+  font-size: 14px;
+  color: #666;
+  font-weight: 700;
+  margin-top: 5px;
+  margin-left: 10px;
+}
+
 .correction-progress {
   display: flex;
   flex-direction: column;
   gap: 5px;
   
-  .progress-text {
-    font-size: 14px;
-    color: #666;
-    font-weight: 500;
-  }
-  
   .progress-bar {
     width: 200px;
   }