闫增涛
2024-05-28 6016198229e16f20be1bf55df64b9f363e27b698
src/components/examinations/index.vue
@@ -211,6 +211,7 @@
            "
          ></TEditorVue> -->
            <el-input
              @input="textChange($event,nindex,value.id)"
              :disabled="value.isComplete"
              style="width: 94%; margin: 0 auto"
              v-else-if="value.questionType == 'shortAnswer'"
@@ -421,14 +422,12 @@
</template>
<script>
import { getPublicImage } from "@/assets/js/middleGround/tool";
export default {
  name: "examination-option",
  // props: ["cardList"],
  props: {
    cardList: {
      type: Array,
      default:[]
      default: [],
    },
    primaryColor: {
      type: String,
@@ -447,7 +446,13 @@
      loading: false,
    };
  },
  inject:['changeQuestionData'],
  mounted() {},
  computed:{
    cardLists() {
      return this.props.cardList
    }
  },
  methods: {
    // 数组转为字符串方法
    arrayToString(data) {
@@ -489,11 +494,7 @@
          citem.isComplete = false;
        }
      }
      // for (let index = 0; index < this.questionList.length; index++) {
      //   const item = this.questionList[index];
      //   item.userAnswer = "";
      //   item.isComplete = false
      // }
      console.log('重做',this.cardList);
    },
    openAnswers() {
      this.$data.loading = true;
@@ -559,10 +560,26 @@
      this.$props.cardList = list;
      console.log(this.$props.cardList);
    },
    getParentWithClass(element, className) {
      while (element.parentElement) {
        element = element.parentElement;
        if (element.classList.contains(className)) {
          return element;
        }
      }
    },
    // 保存按钮
    saveAnswer() {
      console.log(this.cardList);
      const oldAnswerData = localStorage.getItem("oldAnswerData");
      const element = document.getElementsByClassName("examination")[0];
      if (element) {
        const pageNum = this.getParentWithClass(
          element,
          "page-box"
        ).getAttribute("page");
        console.log(this.config.activeBook.name, pageNum);
        const oldAnswerData = localStorage.getItem(
          this.config.activeBook.name + "oldAnswerData"
        );
      let oldData = oldAnswerData ? JSON.parse(oldAnswerData) : {};
      const asnwerList = [];
      for (let index = 0; index < this.$props.cardList.length; index++) {
@@ -575,18 +592,30 @@
          });
        }
      }
      if(oldData[this.chapter]) {
        oldData[this.chapter][this.page] = asnwerList
        if(oldData[pageNum]) {
          oldData[pageNum].push(asnwerList)
      } else {
        oldData[this.chapter] = {}
        oldData[this.chapter][this.page] = asnwerList
          oldData[pageNum] = asnwerList
      }
      console.log(oldData);
      localStorage.setItem("oldAnswerData", JSON.stringify(oldData));
        localStorage.setItem(this.config.activeBook.name + "oldAnswerData", JSON.stringify(oldData));
      }
      // if(oldData[this.chapter]) {
      //   oldData[this.chapter][this.page] = asnwerList
      // } else {
      //   oldData[this.chapter] = {}
      //   oldData[this.chapter][this.page] = asnwerList
      // }
      // console.log(oldData);
    },
    textChange(value,a,b) {
      console.log('输入',value,a,b);
      console.log(this.cardList);
      this.changeQuestionData(9,this.cardList)
    }
  },
};
</script>
<style lang="less" scoped>