ソースを参照

feat: 视频试卷新增收藏题

xuqiaoying 3 年 前
コミット
fc1ea18445
1 ファイル変更110 行追加7 行削除
  1. 110 7
      src/pages/course-exam/index.vue

+ 110 - 7
src/pages/course-exam/index.vue

@@ -139,6 +139,19 @@
                       </div>
                       <div class="question__btns">
                         <!-- <div class="collect" @click="collect">收藏本题</div> -->
+                        <div
+                          class="collect"
+                          @click="
+                            collect(collectList[questionIndex], questionIndex)
+                          "
+                        >
+                          <template v-if="!collectList[questionIndex]"
+                            ><i class="el-icon-star-off"></i>收藏本题
+                          </template>
+                          <template v-if="collectList[questionIndex]"
+                            ><i class="el-icon-star-on"></i>已收藏</template
+                          >
+                        </div>
                       </div>
                     </div>
 
@@ -248,6 +261,19 @@
                           确认答案
                         </div>
                         <!-- <div class="collect" @click="collect">收藏本题</div> -->
+                        <div
+                          class="collect"
+                          @click="
+                            collect(collectList[questionIndex], questionIndex)
+                          "
+                        >
+                          <template v-if="!collectList[questionIndex]"
+                            ><i class="el-icon-star-off"></i>收藏本题</template
+                          >
+                          <template v-if="collectList[questionIndex]"
+                            ><i class="el-icon-star-on"></i>已收藏</template
+                          >
+                        </div>
                       </div>
                     </div>
 
@@ -339,6 +365,19 @@
                       </div>
                       <div class="question__btns">
                         <!-- <div class="collect" @click="collect">收藏本题</div> -->
+                        <div
+                          class="collect"
+                          @click="
+                            collect(collectList[questionIndex], questionIndex)
+                          "
+                        >
+                          <template v-if="!collectList[questionIndex]"
+                            ><i class="el-icon-star-off"></i>收藏本题</template
+                          >
+                          <template v-if="collectList[questionIndex]"
+                            ><i class="el-icon-star-on"></i>已收藏</template
+                          >
+                        </div>
                       </div>
                     </div>
 
@@ -894,6 +933,19 @@
                       </div>
                       <div class="question__btns">
                         <!-- <div class="collect" @click="collect">收藏本题</div>+ -->
+                        <div
+                          class="collect"
+                          @click="
+                            collect(collectList[questionIndex], questionIndex)
+                          "
+                        >
+                          <template v-if="!collectList[questionIndex]"
+                            ><i class="el-icon-star-off"></i>收藏本题</template
+                          >
+                          <template v-if="collectList[questionIndex]"
+                            ><i class="el-icon-star-on"></i>已收藏</template
+                          >
+                        </div>
                       </div>
                     </div>
 
@@ -994,6 +1046,19 @@
                           确认答案
                         </div>
                         <!-- <div class="collect" @click="collect">收藏本题</div> -->
+                        <div
+                          class="collect"
+                          @click="
+                            collect(collectList[questionIndex], questionIndex)
+                          "
+                        >
+                          <template v-if="!collectList[questionIndex]"
+                            ><i class="el-icon-star-off"></i>收藏本题</template
+                          >
+                          <template v-if="collectList[questionIndex]"
+                            ><i class="el-icon-star-on"></i>已收藏</template
+                          >
+                        </div>
                       </div>
                     </div>
                   </template>
@@ -1217,6 +1282,7 @@ export default {
       bankType: 0,
       compareFaceData: 0, // 拍照匹配相似度
       answerNum: 0, // 总次数
+      collectList: [],
     };
   },
   async mounted() {
@@ -1274,7 +1340,24 @@ export default {
         });
       });
     },
-
+    /**
+     * @param {Object} current
+     * 获取收藏信息
+     */
+     getCollectInfo(current) {
+      this.$request.getCollectInfo({
+        examId: this.examId,
+        questionId: this.questionList[current].questionId,
+        goodsId: this.goodsId,
+        orderGoodsId: this.orderGoodsId,
+      })
+      .then((res) => {
+        this.$set(this.collectList, current, res.data);
+      })
+      .catch((err) => {
+        this.$set(this.collectList, current, false);
+      });
+    },
     /**
      * 请求题目列表
      */
@@ -1417,7 +1500,7 @@ export default {
 
           this.questionList = res.data;
           this.lastCount = this.questionList.length;
-
+          this.getCollectInfo(this.current)
           await this.examRecord();
         });
     },
@@ -2004,6 +2087,7 @@ export default {
 
     changeIndex(index) {
       this.current = index;
+      this.getCollectInfo(this.current)
     },
     nextQuestion() {
       if (this.current >= this.questionList.length - 1) {
@@ -2014,6 +2098,7 @@ export default {
         return;
       }
       this.current++;
+      this.getCollectInfo(this.current)
     },
     prevQuestion() {
       if (this.current == 0) {
@@ -2024,6 +2109,7 @@ export default {
         return;
       } else {
         this.current--;
+        this.getCollectInfo(this.current)
       }
     },
     isCheck(item, index) {
@@ -2191,11 +2277,28 @@ export default {
       return count;
     },
 
-    collect() {
-      this.$message({
-        message: "试做题目,不支持收藏~",
-        type: "warning",
-      });
+    collect(state, index) {
+      if (!state) {
+        this.$request
+          .collectQuestion({
+            examId: this.examId,
+            questionId: this.questionList[index].questionId,
+            goodsId: this.goodsId || "",
+            orderGoodsId: this.orderGoodsId,
+          })
+          .then((res) => {
+            this.$set(this.collectList, index, true);
+            this.$message.success("收藏成功");
+            this.getCollectInfo(index);
+          });
+      } else {
+        this.$request
+          .deleteCollectQuestion(this.collectList[index].collectQuestionId)
+          .then((res) => {
+            this.$set(this.collectList, index, false);
+            this.$message.success("取消收藏成功");
+          });
+      }
       return;
     },
     submit() {