闫增涛
2024-03-21 c4e651ac030ef5fe8870f6974fcc4658d42986c6
packageBookService/pages/bookServices/examination/examination.js
@@ -48,6 +48,15 @@
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // wx.enableAlertBeforeUnload({
    //   message: "未提交,是否退出答题?",
    //   success: function (res) {
    //     console.log('确定', res);
    //   },
    //   fail: function (err) {
    //     console.log("失败:", err);
    //   },
    // });
    const systInfo = wx.getSystemInfoSync();
    const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息
    const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
@@ -75,7 +84,6 @@
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  },
  /**
@@ -101,13 +109,12 @@
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
  onUnload(e) {
    if (this.data.countdownInterval !== null) {
      clearInterval(this.data.countdownInterval)
    }
@@ -132,8 +139,29 @@
   */
  onShareAppMessage() {
  },
  // 监听watch
  watch(context, variableName, callback) {
    let value = context.data[variableName]; // 获取被监听属性的当前值
    // 使用 Object.defineProperty 方法在数据对象上定义属性的 getter 和 setter
    Object.defineProperty(context.data, variableName, {
      configurable: true, // 可配置
      enumerable: true, // 可枚举
      get: function () {
        return value; // 返回属性的当前值
      },
      set: function (newVal) {
        const oldVal = value; // 记录属性的旧值
        value = newVal; // 更新属性的值
        callback.call(context, newVal, oldVal); // 调用回调函数,传递新值和旧值
      }
    });
  },
  // 返回
  goBack() {
    console.log(this.data.submitStatus);
    wx.navigateBack();
  },
  //设置背景色
@@ -201,10 +229,11 @@
    this.setData({
      currentIndex: e.detail.index
    })
    let index = e.detail.index - 1 >= 0 ? e.detail.index - 1 : 0
    let flag = this.isHaveAnswer(this.data.questionDataList[index].userAnswer)
    if (flag) this.handleQuestion(e.detail.index)
    if (this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') {
      let index = e.detail.index - 1 >= 0 ? e.detail.index - 1 : 0
      let flag = this.isHaveAnswer(this.data.questionDataList[index].userAnswer)
      if (flag) this.handleQuestion(e.detail.index)
    }
  },
  // 点击答题卡跳转题目
  goQuestion(e) {
@@ -282,17 +311,21 @@
      } else {
        return false
      }
    } else {
    } else if (typeof data == 'object') {
      const answer = data.find((item) => item.length > 0)
      if (answer) {
        return true
      } else {
        return false
      }
    } else {
      return false
    }
  },
  // 提交逻辑
  submitPaper() {
    // 关闭退出页面监听
    wx.disableAlertBeforeUnload()
    this.setData({
      submitStatus: true
    })
@@ -493,6 +526,7 @@
              let value = JSON.parse(res[0].value)
              // 有答题记录,得分赋值
              if (value) {
                wx.disableAlertBeforeUnload()
                this.setData({
                  submitStatus: true
                })
@@ -506,6 +540,7 @@
              this.setData({
                currentIndex: value.currentIndex
              })
              console.log(this.data.submitStatus);
              // 携带答题记录 获取题目
              await this.getQuestionList(value.dataList)
            } else {
@@ -712,7 +747,7 @@
      loading: false,
    })
  },
  // 批改题目 (练习,我的错题,我的收藏)
  // 批改题目 (练习,我的错题,我的收藏,,组卷)
  handleQuestion(num) {
    const questionList = this.data.questionDataList
    const index = num - 1 >= 0 ? num - 1 : 0
@@ -1332,7 +1367,6 @@
  },
  // 获取组卷题目列表
  async getMockDataList(questionList, oldList) {
    console.log(questionList, oldList);
    const questionDataList = this.data.questionDataList
    questionList.forEach(async (pathitem, pathindex) => {
      let itemIds = []
@@ -1451,7 +1485,6 @@
          })
          let questionList = []
          const cardUpdatedList = this.data.cardList
          // if (flag == this.data.idPathList.length) {
          cardUpdatedList.forEach(aitem => {
            aitem.infoList.forEach((bitem, bindex) => {
              questionList.push(bitem)
@@ -1462,6 +1495,7 @@
            questionDataList: questionList,
            cardList: cardUpdatedList
          })
          console.log('组卷题目列表', this.data.questionDataList);
        })
      })
    })