Selaa lähdekoodia

refactor: 只提交改动的数据

ChenYangfan 6 vuotta sitten
vanhempi
commit
cf2395c2cc

+ 5 - 0
src/router/quiz.js

@@ -48,5 +48,10 @@ export default [{
   path: '/student/questions',
   name: 'student-question-table',
   component: () => import(/* webpackChunkName: "student-quiz" */ '@/views/quiz/StudentQuestions.vue')
+}, {
+  meta: { roles: ['student'] },
+  path: '/student/recommend',
+  name: 'do-recommend-question',
+  component: () => import(/* webpackChunkName: "student-quiz" */ '@/views/quiz/DoRecommendQuestion.vue')
 }
 ]

+ 24 - 0
src/server/question.js

@@ -129,3 +129,27 @@ export function getInteractiveList ({ questionIdJoinByComma }) {
     .get(useQuestionServer('/interactive'), { params: { questionId: questionIdJoinByComma } })
     .then(res => res.data)
 }
+
+// 取得推荐题目
+export function getRecommendationQuestions ({ knowledgeId = null, questionNum = 1 }) {
+  const params = new URLSearchParams()
+  if (typeof knowledgeId !== typeof '') {
+    knowledgeId.forEach(_ => {
+      params.append('knowledgeId', _)
+    })
+  } else {
+    params.append('knowledgeId', knowledgeId)
+  }
+
+  params.append('questionNum', questionNum.toString())
+
+  return axios
+    .get(useQuestionServer('/recommendation'))
+    .then(res => res.data)
+}
+
+// 提交推荐题目答题情况
+export function submitAnswerRecord ({ records }) {
+  return axios
+    .post(useQuestionServer('/record'), { records })
+}

+ 59 - 0
src/views/quiz/DoRecommendQuestion.vue

@@ -0,0 +1,59 @@
+<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>
+    </template>
+  </div>
+</template>
+
+<script>
+import BackTitle from '@/components/Basic/BackTitle'
+import DoQuizQuestionCard from '@/views/quiz/components/DoQuizQuestionCard'
+import { getInteractiveList, getRecommendationQuestions } from '@/server/question'
+
+export default {
+  components: { DoQuizQuestionCard, BackTitle },
+  data () {
+    return {
+      questions: [],
+      interactiveMap: null
+    }
+  },
+  mounted () {
+    getRecommendationQuestions({})
+      .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))
+      })
+      .catch(err => this.$setErrorMessage(err.response.data.msg))
+  },
+  methods: {
+    handleChoice () {
+
+    }
+  }
+}
+</script>
+
+<style lang="scss" scoped>
+.do-recommend-question {
+  padding: 64px 24px;
+  max-width: 800px;
+  margin: 0 auto;
+}
+</style>

+ 12 - 8
src/views/quiz/StudentDoQuiz.vue

@@ -102,11 +102,13 @@ export default {
         getInteractiveList({
           questionIdJoinByComma: this.questions.map(_ => _.id).join(',')
         }).then(res => {
-          const tempMap = {}
-          res.forEach(item => {
-            tempMap[item.questionId] = { marked: item.collection, rate: item.rate }
-          })
-          this.interactiveMap = tempMap
+          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))
     },
@@ -117,11 +119,12 @@ export default {
         startAt: this.lastDate,
         endAt: this.choiceDate
       })
-      const records = {}
+
+      const answers = {}
       let uncompleted = false
       this.questions.map(question => {
         if (question.studentAnswer) {
-          records[question.id] = { answer: question.studentAnswer.answer }
+          answers[question.id] = question.studentAnswer.answer
         } else {
           this.$setErrorMessage('题目:"' + question.stem + '"尚未填写')
           uncompleted = true
@@ -129,9 +132,10 @@ export default {
       })
       if (uncompleted) return
 
+      const records = {}
       Object.keys(this.records).forEach(key => {
         records[key] = {
-          ...records[key],
+          answer: answers[key],
           startAt: new Date(this.records[key].startAt),
           endAt: new Date(this.records[key].endAt)
         }

+ 8 - 0
src/views/quiz/StudentQuestions.vue

@@ -17,6 +17,7 @@
       </div>
     </back-title>
     <student-question-table :get-list-function="getListFunction"></student-question-table>
+    <div class="small-tip">* "已完成" 题目列表仅收录您2020年4月20号起所完成的题目</div>
   </div>
 </template>
 
@@ -52,4 +53,11 @@ export default {
   flex-wrap: wrap;
   margin-bottom: 0;
 }
+
+.small-tip {
+  margin-top: 8px;
+  font-weight: normal;
+  color: #aabaca;
+  font-size: 12px;
+}
 </style>

+ 0 - 1
src/views/quiz/components/DoQuizQuestionCard.vue

@@ -34,7 +34,6 @@ import MarkdownSection from '@/views/quiz/components/MarkdownSection'
 import QuestionKind from '@/enums/question-kind'
 import MarkActionBar from '@/views/quiz/components/MarkActionBar'
 
-// fixme: 通过几层reference传值可能会造成一点困惑 - 咕咕咕
 export default {
   components: { MarkActionBar, CIcon, MarkdownSection },
   props: {

+ 4 - 1
src/views/student/tabs/StudentQuiz.vue

@@ -4,7 +4,10 @@
       <h1 class="title">
         课程测验
         <router-link :to="{ name: 'student-question-table' }">
-          <c-button icon="assignment" :left="12" theme="blue" text>我的题库</c-button>
+          <c-button icon="assignment" :left="12" theme="blue" text>题库</c-button>
+        </router-link>
+        <router-link :to="{ name: 'do-recommend-question' }">
+          <c-button icon="highlight" theme="orange" text>刷题</c-button>
         </router-link>
       </h1>
       <div class="show-quiz-type-bar mb-24">