ChenYangfan 6 лет назад
Родитель
Сommit
4a3b3a312c
3 измененных файлов с 126 добавлено и 29 удалено
  1. 3 3
      src/server/question.js
  2. 123 25
      src/views/quiz/DoRecommendQuestion.vue
  3. 0 1
      src/views/quiz/StudentDoQuiz.vue

+ 3 - 3
src/server/question.js

@@ -131,7 +131,7 @@ export function getInteractiveList ({ questionIdJoinByComma }) {
 }
 
 // 取得推荐题目
-export function getRecommendationQuestions ({ knowledgeId = null, questionNum = 1 }) {
+export function getRecommendationQuestions ({ knowledgeId = '', questionNum = '1' }) {
   const params = new URLSearchParams()
   if (typeof knowledgeId !== typeof '') {
     knowledgeId.forEach(_ => {
@@ -141,10 +141,10 @@ export function getRecommendationQuestions ({ knowledgeId = null, questionNum =
     params.append('knowledgeId', knowledgeId)
   }
 
-  params.append('questionNum', questionNum.toString())
+  params.append('questionNum', questionNum)
 
   return axios
-    .get(useQuestionServer('/recommendation'))
+    .get(useQuestionServer('/recommendation'), { params })
     .then(res => res.data)
 }
 

+ 123 - 25
src/views/quiz/DoRecommendQuestion.vue

@@ -1,50 +1,138 @@
 <template>
   <div class="do-recommend-question">
-    <back-title>系统推荐</back-title>
-    <template v-for="(question, index) in questions">
-      <do-quiz-question-card @choice="handleChoice" :key="question.id" :question-prop="question"
-                             :marked-prop="interactiveMap ? interactiveMap[question.id].marked : false"
-                             :rate-prop="interactiveMap ? interactiveMap[question.id].rate : 0"
-                             :index="index"></do-quiz-question-card>
+    <back-title>系统推荐习题</back-title>
+    <div class="vertical-center mb-16" v-if="knowledgeTree">
+      <treeselect
+        v-model="selectedKnowledgeIdList"
+        :multiple="true"
+        :options="knowledgeTree ? knowledgeTree : null"
+        placeholder="选择相关知识点"
+      />
+      <c-button icon="search" theme="green" :left="12">搜索</c-button>
+    </div>
+    <div v-else class="mt-24">知识点加载中...</div>
+    <div class="no-content-warning" v-if="questions === null">
+      推荐习题加载中...
+    </div>
+    <template v-else>
+      <template v-for="(question, index) in questions">
+        <do-quiz-question-card @choice="handleChoice" :key="question.id" :question-prop="question"
+                               :marked-prop="interactiveMap ? interactiveMap[question.id].marked : false"
+                               :rate-prop="interactiveMap ? interactiveMap[question.id].rate : 0"
+                               :index="index"></do-quiz-question-card>
+        <div :key="'detail-' + question.id">
+          <p class="mb-8" v-if="question.knowledgeId.length">知识点:{{question.knowledgeId.map(_ =>
+            knowledgeNaming[_]).join(',')}}</p>
+          <p class="mb-8" v-if="question.keyPoints">关键字:{{question.keyPoints}}</p>
+          <p class="mb-8" v-if="question.tag">标签:{{question.tag.join(',')}}</p>
+        </div>
+        <show-transition :key="'transition-' + question.id">
+          <div v-if="submitted" class="answer">
+            <p class="mb-8">
+              答案:{{question.answer}}
+            </p>
+            <p>
+              解析:{{question.analysis}}
+            </p>
+          </div>
+        </show-transition>
+      </template>
+      <c-button class="mt-16" :icon="submitted ? 'arrow_forward' : 'check'" theme="green" standout
+                @click="handleSubmit">{{submitted ? '下一题' : '提交答案'}}
+      </c-button>
     </template>
   </div>
 </template>
 
 <script>
 import BackTitle from '@/components/Basic/BackTitle'
+import Treeselect from '@riophae/vue-treeselect'
+import '@riophae/vue-treeselect/dist/vue-treeselect.css'
 import DoQuizQuestionCard from '@/views/quiz/components/DoQuizQuestionCard'
-import { getInteractiveList, getRecommendationQuestions } from '@/server/question'
+import { getInteractiveList, getRecommendationQuestions, submitAnswerRecord } from '@/server/question'
+import { getKnowledgeNodes } from '@/server/knowledge'
+import { constructTree } from '@/utils/construct-tree'
+import CButton from '@/components/Basic/CButton'
+import ShowTransition from '@/animations/ShowTransition'
 
 export default {
-  components: { DoQuizQuestionCard, BackTitle },
+  components: { ShowTransition, CButton, Treeselect, DoQuizQuestionCard, BackTitle },
   data () {
     return {
-      questions: [],
-      interactiveMap: null
+      questions: null,
+      knowledgeTree: null,
+      knowledgeNaming: null,
+      interactiveMap: null,
+      selectedKnowledgeIdList: [],
+      submitted: false,
+      startAt: new Date(),
+      endAt: new Date()
     }
   },
   mounted () {
-    getRecommendationQuestions({})
+    getKnowledgeNodes()
       .then(res => {
-        this.questions = res
-        getInteractiveList({ questionIdJoinByComma: this.questions.map(_ => _.id).join(',') })
-          .then(res => {
-            console.log(res)
-            if (res) {
-              const tempMap = {}
-              res.forEach(item => {
-                tempMap[item.questionId] = { marked: item.collection, rate: item.rate }
-              })
-              this.interactiveMap = tempMap
-            }
-          })
-          .catch(err => this.$setErrorMessage(err.response.data.msg))
+        this.knowledgeNaming = {}
+        res.forEach(item => {
+          this.knowledgeNaming[item.abbreviation] = item.name
+        })
+        this.knowledgeTree = constructTree(res)
       })
       .catch(err => this.$setErrorMessage(err.response.data.msg))
+    this.getQuestions()
   },
   methods: {
+    getQuestions () {
+      getRecommendationQuestions({ questionNum: 1 })
+        .then(res => {
+          this.questions = res.map(question => ({
+            ...question,
+            studentAnswer: { answer: '' }
+          }))
+          getInteractiveList({ questionIdJoinByComma: this.questions.map(_ => _.id).join(',') })
+            .then(res => {
+              if (res) {
+                const tempMap = {}
+                res.forEach(item => {
+                  tempMap[item.questionId] = { marked: item.collection, rate: item.rate }
+                })
+                this.interactiveMap = tempMap
+              }
+            })
+            .catch(err => this.$setErrorMessage(err.response.data.msg))
+        })
+        .catch(err => this.$setErrorMessage(err.response.data.msg))
+    },
     handleChoice () {
-
+      this.endAt = new Date()
+    },
+    handleSubmit () {
+      // ! 目前是每次只有一道题
+      //   如果需要多道题的话这里的开始结束时间做法
+      //   应该需要参考学生做题界面的处理
+      //   records 也应该做相应的更改
+      if (this.submitted) {
+        // 点击展示下一题
+        this.getQuestions()
+        this.startAt = new Date()
+        this.submitted = false
+      } else {
+        // 点击上传答案,并显示解析
+        submitAnswerRecord({
+          records: {
+            [this.questions[0].id]: {
+              answer: this.questions[0].studentAnswer.answer,
+              startAt: this.startAt,
+              endAt: this.endAt
+            }
+          }
+        })
+          .then(_ => {
+            this.$setSuccessMessage('提交成功')
+            this.submitted = true
+          })
+          .catch(err => this.$setErrorMessage(err.response.data.msg))
+      }
     }
   }
 }
@@ -56,4 +144,14 @@ export default {
   max-width: 800px;
   margin: 0 auto;
 }
+
+.do-quiz-question-card {
+  border: none;
+  margin: 0 -16px;
+}
+
+.answer {
+  padding: 12px;
+  border: 1px solid #aabaca;
+}
 </style>

+ 0 - 1
src/views/quiz/StudentDoQuiz.vue

@@ -140,7 +140,6 @@ export default {
           endAt: new Date(this.records[key].endAt)
         }
       })
-      console.log(records)
       submitQuizStudentAnswer({ quizId, records }).then(res => {
         this.hasSubmit = true
         this.$setSuccessMessage('提交成功')