litian
2024-09-06 8dc4e50769a7ebc5f0a3d766f61aa08b8f23b772
packageBookService/pages/bookServices/examination/examination.js
@@ -14,6 +14,8 @@
    countdownInterval: null, // 计时器
    isCountdownRunning: true, // 是否倒计时
    countdownTime: 0, // 倒计时时间
    storeInfo: '',
    jslx: '',
    bookId: "",
    productLinkPath: "",
    rootCmsItemId: "",
@@ -47,7 +49,8 @@
    sliderValue: 0, // 字体滑块
    startTime: "", //进入页面当前时间
    pauseTime: 0, //暂停时间
    showDialog: false // 未提交退出拦截弹窗
    showDialog: false, // 未提交退出拦截弹窗
    showId: ''
  },
  /**
@@ -67,15 +70,23 @@
      rootCmsItemId: options.rootCmsItemId,
      idPathList: options.idPathList ? JSON.parse(options.idPathList) : [],
      answerType: options.answerType,
      storeInfo: options.storeInfo,
      jslx: options.jslx,
    });
    // wx.setNavigationBarTitle({
    //   title: options.answerTitle,
    // })
    wx.setNavigationBarTitle({
      title: options.answerTitle,
    })
    if (this.data.answerType == "mock") {
      this.setData({
        uuid: options.uuid,
        mockid: options.mockid,
      });
    }
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      loginInfo(app, (data) => {
        if (data) {} else {}
      })
    }
    this.init();
  },
@@ -198,7 +209,20 @@
      },
    });
  },
  // 修改nav颜色
  changeNavBarColor(e) {
    if (type == 'night') {
      wx.setNavigationBarColor({
        backgroundColor: '#000000',
        frontColor: '#ffffff',
      })
    } else {
      wx.setNavigationBarColor({
        backgroundColor: '#ffffff',
        frontColor: '#000000',
      })
    }
  },
  // 正则找出听力src
  extractSourceSrc(htmlString) {
    // 正则表达式匹配<source>标签中的src属性值  
@@ -235,26 +259,28 @@
  },
  // 返回拦截
  beforeleave() {
    wx.showModal({
      title: "提示",
      content: "未提交,是否退出答题",
      confirmColor: "#ff6c00",
      cancelColor: "#949494",
      complete: (res) => {
        if (res.cancel) {
          this.setData({
            showDialog: true
          })
        }
        if (res.confirm) {
          this.setData({
            submitStatus: true,
            showDialog: false
          });
          wx.navigateBack();
        }
      },
    });
    if ((this.data.answerType == 'option' || this.data.answerType == 'mock') && !this.data.submitStatus) {
      wx.showModal({
        title: "提示",
        content: "未提交,是否退出答题",
        confirmColor: "#ff6c00",
        cancelColor: "#949494",
        complete: (res) => {
          if (res.cancel) {
            this.setData({
              showDialog: true
            })
          }
          if (res.confirm) {
            this.setData({
              submitStatus: true,
              showDialog: false
            });
            wx.navigateBack();
          }
        },
      });
    }
  },
  onChangeSlider(e) {
    this.setData({
@@ -269,9 +295,21 @@
  },
  //设置背景色
  changeBGColor(e) {
    const flag = e.detail.value
    this.setData({
      isNight: e.detail.value,
      isNight: flag,
    });
    if (flag) {
      wx.setNavigationBarColor({
        backgroundColor: '#000000',
        frontColor: '#ffffff',
      })
    } else {
      wx.setNavigationBarColor({
        backgroundColor: '#ffffff',
        frontColor: '#000000',
      })
    }
  },
  // 获取保存的倒计时时间
  getSavedTime() {
@@ -329,11 +367,13 @@
  },
  // 切换题目
  changeSwiper(e) {
    this.setData({
      currentIndex: e.detail.index,
    });
    let index = e.detail.index - 1 >= 0 ? e.detail.index - 1 : 0;
    const item = this.data.questionDataList[index];
    const lastItem = this.data.questionDataList[index + 1];
    this.setData({
      currentIndex: e.detail.index,
      showId: lastItem.id
    });
    if (
      (this.data.answerType == "collectQuestion" ||
        this.data.answerType == "errorQuestion") &&
@@ -432,7 +472,6 @@
    const inputData = e.detail.value.detail.value;
    const id = e.detail.value.currentTarget.dataset.id;
    const index = Number(e.detail.value.currentTarget.dataset.index);
    console.log(index);
    const questionList = this.data.questionDataList;
    questionList.forEach((item) => {
      if (item.id == id) {
@@ -496,7 +535,6 @@
  // 提交逻辑
  submitPaper() {
    this.setData({
      showDialog: false,
      submitStatus: true,
      loading: true,
    });
@@ -563,6 +601,7 @@
    }
    this.setData({
      loading: false,
      showDialog: false,
    });
  },
  // 初始化函数
@@ -662,6 +701,7 @@
      subjectiveNum: 0,
      currentIndex: 0,
      submitStatus: false,
      showDialog: true
    });
    if (this.data.answerType == "option") {
      this.setData({
@@ -787,6 +827,7 @@
      let query = {
        path: "*",
        queryType: "*",
        productId: this.data.bookId,
        cmsPath: pathitem.productLinkPath,
        itemFields: {
@@ -806,6 +847,9 @@
          size: 999,
        },
      };
      if (this.data.storeInfo) {
        query.storeInfo = this.data.storeInfo
      }
      await app.MG.store.getProductDetail(query).then((res) => {
        this.setData({
          total: res.datas.cmsDatas[0].datas.length,
@@ -822,6 +866,19 @@
          });
        }
        res.datas.cmsDatas[0].datas.forEach((item, index) => {
          if (this.data.storeInfo || this.data.jslx) {
            if (item.Embedded_QuestionBank_QuestionType == 'singleChoice') {
              pathitem.name = "单选题"
            } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer') {
              pathitem.name = "简答题"
            } else if (item.Embedded_QuestionBank_QuestionType == "completion") {
              pathitem.name = "填空题";
            } else if (item.Embedded_QuestionBank_QuestionType == "multipleChoice") {
              pathitem.name = "多选题";
            } else if (item.Embedded_QuestionBank_QuestionType == "judge") {
              pathitem.name = "判断题";
            }
          }
          let oldObj = "";
          if (oldList)
            oldObj = oldList.find((oldItem) => oldItem.id == item.id);
@@ -993,6 +1050,9 @@
            questionDataList: questionList,
            cardList: cardUpdatedList,
          });
          console.log(
            '题目', this.data.questionDataList
          );
        });
      });
    }
@@ -1007,6 +1067,7 @@
    }
    this.setData({
      loading: false,
      showId: this.data.questionDataList[0].id
    });
  },
  // 批改题目 (练习,我的错题,我的收藏,,组卷)
@@ -1198,7 +1259,6 @@
        }
      }
    }
    this.setAnswerInfo(setInfoData);
  },
  // 提交答题数据
@@ -1326,6 +1386,9 @@
          Embedded_QuestionBank_Difficulty: [],
        },
      };
      if (this.data.storeInfo) {
        query.storeInfo = this.data.storeInfo
      }
      await app.MG.store.getProductDetail(query).then((res) => {
        let questionArr = [];
        res.datas.cmsDatas[0].datas.forEach((item, index) => {
@@ -1480,6 +1543,7 @@
    }
    this.setData({
      questionDataList: questionArr,
      showId: questionArr[0].id,
      cardList: cardList,
      loading: false,
    });
@@ -1572,6 +1636,9 @@
        Embedded_QuestionBank_Difficulty: [],
      },
    };
    if (this.data.storeInfo) {
      query.storeInfo = this.data.storeInfo
    }
    await app.MG.store.getProductDetail(query).then((res) => {
      let questionArr = [];
      res.datas.cmsDatas[0].datas.forEach((item, index) => {
@@ -1728,11 +1795,11 @@
      }
      this.setData({
        questionDataList: questionArr,
        showId: questionArr[0].id,
        cardList: cardList,
        loading: false,
      });
    });
    // loadings.value = false
  },
  // 获取组卷结果
  async getEduQuizConfig() {
@@ -1857,6 +1924,9 @@
          Embedded_QuestionBank_Difficulty: [],
        },
      };
      if (this.data.storeInfo) {
        query.storeInfo = this.data.storeInfo
      }
      await app.MG.store.getProductDetail(query).then((res) => {
        res.datas.cmsDatas[0].datas.forEach((item, index) => {
          // 循环questionList,给每题赋值分数
@@ -2011,6 +2081,7 @@
    }
    this.setData({
      loading: false,
      showId: this.data.questionDataList[0].id
    });
  },
  // 获取组卷数据