ソースを参照

代码题完善

ChengYuXuan 5 年 前
コミット
c56054af84

+ 1 - 1
src/api/record.ts

@@ -2,7 +2,7 @@ import axios from 'axios'
 import { RECORD_MODULE } from '@/api/prefix'
 import { ExamQuestionSubmitRecord, ID, ReceivedData } from '@/api/types'
 
-const getExamQuestionSubmitRecord = (examId: ID, questionId: ID) => {
+export const getExamQuestionSubmitRecord = (examId: ID, questionId: ID) => {
   return axios.get<ReceivedData<Array<ExamQuestionSubmitRecord>>>(
     `${RECORD_MODULE}?examId=${examId}&questionId=${questionId}`
   )

+ 39 - 15
src/views/exam/components/CodePane.vue

@@ -114,8 +114,9 @@
           <v-btn
             color="primary"
             class="mx-2 mb-2 align-self-center"
-            small
             v-on:click="submitCode"
+            :disabled="running"
+            :loading="running"
             >保存测试</v-btn
           >
         </div>
@@ -125,6 +126,9 @@
         ></code-editor>
       </div>
     </div>
+    <v-snackbar v-model="error" top color="warning" absolute
+      >提交失败</v-snackbar
+    >
   </v-card>
 </template>
 
@@ -137,9 +141,11 @@ import {
   CodeQuestionSerializer,
   CodeSubmitSerializer,
   CodeTuple,
+  ExamQuestionSubmitRecord,
   ID
 } from '@/api/types'
 import { codeJudge } from '@/api/judge'
+import { getExamQuestionSubmitRecord } from '@/api/record'
 
 interface CodeJudgeInfo extends CodeJudgeResult {
   id: ID
@@ -155,10 +161,6 @@ export default Vue.extend({
     question: {
       required: true,
       type: Object as PropType<CodeQuestionSerializer>
-    },
-    totalQuestionNum: {
-      required: true,
-      type: Number
     }
   },
   data() {
@@ -170,15 +172,25 @@ export default Vue.extend({
       currentLang: '',
       currentCode: '',
       codeCache: [] as CodeTuple[], // 切换语言时,将当前编辑的保存到cache中,下次切换回来可继续编辑
+      submitRecords: [] as ExamQuestionSubmitRecord[],
       statusTags: [
         'Accepted',
         'Wrong Answer',
         'Compile Error',
         'Time Limit Exceeded',
-        'Memory Limit Exceeded'
+        'Memory Limit Exceeded',
+        'Running'
+      ],
+      statusColors: [
+        'success',
+        'error',
+        'warning',
+        'warning',
+        'warning',
+        'info'
       ],
-      statusColors: ['success', 'error', 'warning', 'warning', 'warning']
-      // lastCommitCode: [] as CodeSubmitSerializer[]
+      running: false,
+      error: false
     }
   },
   watch: {
@@ -208,9 +220,13 @@ export default Vue.extend({
       return { lang: val, code: '' }
     })
 
-    this.codeJudgeResults = [
-      { id: 1, result: 'Accepted', timeused: 123, memoryused: 12345 }
-    ]
+    const examId = this.$route.params.examId
+    getExamQuestionSubmitRecord(examId, this.question.id).then(({ data }) => {
+      this.submitRecords = data.result
+    })
+    // this.codeJudgeResults = [
+    //   { id: 1, result: 'Accepted', timeused: 123, memoryused: 12345 }
+    // ]
   },
   methods: {
     submitCode(): void {
@@ -220,11 +236,19 @@ export default Vue.extend({
         code: this.currentCode,
         language: this.currentLang
       }
-      codeJudge(examId, this.question.id, codeToSubmit).then(({ data }) => {
-        this.codeJudgeResults = data.result.result_list.map((val, index) => {
-          return { ...val, id: index + 1 }
+      this.running = true
+      codeJudge(examId, this.question.id, codeToSubmit)
+        .then(({ data }) => {
+          this.codeJudgeResults = data.result.result_list.map((val, index) => {
+            return { ...val, id: index + 1 }
+          })
+        })
+        .catch(() => {
+          this.error = true
+        })
+        .finally(() => {
+          this.running = false
         })
-      })
     },
     statusToColor(status: string): string {
       return this.statusColors[this.statusTags.indexOf(status)]

+ 10 - 6
src/views/teacher/TeacherExamDetail.vue

@@ -13,7 +13,7 @@
       </template>
     </page-header>
     <v-container>
-      <v-expansion-panels :value="[0]" multiple>
+      <v-expansion-panels :value="[0, 1, 2]" multiple>
         <v-expansion-panel>
           <v-expansion-panel-header>
             <div class="text-center display-1">评测信息</div>
@@ -213,12 +213,16 @@ export default Vue.extend({
           questionsPromises[ind] = getQuestionInfo(v[0])
         })
 
-        Promise.all(questionsPromises).then((reps) => {
-          this.examQuestions = reps.map((value) => {
-            return value.data.result
+        Promise.all(questionsPromises)
+          .then((reps) => {
+            this.examQuestions = reps.map((value) => {
+              return value.data.result
+            })
+          })
+          .catch()
+          .finally(() => {
+            this.fetching = false
           })
-          this.fetching = false
-        })
       })
       .catch(() => {
         this.$router.push({