yiming
2024-03-25 ecabd20b3dfbd956dad14ffb6ba3dc2efcfdd7c1
packageBookService/pages/bookServices/examination/examination.js
@@ -90,6 +90,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 +114,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)
    }
@@ -458,18 +469,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
            })
          }
        }
@@ -1389,141 +1401,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 +1461,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 +1529,9 @@
            questionDataList: questionList,
            cardList: cardUpdatedList
          })
          console.log('组卷题目列表', this.data.questionDataList);
        })
      })
    })
    }
    this.setData({
      loading: false
    })