YM
2024-05-28 d14467a70204879c15b82de39deb6df23b85a088
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,10 +422,8 @@
</template>
<script>
import { getPublicImage } from "@/assets/js/middleGround/tool";
export default {
  name: "examination-option",
  // props: ["cardList"],
  props: {
    cardList: {
      type: Array,
@@ -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,34 +560,62 @@
      this.$props.cardList = list;
      console.log(this.$props.cardList);
    },
    // 保存按钮
    saveAnswer() {
      console.log(this.cardList);
      const oldAnswerData = localStorage.getItem("oldAnswerData");
      let oldData = oldAnswerData ? JSON.parse(oldAnswerData) : {};
      const asnwerList = [];
      for (let index = 0; index < this.$props.cardList.length; index++) {
        const item = this.$props.cardList[index];
        for (let cindex = 0; cindex < item.infoList.length; cindex++) {
          const citem = item.infoList[cindex];
          asnwerList.push({
            id: citem.id,
            userAnswer: citem.userAnswer,
          });
    getParentWithClass(element, className) {
      while (element.parentElement) {
        element = element.parentElement;
        if (element.classList.contains(className)) {
          return element;
        }
      }
      if(oldData[this.chapter]) {
        oldData[this.chapter][this.page] = asnwerList
      } else {
        oldData[this.chapter] = {}
        oldData[this.chapter][this.page] = asnwerList
      }
      console.log(oldData);
      localStorage.setItem("oldAnswerData", JSON.stringify(oldData));
    },
    // 保存按钮
    saveAnswer() {
      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++) {
          const item = this.$props.cardList[index];
          for (let cindex = 0; cindex < item.infoList.length; cindex++) {
            const citem = item.infoList[cindex];
            asnwerList.push({
              id: citem.id,
              userAnswer: citem.userAnswer,
            });
          }
        }
        if(oldData[pageNum]) {
          oldData[pageNum].push(asnwerList)
        } else {
          oldData[pageNum] = asnwerList
        }
        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>