user1
2024-06-21 7869653a258353bd70fc232630ab8467fa379bfe
src/books/mathBook/view/components/index.vue
@@ -18,13 +18,14 @@
      <chapterOne
        v-if="showCatalogList.indexOf(2) > -1"
        :showPageList="loadPageList"
        :questionData="questionDataMap"
      ></chapterOne>
    </div>
  </div>
</template>
<script>
import axios from "axios";
import pageHeader from "./header.vue";
import chapterOne from "./chapter001.vue";
// import chapterTwo from "./chapter002.vue";
@@ -38,8 +39,9 @@
import "swiper/swiper-bundle.css";
import Viewer from "viewerjs";
import "viewerjs/dist/viewer.css";
import getQuestionList from "@/assets/methods/examination";
export default {
  name:"pageContent",
  name: "pageContent",
  data() {
    return {
      catalogLength: 2, // 总章节数
@@ -54,6 +56,8 @@
      questionDataMap: {},
      renderSignMap: {},
      highlightData: null,
      questionId: {},
      collectId:[]
    };
  },
  computed: {
@@ -188,6 +192,10 @@
    //   txtIndex: 57
    // });
    // }, 5000);
    // 获取题目id列表
    this.getQuestionId();
    this.getCollect()
  },
  methods: {
    // setZoom1() {
@@ -309,7 +317,10 @@
          this.container ? this.container : document
        ).querySelector(`[page="${data.page}"]`);
        // 创建 createTreeWalker 迭代器,用于遍历文本节点,保存到一个数组
        const treeWalker = document.createTreeWalker(pageDom, NodeFilter.SHOW_TEXT);
        const treeWalker = document.createTreeWalker(
          pageDom,
          NodeFilter.SHOW_TEXT
        );
        const allTextNodes = [];
        let currentNode = treeWalker.nextNode();
        while (currentNode) {
@@ -537,30 +548,14 @@
            // 添加页码
            this.loadPageList.push(Number(page));
            const catalog = catalogDom.getAttribute("num");
            // if (!this.questionDataMap[page]) {
            //   if (testData && testData[catalog]) {
            //     if (testData[catalog][page]) {
            //       if (Array.isArray(testData[catalog][page])) {
            //         this.questionDataMap[page] = await getQuestionList(
            //           page,
            //           testData[catalog][page],
            //           this.config.activeBook
            //         );
            //       } else {
            //         const obj = {};
            //         for (let key in testData[catalog][page]) {
            //           obj[key] = await getQuestionList(
            //             [],
            //             testData[catalog][page][key],
            //             this.config.activeBook
            //           );
            //         }
            //         this.questionDataMap[page] = obj;
            //       }
            //       console.log("题目", this.questionDataMap);
            //     }
            //   }
            // }
            if (!this.questionDataMap[page]) {
              if (this.questionId && this.questionId[catalog]) {
                if (this.questionId[catalog][page]) {
                  this.questionDataMap[page] = await this.getQuestion(catalog, page);
                  console.log("题目", this.questionDataMap);
                }
              }
            }
            // 渲染这一页的标记
            for (const key in this.renderSignMap) {
              if (this.renderSignMap[key][page]) {
@@ -574,7 +569,10 @@
              // 高亮行
              setTimeout(() => {
                // 获取页面所有text节点
                const pageTextList = document.createTreeWalker(target, NodeFilter.SHOW_TEXT);
                const pageTextList = document.createTreeWalker(
                  target,
                  NodeFilter.SHOW_TEXT
                );
                // 匹配关键字
                const allPageTextNodes = [];
                let currentNode = pageTextList.nextNode();
@@ -618,23 +616,19 @@
          autoplay: {
            //自动开始
            delay: 3000, //时间间隔
            disableOnInteraction: false //*手动操作轮播图后不会暂停*
            disableOnInteraction: false, //*手动操作轮播图后不会暂停*
          },
          paginationClickable: true,
          slidesPerView: 1, // 一组三个
          spaceBetween: 30, // 间隔
          // 如果需要前进后退按钮
          navigation: {
            nextEl: dom.querySelector(
              ".swiper-button-next"
            ),
            prevEl: dom.querySelector(
              ".swiper-button-prev"
            )
            nextEl: dom.querySelector(".swiper-button-next"),
            prevEl: dom.querySelector(".swiper-button-prev"),
          },
          // 窗口变化,重新init,针对F11全屏和放大缩小,必须加
          observer: true,
          observeParents: true
          observeParents: true,
          // // 如果需要分页器
          // pagination: {
          //   el: (this.container ? this.container : document).querySelector(
@@ -657,12 +651,8 @@
          spaceBetween: 30, // 间隔
          // 如果需要前进后退按钮
          navigation: {
            nextEl: dom.querySelector(
              ".swiper-button-next"
            ),
            prevEl: dom.querySelector(
              ".swiper-button-prev"
            )
            nextEl: dom.querySelector(".swiper-button-next"),
            prevEl: dom.querySelector(".swiper-button-prev"),
          },
          // 窗口变化,重新init,针对F11全屏和放大缩小,必须加
          observer: true,
@@ -681,8 +671,8 @@
              var paginationInfoEl = dom.querySelector(".pageBox");
              if (paginationInfoEl)
                paginationInfoEl.textContent = currentPage + "/" + totalPages;
            }
          }
            },
          },
        });
      }
    },
