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

feat: 课程详情页 学生登录时可查看课程下的eval和coder测试

mjh 4 лет назад
Родитель
Сommit
7bfbc72c5d
4 измененных файлов с 63 добавлено и 36 удалено
  1. 5 0
      src/api/coder.js
  2. 9 0
      src/api/eval.js
  3. 2 2
      src/store/modules/user.js
  4. 47 34
      src/views/CoursePage/CourseDetail.vue

+ 5 - 0
src/api/coder.js

@@ -26,10 +26,15 @@ function getTeacherCoderExamsByCourseId(courseId) {
   return axios.get(`${prefix}/exam/teacher/course`, {params: {courseId,}});
   return axios.get(`${prefix}/exam/teacher/course`, {params: {courseId,}});
 }
 }
 
 
+function getStudentCoderExamsByCourseId(courseId){
+  return axios.get(`${prefix}/exam/student/course`, {params: {courseId,}});
+}
+
 const coderAPIs = {
 const coderAPIs = {
   getStudentCoderExams,
   getStudentCoderExams,
   getExampleCoderExams,
   getExampleCoderExams,
   getTeacherCoderExamsByCourseId,
   getTeacherCoderExamsByCourseId,
+  getStudentCoderExamsByCourseId,
 };
 };
 
 
 export default coderAPIs;
 export default coderAPIs;

+ 9 - 0
src/api/eval.js

@@ -29,11 +29,20 @@ function getTeacherEvalExamsByCourseId(courseId) {
   });
   });
 }
 }
 
 
+function getStudentEvalExamsByCourseId(courseId){
+  return axios.get(`${prefix}/exam/student/course`, {
+    params: {
+      courseId,
+    }
+  });
+}
+
 const evalAPIs = {
 const evalAPIs = {
   getAllEvalExams,
   getAllEvalExams,
   getStudentEvalExams,
   getStudentEvalExams,
   getExampleEvalExams,
   getExampleEvalExams,
   getTeacherEvalExamsByCourseId,
   getTeacherEvalExamsByCourseId,
+  getStudentEvalExamsByCourseId,
 };
 };
 
 
 export default evalAPIs;
 export default evalAPIs;

+ 2 - 2
src/store/modules/user.js

@@ -126,10 +126,10 @@ const user = {
 
 
   getters: {
   getters: {
     isTeacher(state){
     isTeacher(state){
-      return ["TEACHER", "ADMIN"].indexOf(state.role) !== -1;
+      return ["TEACHER"].indexOf(state.role) !== -1;
     },
     },
     isStudent(state){
     isStudent(state){
-      return ["STUDENT", "SEEC"].indexOf(state.role) !== -1;
+      return ["STUDENT"].indexOf(state.role) !== -1;
     }
     }
   }
   }
 };
 };

+ 47 - 34
src/views/CoursePage/CourseDetail.vue

@@ -94,18 +94,18 @@
 
 
       <div v-if="isCreator || isCourseSelected" class="course-tab-content">
       <div v-if="isCreator || isCourseSelected" class="course-tab-content">
         <div v-if="tabName==='task'">
         <div v-if="tabName==='task'">
-<!--          <el-timeline>-->
-<!--            <el-timeline-item-->
-<!--              v-for="(task, index) in tasks"-->
-<!--              :key="index"-->
-<!--              :timestamp="task.timestamp"-->
-<!--            >-->
-<!--              {{ task.content }}-->
-<!--            </el-timeline-item>-->
-<!--          </el-timeline>-->
-          evalExamList: {{this.evalExamList}}
+          <!--          <el-timeline>-->
+          <!--            <el-timeline-item-->
+          <!--              v-for="(task, index) in tasks"-->
+          <!--              :key="index"-->
+          <!--              :timestamp="task.timestamp"-->
+          <!--            >-->
+          <!--              {{ task.content }}-->
+          <!--            </el-timeline-item>-->
+          <!--          </el-timeline>-->
+          evalExamList: {{ this.evalExamList }}
           <br/>
           <br/>
-          coderExamList: {{this.coderExamList}}
+          coderExamList: {{ this.coderExamList }}
         </div>
         </div>
         <div v-else-if="tabName==='notice'" class="tab-notice">
         <div v-else-if="tabName==='notice'" class="tab-notice">
           <NoticeItem v-for="(item,index) in announcementList" :key="index" :ref="'noticeItem'+item.id"
           <NoticeItem v-for="(item,index) in announcementList" :key="index" :ref="'noticeItem'+item.id"
@@ -420,21 +420,19 @@ export default {
               {
               {
                 courseId: this.courseInfo.id,
                 courseId: this.courseInfo.id,
                 userId: this.$store.state.user.id,
                 userId: this.$store.state.user.id,
-              }
-            )
-              .then(() => {
-                ElMessage.success("选课成功");
-                setTimeout(function () {
-                  location.reload();
-                }, 500);
               })
               })
-              .catch(err => {
-                console.log("handleSelectCourse: " + err);
-                ElMessage.error("handleSelectCourse: " + err);
+              .then((res) => {
+                if (res.data.code === -1) {
+                  ElMessage.error("选课失败");
+                  console.log(res.data.message);
+                } else {
+                  ElMessage.success("选课成功");
+                  setTimeout(function () {
+                    location.reload();
+                  }, 500);
+                }
               });
               });
           }
           }
-        })
-        .catch(() => {
         });
         });
     },
     },
     handleDropCourse() {
     handleDropCourse() {
@@ -468,17 +466,32 @@ export default {
     switchTab(tabName) {
     switchTab(tabName) {
       switch (tabName) {
       switch (tabName) {
         case "task":
         case "task":
-          if (this.courseInfo.evalId !== null) {
-            this.$apis.getTeacherEvalExamsByCourseId(this.courseInfo.evalId)
-              .then(res => {
-                this.evalExamList = res.data.data;
-              });
-          }
-          if (this.courseInfo.coderId !== null) {
-            this.$apis.getTeacherCoderExamsByCourseId(this.courseInfo.coderId)
-              .then(res => {
-                this.coderExamList = res.data.data;
-              });
+          if(this.isTeacher) {
+            if (this.courseInfo.evalId !== null) {
+              this.$apis.getTeacherEvalExamsByCourseId(this.courseInfo.evalId)
+                .then(res => {
+                  this.evalExamList = res.data.data;
+                });
+            }
+            if (this.courseInfo.coderId !== null) {
+              this.$apis.getTeacherCoderExamsByCourseId(this.courseInfo.coderId)
+                .then(res => {
+                  this.coderExamList = res.data.data;
+                });
+            }
+          }else if(this.isStudent){
+            if (this.courseInfo.evalId !== null) {
+              this.$apis.getStudentEvalExamsByCourseId(this.courseInfo.evalId)
+                .then(res => {
+                  this.evalExamList = res.data.data;
+                });
+            }
+            if (this.courseInfo.coderId !== null) {
+              this.$apis.getStudentCoderExamsByCourseId(this.courseInfo.coderId)
+                .then(res => {
+                  this.coderExamList = res.data.data;
+                });
+            }
           }
           }
           break;
           break;
         case "notice":
         case "notice":