Browse Source

客观判题接口更新

ChengYuXuan 5 năm trước cách đây
mục cha
commit
2ac9a5eca8

+ 6 - 9
src/api/judge.ts

@@ -1,13 +1,10 @@
 import axios from 'axios'
 import { JUDGE_MODULE } from '@/api/prefix'
-import { ReceivedData } from '@/api/types'
+import { ID, ReceivedData } from '@/api/types'
 
-export const objectiveJudge = (
-  answers: Array<string>,
-  questionsIds: Array<string>
-) => {
-  return axios.post<ReceivedData>(`${JUDGE_MODULE}/objective`, {
-    answers,
-    questionsIds
-  })
+export const objectiveJudge = (examId: ID, records: object) => {
+  return axios.post<ReceivedData>(
+    `${JUDGE_MODULE}/objective?examId=${examId}`,
+    { records: records }
+  )
 }

+ 6 - 0
src/api/types.d.ts

@@ -141,3 +141,9 @@ export interface UserSerializer {
 }
 
 export type QuestionAndScore = Map<string, number>
+
+export interface Record {
+  answer: string
+  endAt: LocalDateTime
+  startAt: LocalDateTime
+}

+ 1 - 1
src/mock/api/exam/post.json

@@ -1,5 +1,5 @@
 {
   "code": "00000",
-  "result": "ok",
+  "result": "@EXAM_SERIALIZER",
   "msg": ""
 }

+ 0 - 0
src/mock/api/exam/questions/sample/_examId/post.json → src/mock/api/exam/question/sample/_examId/post.json


+ 1 - 11
src/router/exam.ts

@@ -17,17 +17,7 @@ const routes: Array<RouteConfig> = [
         path: 'exam-pane',
         name: 'exam-pane',
         component: () =>
-          import(/* webpackChunkName: "exam" */ '@/views/exam/ExamPane.vue'),
-        children: [
-          {
-            path: 'choice',
-            name: 'choice'
-          },
-          {
-            path: 'code',
-            name: 'code'
-          }
-        ]
+          import(/* webpackChunkName: "exam" */ '@/views/exam/ExamPane.vue')
       }
     ]
   }

+ 33 - 21
src/views/exam/ExamPane.vue

@@ -184,6 +184,9 @@
       <v-snackbar v-model="examAvailableDialog" centered absolute color="error">
         评测不可用
       </v-snackbar>
+      <v-snackbar v-model="submittedError" absolute>
+        提交失败,请重试
+      </v-snackbar>
     </v-main>
   </div>
 </template>
@@ -199,7 +202,10 @@ import {
   ExamSerializer,
   CodeQuestionSerializer,
   QuestionStemSerializer,
-  QuestionType
+  QuestionType,
+  Record,
+  LocalDateTime,
+  ID
 } from '@/api/types'
 import { getExamById, getExamQuestions } from '@/api/exam'
 import { getQuestionStem } from '@/api/question'
@@ -220,7 +226,7 @@ export default Vue.extend({
       fetchingStem: true,
       exitDialog: false,
       submitDialog: false,
-      submitted: false,
+      submittedError: false,
       currentTime: 0,
       examInfo: (null as unknown) as ExamSerializer,
       endTime: 0,
@@ -228,9 +234,9 @@ export default Vue.extend({
 
       currentQuestion: (null as unknown) as QuestionStemSerializer,
       currentQuestionIndex: -1,
-      objectiveAnswers: [] as Array<string>,
+      objectiveAnswers: {} as Map<ID, Record>,
       questionIds: [] as Array<string>,
-
+      questionStartTime: dayjs().format(TIME_FORMAT) as LocalDateTime,
       examId: 0,
       // codeQuestions: [] as Array<CodeQuestionSerializer>,
       // codeIndex: -1
@@ -288,8 +294,12 @@ export default Vue.extend({
     //   changedCodeTuple.code = code
     // },
     saveObjectiveAnswer(answer: string) {
-      this.objectiveAnswers[this.currentQuestionIndex] = answer
-      console.log(answer)
+      let questionEndTime = dayjs().format(TIME_FORMAT)
+      this.objectiveAnswers.set(this.questionIds[this.currentQuestionIndex], {
+        answer,
+        startAt: this.questionStartTime,
+        endAt: questionEndTime
+      })
     },
     leaveExam() {
       this.exitDialog = false
@@ -302,7 +312,14 @@ export default Vue.extend({
       console.log(this.objectiveAnswers)
       console.log(this.questionIds)
 
-      objectiveJudge(this.objectiveAnswers, this.questionIds)
+      let mapObj = Object.create(null)
+      for (let [k, v] of this.objectiveAnswers) {
+        if (v.answer) {
+          mapObj[k] = v
+        }
+      }
+
+      objectiveJudge(this.examId, mapObj)
         .then(() => {
           setTimeout(() => {
             this.$router.push({
@@ -314,23 +331,19 @@ export default Vue.extend({
           }, 1000)
         })
         .catch(() => {
-          objectiveJudge(this.objectiveAnswers, this.questionIds).then(() => {
-            setTimeout(() => {
-              this.$router.push({
-                name: 'result',
-                params: {
-                  examId: this.examId.toString()
-                }
-              })
-            }, 1000)
-          })
+          this.submittedError = true
         })
-        .catch(() => {})
     },
     nextQuestion() {
       if (this.currentQuestionIndex < this.totalQuestionNum - 1) {
-        if (this.objectiveAnswers[this.currentQuestionIndex] === '') {
+        if (
+          !this.objectiveAnswers.get(
+            this.questionIds[this.currentQuestionIndex]
+          )
+        ) {
+          //TODO 提示未答题?
         }
+        this.questionStartTime = dayjs().format(TIME_FORMAT)
 
         this.currentQuestionIndex++
         this.fetchQuestionStem(this.currentQuestionIndex)
@@ -362,8 +375,7 @@ export default Vue.extend({
         this.currentQuestionIndex = 0
         this.fetchQuestionStem(0)
 
-        this.objectiveAnswers = Array(this.objectiveQuestionNum)
-        this.objectiveAnswers.fill('')
+        this.objectiveAnswers = new Map<ID, Record>()
       })
     }
   },