1
闫增涛
2024-03-27 b2a6887c94cc7887b03ba1cce578e3fc59a62259
packageBookService/pages/bookServices/examination/examination.js
@@ -41,7 +41,8 @@
      answer: []
    },
    saveTime: 20,
    isNight: false
    isNight: false,
    sliderValue: 0, // 字体滑块
  },
  /**
@@ -90,6 +91,11 @@
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (this.data.answerType != 'mock') {
      if (wx.timer) {
        clearInterval(wx.timer)
      }
    }
    if (this.data.answerType == 'mock') {
      if (wx.timer) {
        clearInterval(wx.timer)
@@ -109,12 +115,18 @@
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    if (wx.timer) {
      clearInterval(wx.timer)
    }
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload(e) {
    if (wx.timer) {
      clearInterval(wx.timer)
    }
    if (this.data.countdownInterval !== null) {
      clearInterval(this.data.countdownInterval)
    }
@@ -158,7 +170,12 @@
      }
    });
  },
  onChangeSlider(e) {
    this.setData({
      sliderValue: e.detail.value
    })
    console.log(e.detail.value);
  },
  // 返回
  goBack() {
    console.log(this.data.submitStatus);
@@ -229,10 +246,11 @@
    this.setData({
      currentIndex: 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)
    let index = e.detail.index - 1 >= 0 ? e.detail.index - 1 : 0
    const item = this.data.questionDataList[index]
    if ((this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') && !item.isComplete) {
      let flag = this.isHaveAnswer(item.userAnswer)
      if (flag) this.handleQuestion(index)
    }
  },
  // 点击答题卡跳转题目
@@ -252,21 +270,47 @@
    const id = e.detail.value.currentTarget.dataset.id
    const radioChecked = e.detail.value.detail.value
    const questionList = this.data.questionDataList
    questionList.forEach(item => {
      if (item.id == id) {
    // 我的错题和我的收藏模式下,单选题选择了直接批改
    for (let index = 0; index < questionList.length; index++) {
      const item = questionList[index];
      if (item.id == id && !item.isComplete) {
        item.userAnswer = radioChecked
        item.isUserAnswer = this.isHaveAnswer(radioChecked)
        if ((item.questionType == 'singleChoice' || item.questionType == 'judge') && (this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') && !item.isComplete) {
          debugger
          let index = this.data.currentIndex - 1 >= 0 ? this.data.currentIndex - 1 : 0
          this.handleQuestion(index)
        }
      }
    })
    }
    // questionList.forEach(item => {
    //   if (item.id == id && !item.isComplete) {
    //     item.userAnswer = radioChecked
    //     item.isUserAnswer = this.isHaveAnswer(radioChecked)
    //     if ((item.questionType == 'singleChoice' || item.questionType == 'judge') && (this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') && !item.isComplete) {
    //       this.handleQuestion(this.data.currentIndex)
    //     }
    //   }
    // })
    const cardListUpdata = this.data.cardList
    cardListUpdata.forEach(item => {
      item.infoList.forEach(citem => {
        if (citem.id == id) {
    for (let index = 0; index < cardListUpdata.length; index++) {
      const item = cardListUpdata[index];
      for (let cindex = 0; cindex < item.infoList.length; cindex++) {
        const citem = item.infoList[cindex];
        if (citem.id == id && !citem.isComplete) {
          citem.userAnswer = radioChecked
          citem.isUserAnswer = this.isHaveAnswer(radioChecked)
        }
      })
    })
      }
    }
    // cardListUpdata.forEach(item => {
    //   item.infoList.forEach(citem => {
    //     if (citem.id == id && !citem.isComplete) {
    //       citem.userAnswer = radioChecked
    //       citem.isUserAnswer = this.isHaveAnswer(radioChecked)
    //     }
    //   })
    // })
    this.setData({
      questionDataList: questionList,
      cardList: cardListUpdata
@@ -345,10 +389,12 @@
  },
  // 提交逻辑
  submitPaper() {
    // 关闭退出页面监听
    wx.disableAlertBeforeUnload()
    this.setData({
      submitStatus: true
      submitStatus: true,
      loading: true
    })
    const child = this.selectComponent('#question-options')
    if (this.data.answerType == 'option' || this.data.answerType == 'errorQuestion' || this.data.answerType == 'mock') {
@@ -356,7 +402,7 @@
      const qustionList = this.data.questionDataList
      for (let index = 0; index < qustionList.length; index++) {
        const item = qustionList[index];
        if (!item.isComplete) this.handleQuestion(index + 1)
        if (!item.isComplete) this.handleQuestion(index)
      }
    }
    if (this.data.answerType == 'option') {
@@ -406,7 +452,9 @@
      })
      child.openTestReportDialog()
    }
    this.setData({
      loading: false
    })
  },
  // 初始化函数
  async init() {
@@ -418,17 +466,23 @@
    })
    if (this.data.answerType == 'option') {
      if (this.data)
        this.startCountdown()
      this.setData({
        countdownTime: 2 * 60 * 60 * 1000
      })
        // this.startCountdown()
        this.setData({
          countdownTime: 2 * 60 * 60 * 1000
        })
      // 测试答题
      await this.getCollectIdList() // 获取收藏id列表
      await this.getErrorList()   // 获取错题id列表
    } else if (this.data.answerType == 'collectQuestion') {
      this.setData({
        submitStatus: true
      })
      // 我的收藏
      await this.getcollectId() // 获取收藏题目
    } else if (this.data.answerType == 'errorQuestion') {
      this.setData({
        submitStatus: true
      })
      // 我的错题
      // loadings.value = true
      await this.getErrorIdList()
@@ -458,18 +512,19 @@
            let oldQuestionList = []
            oldQuestionList = await this.getMockQuestionList()
            const userAnswerList = await this.getMockAnswer()
            await this.getMockDataList(oldQuestionList, userAnswerList)
            this.setData({
              'mockData.sumTime': oldMockData.time,
              cardList: oldQuestionList
            })
            await this.getMockDataList(oldQuestionList, userAnswerList)
          }
          if (oldMockData.state == '0' || oldMockData.state == '1' || oldMockData.state == '2') {
            this.startCountdown()
          }
          if (oldMockData.state == '3') {
            this.setData({
              submitStatus: true
              submitStatus: true,
              subjectiveNum: oldMockData.report.userScore
            })
          }
        }
@@ -764,6 +819,8 @@
        })
      })
    }
    // 有题目再开始倒计时
    if (this.data.questionDataList.length) this.startCountdown()
    this.setData({
      loading: false
    })
@@ -771,7 +828,7 @@
  // 批改题目 (练习,我的错题,我的收藏,,组卷)
  handleQuestion(num) {
    const questionList = this.data.questionDataList
    const index = num - 1 >= 0 ? num - 1 : 0
    const index = num
    if (questionList[index].isComplete) {
      // 题目已完成,跳过
      return true
@@ -1389,141 +1446,8 @@
  // 获取组卷题目列表
  async getMockDataList(questionList, oldList) {
    const questionDataList = this.data.questionDataList
    // for (let pathindex = 0; pathindex < questionList.length; pathindex++) {
    //   const pathitem = questionList[pathindex];
    //   let itemIds = []
    //   pathitem.infoList.forEach(item => {
    //     itemIds.push(item.id + '')
    //   })
    //   let query = {
    //     path: '*',
    //     cmsPath: this.data.rootCmsItemId,
    //     cmsType: '*',
    //     productId: this.data.bookId,
    //     queryType: '*',
    //     itemIds,
    //     itemFields: {
    //       Embedded_QuestionBank_Stem: [],
    //       Embedded_QuestionBank_AnalysisCon: [],
    //       Embedded_QuestionBank_Answer: [],
    //       Embedded_QuestionBank_Option: [],
    //       Embedded_QuestionBank_QuestionType: [],
    //       Embedded_QuestionBank_StemStyle: [],
    //       Embedded_QuestionBank_OptionStyle: [],
    //       Embedded_QuestionBank_KnowledgePoint: [],
    //       Embedded_QuestionBank_Difficulty: []
    //     }
    //   }
    //   await app.MG.store.getProductDetail(query).then((res) => {
    //     res.datas.cmsDatas[0].datas.forEach((item, index) => {
    //       // 循环questionList,给每题赋值分数
    //       let oldObj
    //       if (oldList) oldObj = oldList.find((oldItem) => oldItem.id == item.id)
    //       let questionObj = {
    //         // number: pathitem.infoList.find(infoItem => infoItem.itemId == item.id).number,
    //         id: item.id,
    //         score: pathitem.infoList.find(infoItem => infoItem.id == item.id).score,
    //         stem:
    //           item.Embedded_QuestionBank_QuestionType == 'completion'
    //             ? JSON.parse(item.Embedded_QuestionBank_Stem)
    //               .stemTxt.replaceAll('<vacancy>', ',input,')
    //               .split(',')
    //             : JSON.parse(item.Embedded_QuestionBank_Stem), // 题干
    //         answer: item.Embedded_QuestionBank_Answer, // 答案
    //         option: item.Embedded_QuestionBank_Option
    //           ? JSON.parse(item.Embedded_QuestionBank_Option)
    //           : '', // 选择题选项
    //         analysisCon: item.Embedded_QuestionBank_AnalysisCon, // 解析
    //         questionType: item.Embedded_QuestionBank_QuestionType, // 题型
    //         optionStyle: item.Embedded_QuestionBank_OptionStyle, // 选项显示类型
    //         stemStyle: item.Embedded_QuestionBank_StemStyle, // 题干显示类型
    //         difficulty: item.Embedded_QuestionBank_Difficulty
    //           ? 4 - item.Embedded_QuestionBank_Difficulty
    //           : 0, // 难度等级
    //         userAnswer: oldObj
    //           ? oldObj.answer
    //           : item.Embedded_QuestionBank_QuestionType == 'completion' ||
    //             item.Embedded_QuestionBank_QuestionType == 'multipleChoice'
    //             ? []
    //             : '',
    //         isUserAnswer: oldObj ? this.isHaveAnswer(oldObj.userAnswer) : false,
    //         isRight: oldObj ? oldObj.isRight : null,
    //         // isComplete: oldObj ? oldObj.isComplete : false,
    //         isComplete: this.data.mockData.state == '3' ? true : oldObj ? this.isHaveAnswer(oldObj.answer) : false,
    //         isCollect: this.data.collectList.indexOf(item.id) > -1 ? true : false,
    //         isUnfold: '' // 控制解析的折叠面板是否展开
    //       }
    //       // 多选和填空答案肯为数组,要转换JSON格式
    //       if (
    //         questionObj.questionType == 'completion' ||
    //         questionObj.questionType == 'multipleChoice'
    //       ) {
    //         try {
    //           questionObj.answer = JSON.parse(questionObj.answer)
    //         } catch (error) {
    //           questionObj.answer = item.Embedded_QuestionBank_Answer
    //         }
    //       }
    //       // 填空题改造
    //       if (questionObj.questionType == 'completion') {
    //         let index = 0
    //         for (let i = 0; i < questionObj.stem.length; i++) {
    //           const item = questionObj.stem[i]
    //           if (item == 'input') {
    //             questionObj.stem[i] = {
    //               num: index,
    //               data: 'input'
    //             }
    //             if (!oldObj) questionObj.userAnswer[index] = ''
    //             index++
    //           }
    //         }
    //       }
    //       // 获取图片
    //       if (questionObj.stemStyle == 'Image' || questionObj.stemStyle == 'TxtAndImage') {
    //         questionObj.stem.stemImage = getPublicImage(questionObj.stem.stemImage, 150)
    //       }
    //       if (questionObj.optionStyle == 'Image' || questionObj.optionStyle == 'TxtAndImage') {
    //         questionObj.option.forEach(optionItem => {
    //           if (optionItem.img) optionItem.img = getPublicImage(optionItem.img, 150)
    //         })
    //       }
    //       if (oldObj && oldObj.isRight) {
    //         this.setData({
    //           correctNum: this.data.correctNum + 1
    //         })
    //       }
    //       if (item.questionType != 'shortAnswer' && item.isComplete) {
    //         this.setData({
    //           subjectiveTotal: this.data.subjectiveTotal + 1
    //         })
    //       }
    //       // if (oldObj && isHaveAnswer(oldObj.answer)) countDownRef.value.changeAlready()
    //       // cardList赋值
    //       let cardIndex = this.data.cardList.findIndex((item) => item.catalogName == pathitem.catalogName)
    //       debugger
    //       let infoIndex = this.data.cardList[cardIndex].infoList.findIndex(infoItem => infoItem.id == item.id)
    //       this.setData({
    //         [`cardList[${cardIndex}].infoList[${infoIndex}]`]: questionObj
    //       })
    //       let questionList = []
    //       const cardUpdatedList = this.data.cardList
    //       cardUpdatedList.forEach(aitem => {
    //         aitem.infoList.forEach((bitem, bindex) => {
    //           questionList.push(bitem)
    //           bitem.number = bindex + 1
    //         })
    //       })
    //       this.setData({
    //         questionDataList: questionList,
    //         cardList: cardUpdatedList
    //       })
    //       console.log('组卷题目列表', this.data.questionDataList);
    //     })
    //   })
    // }
    questionList.forEach(async (pathitem, pathindex) => {
    for (let pathindex = 0; pathindex < questionList.length; pathindex++) {
      const pathitem = questionList[pathindex];
      let itemIds = []
      pathitem.infoList.forEach(item => {
        itemIds.push(item.id + '')
@@ -1582,7 +1506,7 @@
            isUserAnswer: oldObj ? this.isHaveAnswer(oldObj.userAnswer) : false,
            isRight: oldObj ? oldObj.isRight : null,
            // isComplete: oldObj ? oldObj.isComplete : false,
            isComplete: this.data.mockData.state == '3' ? true : oldObj ? this.isHaveAnswer(oldObj.answer) : false,
            isComplete: this.data.mockData.state == '3' ? true : false,
            isCollect: this.data.collectList.indexOf(item.id) > -1 ? true : false,
            isUnfold: '' // 控制解析的折叠面板是否展开
          }
@@ -1650,10 +1574,9 @@
            questionDataList: questionList,
            cardList: cardUpdatedList
          })
          console.log('组卷题目列表', this.data.questionDataList);
        })
      })
    })
    }
    this.setData({
      loading: false
    })