Forráskód Böngészése

update exam module

reghao 1 éve
szülő
commit
749544ee95
3 módosított fájl, 75 hozzáadás és 51 törlés
  1. 1 1
      src/api/exam.js
  2. 32 5
      src/views/exam/ExamCard.vue
  3. 42 45
      src/views/exam/ExamResult.vue

+ 1 - 1
src/api/exam.js

@@ -7,7 +7,7 @@ const examApi = {
   getExamQuestion1: '/api/content/exam/question/1',
   getExamQuestionType: '/api/content/exam/question/type',
   postExamQuestion: '/api/content/exam/question',
-  postExamPaper: '/api/content/exam/paper/submit',
+  postExamPaper: '/api/content/exam/paper/submit1',
   getExamPapers: '/api/content/exam/start',
   getExamResult: '/api/content/exam/result',
   getExamPaperScore: '/api/content/exam/paper/score',

+ 32 - 5
src/views/exam/ExamCard.vue

@@ -491,8 +491,6 @@ export default {
     },
     // 点击展示高清大图
     showBigImg(url) {
-      console.log('show big')
-      console.log(url)
       this.bigImgUrl = url
       this.bigImgDialog = true
     },
@@ -598,7 +596,6 @@ export default {
     // ****************************************************************************************************************
     // 上传用户考试信息进入后台
     async uploadExamToAdmin() {
-      console.log(this.userAnswer)
       if (this.cameraOn) await this.takePhoto()// 结束的时候拍照上传一张
       // 正则
       var reg = new RegExp('-', 'g')
@@ -656,6 +653,28 @@ export default {
         msg = '考试时间结束,已为您自动提交 *^▽^*'
       }
 
+      const userAnswers = []
+      console.log(this.questionList)
+      console.log(this.userAnswer)
+      this.questionList.forEach((item, index) => {
+        let answer
+        if (this.userAnswer[index] === undefined) {
+          answer = '-'
+        } else {
+          answer = this.userAnswer[index]
+        }
+        userAnswers.push({
+          pos: item.pos,
+          questionId: item.questionId,
+          answer: answer
+        })
+      })
+
+      const payload = {}
+      payload.paperId = parseInt(this.$route.params.paperId)
+      payload.answers = userAnswers
+      console.log(payload)
+
       const userPayload = {}
       userPayload.questionIds = []
       userPayload.userAnswers = this.userAnswer.join('-')
@@ -677,7 +696,7 @@ export default {
       userPayload.examId = parseInt(this.$route.params.paperId)
       userPayload.questionIds = userPayload.questionIds.join(',')
       userPayload.creditImgUrl = this.takePhotoUrl.join(',')
-      submitExamPaper(userPayload).then((resp) => {
+      submitExamPaper(payload).then((resp) => {
         if (resp.code === 0) {
           this.$notify({
             title: 'Tips',
@@ -685,8 +704,16 @@ export default {
             type: 'success',
             duration: 2000
           })
-          this.$router.push('/exam/result/' + resp.data)
+          const resultId = resp.data
+          this.$router.push('/exam/result/' + resultId)
         }
+      }).catch(error => {
+        this.$notify({
+          title: '提示',
+          message: error.message,
+          type: 'error',
+          duration: 3000
+        })
       })
     }
   }

+ 42 - 45
src/views/exam/ExamResult.vue

@@ -2,23 +2,19 @@
   <el-container>
     <el-header height="150">
       <el-card style="height: 150px">
-        <span class="examName">{{ examInfo.examName }}</span>
+        <span class="examName">{{ examRecord.examName }}</span>
         <span class="examTime">{{ examRecord.examTime }}</span>
-
         <el-row style="margin-top: 55px;">
-          <el-tooltip class="item" effect="dark" content="包括(单选,多选,判断题)" placement="top-start">
+          <el-tooltip class="item" effect="dark" content="包括选择题和判断题" placement="top-start">
             <span style="font-weight: 800;font-size: 17px">
-              逻辑题得分: {{ examRecord.logicScore }}分</span>
+              客观题得分: {{ examRecord.logicScore }}分</span>
           </el-tooltip>
-
           <el-tooltip class="item" effect="dark" content="简答题与逻辑题" placement="top-start">
             <span style="float: right;font-weight: 800;font-size: 17px">
-              总分: {{ examInfo.totalScore }}分</span>
+              试卷总分: {{ examRecord.totalScore }}分</span>
           </el-tooltip>
         </el-row>
-
       </el-card>
-
     </el-header>
 
     <el-main>
@@ -29,11 +25,15 @@
             <i class="num">{{ index + 1 }}</i>
             <span v-if="item.questionType === 1">【单选题】</span>
             <span v-else-if="item.questionType === 2">【多选题】</span>
-            <span v-else-if="item.questionType === 3">【判断题】</span>
-            <span v-else>【简答题】</span>
+            <span v-else-if="item.questionType === 3">【不定项选择题】</span>
+            <span v-else-if="item.questionType === 4">【判断题】</span>
+            <span v-else-if="item.questionType === 5">【填空题】</span>
+            <span v-else-if="item.questionType === 6">【问答题】</span>
+            <span v-else-if="item.questionType === 7">【理解题】</span>
+            <span v-else>【综合题】</span>
             <span>{{ item.questionContent }}:</span>
             <span style="color: red;font-style: italic;font-weight: 400;">&nbsp;{{
-              questionScore.get(String(item.questionId))
+              item.score
             }}分</span>
           </div>
           <!--题目中的配图-->
@@ -46,9 +46,9 @@
             @click="showBigImg(url)"
           >
 
-          <!--单选 和 判断 的答案列表-->
+          <!-- 单选和判断题候选答案列表 -->
           <div
-            v-show="item.questionType === 1 || item.questionType === 3"
+            v-show="item.questionType === 1 || item.questionType === 4"
             style="margin-top: 25px"
           >
             <div class="el-radio-group">
@@ -73,8 +73,11 @@
             </div>
           </div>
 
-          <!--多选的答案列表-->
-          <div v-show="item.questionType === 2" style="margin-top: 25px">
+          <!-- 多选和不定项选择题的候选答案列表 -->
+          <div
+            v-show="item.questionType === 2 || item.questionType === 3"
+            style="margin-top: 25px"
+          >
             <div class="el-radio-group">
               <label
                 v-for="(i2,index2) in item.answer"
@@ -97,16 +100,17 @@
             </div>
           </div>
 
-          <!--简答题的答案-->
-          <div v-show="item.questionType === 4" style="margin-top: 25px">
+          <!-- 填空题和问答题的回答区 -->
+          <div
+            v-show="item.questionType === 5 || item.questionType === 6"
+            style="margin-top: 25px"
+          >
             <div class="ques-analysis">
               <h3 style="font-weight: 400">我的回答:</h3>
               <p style="font-weight: 400;color: orange"> {{ userAnswer[index] }} </p>
             </div>
           </div>
-
         </div>
-
       </el-card>
     </el-main>
 
@@ -118,7 +122,7 @@
 </template>
 
 <script>
-import { getExamInfoById, getExamPaperScore, getExamResult, getQuestionByIds } from '@/api/exam'
+import { getExamResult, getQuestionByIds, getQuestionByPaperId } from '@/api/exam'
 
 export default {
   name: 'ExamResult',
@@ -148,12 +152,12 @@ export default {
     document.title = '考试结果'
     this.getExamRecord()
     // 页面数据加载的等待状态栏
-    /* this.loading = this.$Loading.service({
+    this.loading = this.$loading({
       body: true,
       lock: true,
       text: '数据拼命加载中,(*╹▽╹*)',
       spinner: 'el-icon-loading'
-    })*/
+    })
   },
   methods: {
     // 查询用户当时考试的信息
@@ -162,23 +166,15 @@ export default {
       await getExamResult(examId).then((resp) => {
         if (resp.code === 0) {
           this.examRecord = resp.data
-          this.getExamInfoById(resp.data.examId)
-          this.userAnswer = resp.data.userAnswers.split('-')
-          // 获取单题的分值
-          this.getQuestionScore(resp.data.examId)
-          // 获取所有题目信息
-          this.getQuestionInfoByIds(resp.data.questionIds)
+          // this.userAnswer = resp.data.userAnswers.split('-')
+          this.userAnswer = resp.data.userAnswers.split(',')
+          const paperId = resp.data.examId
+          this.getPaperQuestions(paperId)
           // 数据加载完毕
-          // this.loading.close()
+          this.loading.close()
         }
       })
     },
-    // 根据考试id查询考试信息
-    getExamInfoById(examId) {
-      getExamInfoById(examId).then((resp) => {
-        if (resp.code === 0) this.examInfo = resp.data
-      })
-    },
     // 根据ids查询题目信息
     async getQuestionInfoByIds(questionIds) {
       await getQuestionByIds({ ids: questionIds }).then((resp) => {
@@ -191,6 +187,17 @@ export default {
         }
       })
     },
+    async getPaperQuestions(paperId) {
+      await getQuestionByPaperId(paperId).then((resp) => {
+        if (resp.code === 0) {
+          this.questionInfo = resp.data || []
+          // 重置问题的顺序 单选 多选 判断 简答
+          this.questionInfo = this.questionInfo.sort(function(a, b) {
+            return a.questionType - b.questionType
+          })
+        }
+      })
+    },
     // 点击展示高清大图
     showBigImg(url) {
       this.bigImgUrl = url
@@ -198,16 +205,6 @@ export default {
     },
     // 根据考试id查询考试中每一题的分数
     async getQuestionScore(examId) {
-      await getExamPaperScore(examId).then((resp) => {
-        if (resp.code === 0) {
-          // 设置单题分值给map
-          const scores = resp.data.scores.split(',')
-          resp.data.questionIds.split(',').forEach((item, index) => {
-            // this.$set(this.questionScore, item, scores[index])
-            this.questionScore.set(item, scores[index])
-          })
-        }
-      })
     }
   }
 }