智慧保安考试系统
shuishen
2023-11-07 b6862540422a853ddca486de30382b34ad667b7f
src/components/Subjects/Judgement/index.vue
@@ -1,76 +1,84 @@
<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>
            <ul class="subject-options" v-for="option in options" :key="option.id">
                <li class="subject-option">
                    <input class="toggle" type="checkbox" :checked="userAnswer === option.optionName"
                        :id="'option' + option.id" @change="toggleOption(option)" />
                    <label :for="'option' + option.id">
                        <span class="subject-option-prefix">{{ option.optionName }}&nbsp;</span>
                    </label>
                </li>
            </ul>
        </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="userAnswer === option.optionName"
            :id="'option' + option.id"
            @change="toggleOption(option)"
          />
          <label :for="'option' + option.id">
            <span class="subject-option-prefix"
              >{{ option.optionName }}&nbsp;</span
            >
          </label>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
export default {
    name: "Judgement",
    data () {
        return {
            subjectCount: 0,
            subjectInfo: {
                subjectName: "",
                score: 0,
            },
            options: [
                { id: 1, optionName: "正确" },
                { id: 2, optionName: "错误" },
            ],
            userAnswer: "",
            index: "",
        }
  name: "Judgement",
  data() {
    return {
      subjectCount: 0,
      subjectInfo: {
        subjectName: "",
        score: 0,
      },
      options: [
        { id: 1, optionName: "正确" },
        { id: 2, optionName: "错误" },
      ],
      userAnswer: "",
      index: "",
    };
  },
  methods: {
    getAnswer() {
      return this.userAnswer;
    },
    methods: {
        getAnswer () {
            return this.userAnswer
        },
        setAnswer (answer) {
            this.userAnswer = ''
        },
        setSubjectInfo (subject, subjectCount, index) {
            this.subjectCount = subjectCount
            this.subjectInfo = subject
            if (subject.hasOwnProperty("answer")) {
                this.setAnswer(subject.answer)
            }
            this.index = index + "."
        },
        getSubjectInfo () {
            this.subjectInfo.options = this.options
            return this.subjectInfo
        },
        // 选中选项
        toggleOption (option) {
            this.userAnswer = option.optionName
        },
    setAnswer(answer) {
      this.userAnswer = answer;
    },
}
    setSubjectInfo(subject, subjectCount, index) {
      this.subjectCount = subjectCount;
      this.subjectInfo = subject;
      if (subject.hasOwnProperty("answer")) {
        this.setAnswer(subject.answer);
      }
      this.index = index + ".";
    },
    getSubjectInfo() {
      this.subjectInfo.options = this.options;
      return this.subjectInfo;
    },
    // 选中选项
    toggleOption(option) {
      this.userAnswer = option.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>