@@ -726,7 +716,7 @@
          propsData: {
            showPageList: [],
            questionData: {},
            isSearch: true
            isSearch: true,
          },
        });
        pageExample.$mount(
@@ -758,7 +748,7 @@
              propsData: {
                showPageList: [pageNum],
                questionData: {},
                isSearch: true
                isSearch: true,
              },
            });
            pageExample.$mount(
@@ -772,7 +762,10 @@
              .querySelector(`[page="${pageNum}"]`);
            if (thisPageDom) {
              // 获取页面所有text节点
              const pageTextList = document.createTreeWalker(thisPageDom, NodeFilter.SHOW_TEXT);
              const pageTextList = document.createTreeWalker(
                thisPageDom,
                NodeFilter.SHOW_TEXT
              );
              // 匹配关键字
              const allPageTextNodes = [];
              let currentNode = pageTextList.nextNode();
@@ -813,6 +806,92 @@
      // 跳转
      this.gotoPage(data.catalog, data.page, () => {});
    },
    // 获取题目列表
    getQuestionId() {
      axios
        .get(this.config.activeBook.resourceUrl + "/question.json")
        .then((res) => {
          this.questionId = res.data.data;
        });
    },
    // 获取题目收藏id列表
    getCollect() {
      this.MG.identity
        .getUserKey({
          domain: "collectData",
          keys: [this.config.activeBook.bookId],
        })
        .then((res) => {
          try {
            const collect = JSON.parse(res[0].value);
            if (collect.length) {
              this.collectId = collect.find(item => item.type == 'json').collectList
            }
          } catch (error) {
            console.log("暂无数据");
          }
        }).catch(res => {
          console.log('index 请求题目收藏id报错');
        })
    },
    // 获取章节题目
    async getQuestion(num, page) {
      let cardList = [
        {
          catalogName: "单选题",
          infoList: [],
        },
        {
          catalogName: "判断题",
          infoList: [],
        },
        {
          catalogName: "多选题",
          infoList: [],
        },
        {
          catalogName: "填空题",
          infoList: [],
        },
        {
          catalogName: "简答题",
          infoList: [],
        },
      ];
      if (this.questionId) {
        if (this.questionId[num] && this.questionId[num][page]) {
          const res = await axios.get(
            this.config.activeBook.resourceUrl + "/question-" + num + ".json"
          );
          if (!res.data.data) return [];
          for (let index = 0; index < res.data.data.length; index++) {
            const item = res.data.data[index];
              item.isCollect = this.collectId.indexOf(item.id) > -1 ? true :false
            console.log(item.id ,this.collectId.indexOf(item.id));
            if (this.questionId[num][page].indexOf(item.id) > -1) {
              if (item.type && item.type == "material") {
                cardList.push(item);
              } else {
                if (item.questionType == "judge") {
                  cardList[1].infoList.push(item);
                } else if (item.questionType == "singleChoice") {
                  cardList[0].infoList.push(item);
                } else if (item.questionType == "multipleChoice") {
                  cardList[2].infoList.push(item);
                } else if (item.questionType == "completion") {
                  cardList[3].infoList.push(item);
                } else if (item.questionType == "shortAnswer") {
                  cardList[4].infoList.push(item);
                }
              }
            }
          }
          return cardList.filter((item) => item.infoList.length > 0);
        }
      } else {
        return [];
      }
    },
  },
  components: {
    pageHeader,