From b6862540422a853ddca486de30382b34ad667b7f Mon Sep 17 00:00:00 2001
From: shuishen <1109946754@qq.com>
Date: Tue, 07 Nov 2023 15:15:37 +0800
Subject: [PATCH] 考试逻辑

---
 src/components/Subjects/MultipleChoices/index.vue |  162 ++++++++++++++++++++++++++++-------------------------
 1 files changed, 86 insertions(+), 76 deletions(-)

diff --git a/src/components/Subjects/MultipleChoices/index.vue b/src/components/Subjects/MultipleChoices/index.vue
index 9bb7bc5..5b8c33c 100644
--- a/src/components/Subjects/MultipleChoices/index.vue
+++ b/src/components/Subjects/MultipleChoices/index.vue
@@ -2,100 +2,110 @@
  * @Author: shuishen 1109946754@qq.com
  * @Date: 2023-11-06 10:15:36
  * @LastEditors: shuishen 1109946754@qq.com
- * @LastEditTime: 2023-11-07 14:43:28
+ * @LastEditTime: 2023-11-07 15:12:56
  * @FilePath: \zhba_exam\src\components\Subjects\MultipleChoices\index.vue
  * @Description: 
  * 
  * Copyright (c) 2023 by shuishen, All Rights Reserved. 
 -->
 <template>
-    <div>
-        <div class="subject-content">
-            <div class="subject-title">
-                {{ index }}
-                <span class="subject-title-content" v-html="subjectInfo.subjectName" />
-                <span class="subject-title-content titlesss">
-                    (&nbsp;多选题&nbsp;<span v-if="subjectInfo.score !== undefined && subjectInfo.score !== 0">&nbsp;{{
-                        subjectInfo.score }}分&nbsp;</span>)
-                </span>
-            </div>
+  <div>
+    <div class="subject-content">
+      <div class="subject-title">
+        {{ index }}
+        <span class="subject-title-content" v-html="subjectInfo.subjectName" />
+        <span class="subject-title-content titlesss">
+          (&nbsp;多选题&nbsp;<span
+            v-if="subjectInfo.score !== undefined && subjectInfo.score !== 0"
+            >&nbsp;{{ subjectInfo.score }}分&nbsp;</span
+          >)
+        </span>
+      </div>
 
-            <ul class="subject-options" v-for="option in options" :key="option.id">
-                <li class="subject-option">
-                    <input class="toggle" type="checkbox" :checked="isChecked(option.optionName)" :id="'option' + option.id"
-                        @change="toggleOption($event, option)" />
-                    <label :for="'option' + option.id">
-                        <span class="subject-option-prefix">{{ option.optionName + "." }}&nbsp;</span>
-                        <span v-html="option.optionContent" class="subject-option-prefix" />
-                    </label>
-                </li>
-            </ul>
-        </div>
+      <ul class="subject-options" v-for="option in options" :key="option.id">
+        <li class="subject-option">
+          <input
+            class="toggle"
+            type="checkbox"
+            :checked="isChecked(option.optionName)"
+            :id="'option' + option.id"
+            @change="toggleOption($event, option)"
+          />
+          <label :for="'option' + option.id">
+            <span class="subject-option-prefix"
+              >{{ option.optionName + "." }}&nbsp;</span
+            >
+            <span v-html="option.optionContent" class="subject-option-prefix" />
+          </label>
+        </li>
+      </ul>
     </div>
+  </div>
 </template>
 
 <script>
 export default {
-    name: "MultipleChoices",
-    data () {
-        return {
-            subjectCount: 0,
-            subjectInfo: {
-                subjectName: "",
-                score: 0,
-            },
-            options: [],
-            userAnswer: [],
-            index: "",
+  name: "MultipleChoices",
+  data() {
+    return {
+      subjectCount: 0,
+      subjectInfo: {
+        subjectName: "",
+        score: 0,
+      },
+      options: [],
+      userAnswer: [],
+      index: "",
+    };
+  },
+  watch: {},
+  methods: {
+    getAnswer() {
+      return this.userAnswer.join(",");
+    },
+    setAnswer(answer) {
+      // if (isNotEmpty(answer)) {
+      this.userAnswer = answer.split(",");
+      // }
+    },
+    setSubjectInfo(subject, subjectCount, index) {
+      this.subjectCount = subjectCount;
+      this.subjectInfo = subject;
+      if (subject.hasOwnProperty("examSubjectOptions")) {
+        this.options = subject.examSubjectOptions;
+      }
+      if (subject.hasOwnProperty("answer")) {
+        this.setAnswer(subject.answer);
+      }
+      this.index = index + ".";
+    },
+    getSubjectInfo() {
+      this.subjectInfo.options = this.options;
+      return this.subjectInfo;
+    },
+    // 选中选项
+    toggleOption($event, option) {
+      if ($event.target.checked) {
+        if (!this.userAnswer.includes(option.optionName)) {
+          this.userAnswer.push(option.optionName);
         }
+      } else {
+        this.userAnswer.splice(
+          this.userAnswer.findIndex((item) => item === option.optionName),
+          1
+        );
+      }
     },
-    watch: {},
-    methods: {
-        getAnswer () {
-            return this.userAnswer.join(",")
-        },
-        setAnswer (answer) {
-            this.userAnswer = []
-        },
-        setSubjectInfo (subject, subjectCount, index) {
-            this.subjectCount = subjectCount
-            this.subjectInfo = subject
-            if (subject.hasOwnProperty("examSubjectOptions")) {
-                this.options = subject.examSubjectOptions
-            }
-            if (subject.hasOwnProperty("answer")) {
-                this.setAnswer(subject.answer)
-            }
-            this.index = index + "."
-        },
-        getSubjectInfo () {
-            this.subjectInfo.options = this.options
-            return this.subjectInfo
-        },
-        // 选中选项
-        toggleOption ($event, option) {
-            if ($event.target.checked) {
-                if (!this.userAnswer.includes(option.optionName)) {
-                    this.userAnswer.push(option.optionName)
-                }
-            } else {
-                this.userAnswer.splice(
-                    this.userAnswer.findIndex((item) => item === option.optionName),
-                    1
-                )
-            }
-        },
-        isChecked (optionName) {
-            return this.userAnswer.includes(optionName)
-        },
+    isChecked(optionName) {
+      return this.userAnswer.includes(optionName);
     },
-}
+  },
+};
 </script>
 
 <style lang="scss" scoped>
 @import "../../../assets/css/subject.scss";
-
-.subject-options>li label {
-    line-height: 36px !important;
+.subject-options > li label {
+  line-height: 36px !important;
 }
 </style>

--
Gitblit v1.9.3