litian
2024-07-22 f4e7324c27b7c6ecb824029e22a13541c5033ade
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, // 未提交退出拦截弹窗
    showId: ''
  },
  /**
@@ -67,7 +70,12 @@
      rootCmsItemId: options.rootCmsItemId,
      idPathList: options.idPathList ? JSON.parse(options.idPathList) : [],
      answerType: options.answerType,
      storeInfo: options.storeInfo,
      jslx: options.jslx,
    });
    wx.setNavigationBarTitle({
      title: options.answerTitle,
    })
    if (this.data.answerType == "mock") {
      this.setData({
        uuid: options.uuid,
@@ -75,7 +83,6 @@
      });
    }
    this.init();
    console.log("传参", options);
  },
  /**
@@ -196,20 +203,34 @@
      },
    });
  },
  // 修改nav颜色
  changeNavBarColor(e) {
    if (type == 'night') {
      wx.setNavigationBarColor({
        backgroundColor: '#000000',
        frontColor: '#ffffff',
      })
    } else {
      wx.setNavigationBarColor({
        backgroundColor: '#ffffff',
        frontColor: '#000000',
      })
    }
  },
  // 正则找出听力src
  extractSourceSrc(htmlString) {
    // 正则表达式匹配<source>标签中的src属性值  
    var srcRegex = /<source\s+src="([^"]+)"/i;
    var srcTwo = /<audio\s+src="([^"]+)"/i;
    // 执行正则匹配  
    var match = srcRegex.exec(htmlString);
    const local = srcTwo.exec(htmlString)
    // 如果匹配成功,返回第一个捕获组的内容(src属性的值)  
    if (match && match[1]) {
      return match[1];
      return match[1].replace('../file', app.config.requestCtx + '/file');
    } else if (local && local[1]) {
      return local[1]
      return local[1].replace('../file', app.config.requestCtx + '/file')
    } else {
      // 如果没有匹配到,返回null  
      return null;
@@ -232,21 +253,28 @@
  },
  // 返回拦截
  beforeleave() {
    wx.showModal({
      title: "提示",
      content: "未提交,是否退出答题",
      confirmColor: "#ff6c00",
      cancelColor: "#949494",
      complete: (res) => {
        if (res.cancel) {}
        if (res.confirm) {
          this.setData({
            submitStatus: true,
          });
          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({
@@ -261,9 +289,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() {
@@ -321,11 +361,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") &&
@@ -424,7 +466,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) {
@@ -554,6 +595,7 @@
    }
    this.setData({
      loading: false,
      showDialog: false,
    });
  },
  // 初始化函数
@@ -566,7 +608,6 @@
    });
    if (this.data.answerType == "option") {
      if (this.data)
        // this.startCountdown()
        this.setData({
          countdownTime: 2 * 60 * 60 * 1000,
        });
@@ -630,6 +671,9 @@
            oldMockData.state == "2"
          ) {
            this.startCountdown();
            this.setData({
              showDialog: true
            })
          }
          if (oldMockData.state == "3") {
            this.setData({
@@ -651,6 +695,7 @@
      subjectiveNum: 0,
      currentIndex: 0,
      submitStatus: false,
      showDialog: true
    });
    if (this.data.answerType == "option") {
      this.setData({
@@ -729,6 +774,9 @@
              await this.getQuestionList(value.dataList);
            } else {
              await this.getQuestionList(); // 获取题库题目
              this.setData({
                showDialog: true
              })
            }
          });
        }
@@ -773,6 +821,7 @@
      let query = {
        path: "*",
        queryType: "*",
        productId: this.data.bookId,
        cmsPath: pathitem.productLinkPath,
        itemFields: {
@@ -792,10 +841,10 @@
          size: 999,
        },
      };
      if (this.data.storeInfo) {
        query.storeInfo = this.data.storeInfo
      }
      await app.MG.store.getProductDetail(query).then((res) => {
        if (!res.datas.cmsDatas[0].datas.length) return this.setData({
          noData: true
        })
        this.setData({
          total: res.datas.cmsDatas[0].datas.length,
        });
@@ -811,6 +860,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);
@@ -874,7 +936,7 @@
                /\<img/gi,
                '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" '
              )
              .replace(/\<p/gi, '<p class="stem-rich-p"');
              .replace(/\<p/gi, '<p class="stem-rich-p"').replace('../file', app.config.requestCtx + '/file');
          }
          // 选项富文本处理
          if (
@@ -887,7 +949,7 @@
              if (item.txt)
                item.txt = item.txt
                .replace(/\<img/gi, '<img class="option-rich-img"')
                .replace(/\<p/gi, '<p class="stem-rich-p"');
                .replace(/\<p/gi, '<p class="stem-rich-p"').replace('../file', app.config.requestCtx + '/file');
            });
          }
          // 解析富文本处理
@@ -982,13 +1044,24 @@
            questionDataList: questionList,
            cardList: cardUpdatedList,
          });
          console.log(
            '题目', this.data.questionDataList
          );
        });
      });
    }
    // 有题目再开始倒计时
    if (this.data.questionDataList.length) this.startCountdown();
    if (this.data.questionDataList.length) {
      console.log(this.data.questionDataList);
      this.startCountdown();
    } else {
      this.setData({
        noData: true
      })
    }
    this.setData({
      loading: false,
      showId: this.data.questionDataList[0].id
    });
  },
  // 批改题目 (练习,我的错题,我的收藏,,组卷)
@@ -1180,7 +1253,6 @@
        }
      }
    }
    this.setAnswerInfo(setInfoData);
  },
  // 提交答题数据
@@ -1308,6 +1380,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) => {
@@ -1387,7 +1462,7 @@
                /\<img/gi,
                '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" '
              )
              .replace(/\<p/gi, '<p class="stem-rich-p"');
              .replace(/\<p/gi, '<p class="stem-rich-p"').replace('../file', app.config.requestCtx + '/file');
          }
          // 选项富文本处理
          if (
@@ -1400,7 +1475,7 @@
              if (item.txt)
                item.txt = item.txt
                .replace(/\<img/gi, '<img class="option-rich-img"')
                .replace(/\<p/gi, '<p class="stem-rich-p"');
                .replace(/\<p/gi, '<p class="stem-rich-p"').replace('../file', app.config.requestCtx + '/file');
            });
          }
          // 解析富文本处理
@@ -1462,6 +1537,7 @@
    }
    this.setData({
      questionDataList: questionArr,
      showId: questionArr[0].id,
      cardList: cardList,
      loading: false,
    });
@@ -1554,6 +1630,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) => {
@@ -1635,7 +1714,7 @@
              /\<img/gi,
              '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" '
            )
            .replace(/\<p/gi, '<p class="stem-rich-p"');
            .replace(/\<p/gi, '<p class="stem-rich-p"').replace('../file', app.config.requestCtx + '/file');
        }
        // 选项富文本处理
        if (
@@ -1648,7 +1727,7 @@
            if (item.txt)
              item.txt = item.txt
              .replace(/\<img/gi, '<img class="option-rich-img"')
              .replace(/\<p/gi, '<p class="stem-rich-p"');
              .replace(/\<p/gi, '<p class="stem-rich-p"').replace('../file', app.config.requestCtx + '/file');
          });
        }
        // 解析富文本处理
@@ -1710,11 +1789,11 @@
      }
      this.setData({
        questionDataList: questionArr,
        showId: questionArr[0].id,
        cardList: cardList,
        loading: false,
      });
    });
    // loadings.value = false
  },
  // 获取组卷结果
  async getEduQuizConfig() {
@@ -1839,6 +1918,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,给每题赋值分数
@@ -1905,7 +1987,7 @@
            questionObj.stem.stemTxt = questionObj.stem.stemTxt.replace(
              /\<img/gi,
              '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img"'
            );
            ).replace(/\<p/gi, '<p class="stem-rich-p"').replace('../file', app.config.requestCtx + '/file');
          }
          // 选项富文本处理
          if (
@@ -1919,7 +2001,7 @@
                item.txt = item.txt.replace(
                  /\<img/gi,
                  '<img class="option-rich-img"'
                );
                ).replace(/\<p/gi, '<p class="stem-rich-p"').replace('../file', app.config.requestCtx + '/file');
            });
          }
          // 听力题修改
@@ -1993,6 +2075,7 @@
    }
    this.setData({
      loading: false,
      showId: this.data.questionDataList[0].id
    });
  },
  // 获取组卷数据
@@ -2053,11 +2136,12 @@
      })
      .then((res) => {
        if (res[0]) {
          // 这里的 countdownTime 赋值:如果是时间到了提交,记录的剩余时间就是0,所以:如果是0的话赋值1秒,防止监听到时间为0再次提交
          this.setData({
            currentIndex: JSON.parse(res[0].value).currentIndex,
            "mockData.time": JSON.parse(res[0].value).time,
            countdownTime: JSON.parse(res[0].value).time ?
              JSON.parse(res[0].value).time : this.data.mockData.sumTime,
            countdownTime: JSON.parse(res[0].value).time > 0 ?
              JSON.parse(res[0].value).time : 1000,
            "mockData.answer": JSON.parse(res[0].value).answerData,
          });
          console.log(JSON.parse(res[0].value));