فهرست منبع

解决AI历史对话顺序、起止时间不符合逻辑

XiaoYu 1 سال پیش
والد
کامیت
6c46ba558f

+ 5 - 0
src/apis/assignment.ts

@@ -39,7 +39,12 @@ const assignmentApis = {
                 assignmentId
             }
         })
+    },
+    deleteById(teacherId:number, assignmentId:number){
+        return axiosInstance.delete(`${ASSIGNMENT_PREFIX}/byTeacher/${teacherId}/${assignmentId}`)
+
     }
+
 }
 
 export default assignmentApis

+ 3 - 2
src/components/AIChatter/AIChatter.vue

@@ -27,7 +27,7 @@
     <!-- 消息区域,采用ChatGPT的交互模式 -->
     <div :class="$style['message-box']" ref="containerTopRef">
       <div
-          v-for="(item, index) in data.messages"
+          v-for="(item, index) in data.messages.slice().reverse()"
           :key="index"
           :class="$style.item"
       >
@@ -193,11 +193,12 @@
     });
   });
 
+  //  BUG: 按这套逻辑显示的名字可能与内容对不上 
   const handleSendQuestion = () => {
     data.loading = true;
 
     let requestBody:IDialogue[] = data.messages
-    requestBody.push({
+    requestBody.unshift({
       role: 'user',
       content: data.questionContent
     })

+ 5 - 0
src/views/CoursePage/CoursePage.vue

@@ -240,6 +240,11 @@
   const handleSubmit = () => {
     newCourse.endTime = formatDate(newCourse.endTime)
     newCourse.startTime = formatDate(newCourse.startTime)
+    if(new Date(newCourse.endTime) < new Date(newCourse.startTime)){
+      ElMessage.error('截止时间不能早于开始时间!');
+      return;
+    }
+
     apis.createCourse(newCourse)
         .then((res:any) => {
           if(res.data.code===200) {

+ 47 - 1
src/views/CourseSquare/component/CourseDetails/component/CourseHomeworkTable.vue

@@ -137,6 +137,8 @@
       <div class="dialog-footer">
         <el-button @click="dialogConfig.visible = false; cleanNewAssignmentInfo()">取消</el-button>
         <el-button type="primary" @click="handleSubmit">确定</el-button>
+        <!-- TODO:有点问题 总是删除失败 -->
+        <!-- <el-button type="danger" @click="confirmDelete()">删除作业</el-button> -->
       </div>
     </template>
   </el-dialog>
@@ -153,6 +155,7 @@ import {defineProps, inject, onMounted, reactive, ref} from 'vue';
   import {
   ElMessage,
   ElNotification,
+  ElMessageBox,
   type UploadFile,
   type UploadFiles,
   type UploadProps,
@@ -162,6 +165,7 @@ import {defineProps, inject, onMounted, reactive, ref} from 'vue';
   import ViewsWordEditor from "@/components/ViewsWordEditor/ViewsWordEditor.vue";
   import {useStore} from "@/store";
   import {Search, Edit, UploadFilled, Plus} from "@element-plus/icons-vue"
+import { userInfo } from 'os';
 
   const props = defineProps<{
     tableData: IAssignmentTableItem[],
@@ -423,7 +427,9 @@ const openEditor = (url: string, title: string) => {
               ElNotification({
                 title: '新增成功',
                 type: 'success',
-              })
+              });
+              //TODO: 新建作业后自动刷新页面 但是怎么跳转回作业列表页面?
+              location.reload();
             }else {
               ElNotification({
                 title: '新增失败',
@@ -464,6 +470,46 @@ const openEditor = (url: string, title: string) => {
     }
     doRefresh();
   }
+//传teacherId:number, assignmentId:number
+  const confirmDelete = () => {
+    ElMessageBox.confirm('确定要删除这个作业吗?', '警告', {
+      confirmButtonText: '确定',
+      cancelButtonText: '取消',
+      type: 'warning'
+    }).then(() => {
+      deleteAssignment();
+    }).catch(() => {
+      // 用户选择取消,什么都不做
+    });
+  };
+
+  const deleteAssignment = () => {
+    //TODO:teacherId,assignmentId
+    apis.deleteById(store.user.id,IAssignmentId.value)
+    
+      .then((res: any) => {
+        if (res.data.code === 200) {
+          ElMessage({
+            type: 'success',
+            message: '删除成功!'
+          });
+          // 这里可以调用刷新数据的方法
+          doRefresh();
+        } else {
+          ElMessage({
+            type: 'error',
+            message: '删除失败!'+res.data.message
+          });
+        }
+      })
+      .catch((err) => {
+        console.log(err);
+        ElMessage({
+          type: 'error',
+          message: '请求出错!'
+        });
+      });
+  };
 
   const isDisabled = (teacherId: string, endDate: string) => {
     if(props.role == 'teachers'){// 是教师且不是作业发布人则禁用

+ 28 - 4
src/views/CourseSquare/component/CourseDetails/index.vue

@@ -495,6 +495,11 @@ const submitForm = async (formEl: FormInstance | undefined) => {
 const handleSubmit = () => {
   newCourseInfo.endTime = formatDate(newCourseInfo.endTime)
   newCourseInfo.startTime = formatDate(newCourseInfo.startTime)
+  if(new Date(newCourseInfo.endTime) < new Date(newCourseInfo.startTime)){
+      ElMessage.error('截止时间不能早于开始时间!');
+      checkTimeAndAdjust();
+      return;
+  }
   // uploadRef.value!.submit()
   console.log(newCourseInfo)
   // TODO: 更新图片需要更新两次,不知道为什么
@@ -506,10 +511,11 @@ const handleSubmit = () => {
           type: 'success',
         })
         visible.value = false
-        apis.getCourseByCourseId(dataForm.courseId)
-            .then((res:any) => {
-              console.log(res.data.data.records[0])
-            })
+        getCourse();
+        // apis.getCourseByCourseId(dataForm.courseId)
+        //     .then((res:any) => {
+        //       console.log(res.data.data.records[0])
+        //     })
         // setTimeout(() => apis.updateCourse(dataForm.courseId, newCourseInfo), 500)
       }else {
         ElNotification({
@@ -524,6 +530,19 @@ const handleSubmit = () => {
     })
 }
 
+const checkTimeAndAdjust = () => {
+  const startTime = new Date(dataForm.startTime);
+  let endTime = new Date(dataForm.endTime);
+
+  // 检查截止时间是否早于开始时间
+  if (endTime < startTime) {
+      // 将截止时间设置为开始时间的下一天
+      endTime.setDate(startTime.getDate() + 1);
+      newCourseInfo.endTime = formatDate(endTime.toISOString()); // 更新格式
+      ElMessage.warning('先前时间逻辑有误,截止时间已自动调整为开始时间的下一天!');
+  }  
+}
+
 function isDisabled(){
   if(role == "student") return showCode.value;
   if(role == "teachers") return !showEdit.value;
@@ -534,9 +553,14 @@ onMounted(() => {
   getHomeworkList()
   if(role == 'student') isShowCode()
   if(role == 'teachers') isShowEdit()
+
+  //检查并自动调整时间逻辑
+  checkTimeAndAdjust();
 })
 
 
+
+
 </script>
 
 <style scoped>