From 6a734d758720185f538e672c879121adb6732274 Mon Sep 17 00:00:00 2001 From: litian <C21AF165> Date: 星期二, 02 四月 2024 09:20:45 +0800 Subject: [PATCH] 代码合并,问题修改,学习 --- packageBookService/pages/bookServices/examination/examination.js | 393 +++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 276 insertions(+), 117 deletions(-) diff --git a/packageBookService/pages/bookServices/examination/examination.js b/packageBookService/pages/bookServices/examination/examination.js index 196a0ce..b10cd73 100644 --- a/packageBookService/pages/bookServices/examination/examination.js +++ b/packageBookService/pages/bookServices/examination/examination.js @@ -45,6 +45,8 @@ saveTime: 20, isNight: false, sliderValue: 0, // 瀛椾綋婊戝潡 + startTime: "", //杩涘叆椤甸潰褰撳墠鏃堕棿 + pauseTime: 0 //鏆傚仠鏃堕棿 }, /** @@ -110,6 +112,9 @@ } }, 1000) } + this.setData({ + startTime: Date.now() + }) }, /** @@ -118,6 +123,13 @@ onHide() { if (wx.timer) { clearInterval(wx.timer) + } + this.setData({ + pauseTime: Date.now() + }) + if (wx.getStorageSync(app.config.tokenKey)) { + let duration = this.data.pauseTime - this.data.startTime + this.count(duration) } }, @@ -131,6 +143,32 @@ if (this.data.countdownInterval !== null) { clearInterval(this.data.countdownInterval) } + this.setData({ + pauseTime: Date.now() + }) + if (wx.getStorageSync(app.config.tokenKey)) { + let duration = this.data.pauseTime - this.data.startTime + this.count(duration) + } + }, + + count(timeStr) { + const data = { + appRefCode: app.config.appRefCode, + type: 'LearningTime', //缁熻绫诲瀷--闃呰鏃堕暱 + data: timeStr + '', //缁熻鍐呭--鏃堕暱姣 + event: 'LearningTime', + sysType: 'App' + } + //闃呰鍟嗗搧鐨刬d + if (this.data.bookId) { + data.productId = this.data.bookId + } + //闃呰璧勬簮鐨刬d + // if (product.cmsItemId) { + // data.cmsItemId = product.cmsItemId + // } + app.MG.job.newJobWithApiNewEvent(data).then((res) => {}) }, /** @@ -253,6 +291,13 @@ if (flag) this.handleQuestion(index) } }, + // 鎴戠殑閿欓锛屾敹钘忔煡鐪嬭В鏋愭寜閽� + viewParsing() { + if (this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') { + const item = this.data.questionDataList[this.data.currentIndex] + if (!item.isComplete) this.handleQuestion(this.data.currentIndex) + } + }, // 鐐瑰嚮绛旈鍗¤烦杞鐩� goQuestion(e) { const id = e.detail.id @@ -277,8 +322,7 @@ 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) { - let index = this.data.currentIndex - 1 >= 0 ? this.data.currentIndex - 1 : 0 - this.handleQuestion(index) + this.handleQuestion(this.data.currentIndex) } } } @@ -388,7 +432,6 @@ }, // 鎻愪氦閫昏緫 submitPaper() { - // 鍏抽棴閫�鍑洪〉闈㈢洃鍚� wx.disableAlertBeforeUnload() this.setData({ @@ -824,9 +867,8 @@ }) }, // 鎵规敼棰樼洰 锛堢粌涔狅紝鎴戠殑閿欓锛屾垜鐨勬敹钘�,锛岀粍鍗凤級 - handleQuestion(num) { + handleQuestion(index) { const questionList = this.data.questionDataList - const index = num if (questionList[index].isComplete) { // 棰樼洰宸插畬鎴愶紝璺宠繃 return true @@ -854,7 +896,17 @@ // 绠�绛� 缈昏瘧 questionList[index].isRight = null } else if (item.questionType == 'completion') { - // 濉┖ + if (item.answer == 'string') { + item.isRight = item.answer == item.userAnswer[0] + } else { + if (item.answer.length != item.userAnswer.length) { + item.isRight = false + } else { + item.isRight = item.answer.every( + (value, index) => value === item.userAnswer[index] + ) + } + } // subjectiveGrade.value += item.score if (typeof item.answer == 'string') { questionList[index].isRight = item.answer == item.userAnswer[0] @@ -1044,7 +1096,6 @@ this.setData({ collectList: JSON.parse(res[0].value) }) - // total.value = collectList.value.length } catch (error) {} if (this.data.collectList && this.data.collectList.length) { await this.getCollectDataList() @@ -1075,110 +1126,160 @@ let questionArr = [] this.setData({ cardList: [{ - catalogName: '鏀惰棌澶�', + catalogName: '鍗曢�夐', + infoList: [] + }, { + catalogName: '鍒ゆ柇棰�', + infoList: [] + }, { + catalogName: '澶氶�夐', + infoList: [] + }, { + catalogName: '濉┖棰�', + infoList: [] + }, { + catalogName: '绠�绛旈', infoList: [] }] }) - let query = { - path: '*', - cmsPath: this.data.rootCmsItemId, - cmsType: '*', - productId: this.data.bookId, - queryType: '*', - itemIds: this.data.collectList.map((item) => item + ''), - 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: [] + let singleChoiceArr = [] // 鍗曢�� + let judgeArr = [] // 鍒ゆ柇 + let shortArr = [] // 绠�绛� + let multipleChoiceArr = [] // 澶氶�� + let completionArr = [] // 濉┖ + for (let qindex = 0; qindex < this.data.collectList.length; qindex++) { + const qitem = this.data.collectList[qindex]; + let query = { + path: '*', + cmsPath: this.data.rootCmsItemId, + cmsType: '*', + productId: this.data.bookId, + queryType: '*', + itemIds: qitem + '', + 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: [] + } } - } - app.MG.store.getProductDetail(query).then((res) => { - let questionArr = [] - res.datas.cmsDatas[0].datas.forEach((item, index) => { - const questionObj = { - number: index + 1, // 棰樺彿 - id: item.id, - 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, // 瑙f瀽 - 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: item.Embedded_QuestionBank_QuestionType == 'completion' || - item.Embedded_QuestionBank_QuestionType == 'multipleChoice' ? [] : '', - isSubmit: false, // 鏌ョ湅瑙f瀽 - isRight: null, // 鏄惁姝g‘ - isComplete: false, - isCollect: true - } - // 澶氶�夊拰濉┖绛旀鑲负鏁扮粍锛岃杞崲JSON鏍煎紡 - if ( - questionObj.questionType == 'completion' || - questionObj.questionType == 'multipleChoice' - ) { - try { - questionObj.answer = JSON.parse(questionObj.answer) - } catch (error) { - // + await app.MG.store.getProductDetail(query).then((res) => { + let questionArr = [] + res.datas.cmsDatas[0].datas.forEach((item, index) => { + const questionObj = { + number: index + 1, // 棰樺彿 + id: item.id, + 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, // 瑙f瀽 + 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: item.Embedded_QuestionBank_QuestionType == 'completion' || + item.Embedded_QuestionBank_QuestionType == 'multipleChoice' ? [] : '', + isSubmit: false, // 鏌ョ湅瑙f瀽 + isRight: null, // 鏄惁姝g‘ + isComplete: false, + isCollect: true } - } - // 濉┖棰樻敼閫� - 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' - } - questionObj.userAnswer[index] = '' - index++ + // 澶氶�夊拰濉┖绛旀鑲负鏁扮粍锛岃杞崲JSON鏍煎紡 + if ( + questionObj.questionType == 'completion' || + questionObj.questionType == 'multipleChoice' + ) { + try { + questionObj.answer = JSON.parse(questionObj.answer) + } catch (error) { + // } } - } - // 鑾峰彇鍥剧墖 - 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 (item.Embedded_QuestionBank_QuestionType == 'judge') { - // topicList.value.judge.data.push(questionObj) - // } else if (item.Embedded_QuestionBank_QuestionType == 'singleChoice') { - // topicList.value.radio.data.push(questionObj) - // } else if (item.Embedded_QuestionBank_QuestionType == 'multipleChoice') { - // topicList.value.check.data.push(questionObj) - // } else if (item.Embedded_QuestionBank_QuestionType == 'completion') { - // topicList.value.gap.data.push(questionObj) - // } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer') { - // topicList.value.short.data.push(questionObj) - // } - questionArr.push(questionObj) - // cardList.value[0].infoList.push(questionObj) + // 濉┖棰樻敼閫� + 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' + } + 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 (questionObj.stemStyle == 'RichText') { + // questionObj.option.txt = '' + 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"') + + } + // 閫夐」瀵屾枃鏈鐞� + if (questionObj.optionStyle == 'RichText' && (questionObj.questionType == 'singleChoice' || questionObj.questionType == 'judge' || questionObj.questionType == 'multipleChoice')) { + questionObj.option.forEach(item => { + if (item.txt) item.txt = item.txt.replace(/\<img/gi, '<img class="option-rich-img"').replace(/\<p/gi, '<p class="stem-rich-p"') + }) + } + if (item.Embedded_QuestionBank_QuestionType == 'judge') { + questionObj.type = '鍒ゆ柇棰�' + judgeArr.push(questionObj) + } else if (item.Embedded_QuestionBank_QuestionType == 'singleChoice') { + questionObj.type = '鍗曢�夐' + singleChoiceArr.push(questionObj) + } else if (item.Embedded_QuestionBank_QuestionType == 'multipleChoice') { + questionObj.type = '澶氶�夐' + multipleChoiceArr.push(questionObj) + } else if (item.Embedded_QuestionBank_QuestionType == 'completion') { + questionObj.type = '濉┖棰�' + completionArr.push(questionObj) + } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer') { + questionObj.type = '绠�绛旈' + shortArr.push(questionObj) + } + }) }) - // loadings.value = false - this.setData({ - questionDataList: questionArr, - ['cardList[0].infoList']: questionArr, - loading: false, - }) + } + this.setData({ + ['cardList[0].infoList']: singleChoiceArr, + ['cardList[1].infoList']: judgeArr, + ['cardList[2].infoList']: multipleChoiceArr, + ['cardList[3].infoList']: completionArr, + ['cardList[3].infoList']: shortArr, + }) + const cardList = this.data.cardList + for (let index = 0; index < cardList.length; index++) { + const item = cardList[index]; + for (let cindex = 0; cindex < item.infoList.length; cindex++) { + const citem = item.infoList[cindex] + citem.number = cindex + 1 + questionArr.push(citem) + } + } + this.setData({ + questionDataList: questionArr, + cardList: cardList, + loading: false }) }, // 鎴戠殑閿欓妯″紡涓嬭幏鍙栭敊棰榠d鍒楄〃 @@ -1219,12 +1320,35 @@ }, // 鑾峰彇閿欓闆� async getErrorDataList() { + // this.setData({ + // cardList: [{ + // catalogName: '閿欓闆�', + // infoList: [] + // }] + // }) this.setData({ cardList: [{ - catalogName: '閿欓闆�', + catalogName: '鍗曢�夐', + infoList: [] + }, { + catalogName: '鍒ゆ柇棰�', + infoList: [] + }, { + catalogName: '澶氶�夐', + infoList: [] + }, { + catalogName: '濉┖棰�', + infoList: [] + }, { + catalogName: '绠�绛旈', infoList: [] }] }) + let singleChoiceArr = [] // 鍗曢�� + let judgeArr = [] // 鍒ゆ柇 + let shortArr = [] // 绠�绛� + let multipleChoiceArr = [] // 澶氶�� + let completionArr = [] // 濉┖ let query = { path: '*', cmsPath: this.data.rootCmsItemId, @@ -1305,22 +1429,57 @@ if (optionItem.img) optionItem.img = getPublicImage(optionItem.img, 150) }) } - // if (item.Embedded_QuestionBank_QuestionType == 'judge') { - // topicList.value.judge.data.push(questionObj) - // } else if (item.Embedded_QuestionBank_QuestionType == 'singleChoice') { - // topicList.value.radio.data.push(questionObj) - // } else if (item.Embedded_QuestionBank_QuestionType == 'multipleChoice') { - // topicList.value.check.data.push(questionObj) - // } else if (item.Embedded_QuestionBank_QuestionType == 'completion') { - // topicList.value.gap.data.push(questionObj) - // } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer') { - // topicList.value.short.data.push(questionObj) - // } - questionArr.push(questionObj) + // 棰樺共瀵屾枃鏈鐞� + if (questionObj.stemStyle == 'RichText') { + // questionObj.option.txt = '' + 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"') + + } + // 閫夐」瀵屾枃鏈鐞� + if (questionObj.optionStyle == 'RichText' && (questionObj.questionType == 'singleChoice' || questionObj.questionType == 'judge' || questionObj.questionType == 'multipleChoice')) { + questionObj.option.forEach(item => { + if (item.txt) item.txt = item.txt.replace(/\<img/gi, '<img class="option-rich-img"').replace(/\<p/gi, '<p class="stem-rich-p"') + }) + } + if (item.Embedded_QuestionBank_QuestionType == 'judge') { + questionObj.type = '鍒ゆ柇棰�' + judgeArr.push(questionObj) + } else if (item.Embedded_QuestionBank_QuestionType == 'singleChoice') { + questionObj.type = '鍗曢�夐' + singleChoiceArr.push(questionObj) + } else if (item.Embedded_QuestionBank_QuestionType == 'multipleChoice') { + questionObj.type = '澶氶�夐' + multipleChoiceArr.push(questionObj) + } else if (item.Embedded_QuestionBank_QuestionType == 'completion') { + questionObj.type = '濉┖棰�' + completionArr.push(questionObj) + } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer') { + questionObj.type = '绠�绛旈' + shortArr.push(questionObj) + } + // questionArr.push(questionObj) }) this.setData({ + // questionDataList: questionArr, + ['cardList[0].infoList']: singleChoiceArr, + ['cardList[1].infoList']: judgeArr, + ['cardList[2].infoList']: multipleChoiceArr, + ['cardList[3].infoList']: completionArr, + ['cardList[3].infoList']: shortArr, + // loading: false + }) + const cardList = this.data.cardList + for (let index = 0; index < cardList.length; index++) { + const item = cardList[index]; + for (let cindex = 0; cindex < item.infoList.length; cindex++) { + const citem = item.infoList[cindex] + citem.number = cindex + 1 + questionArr.push(citem) + } + } + this.setData({ questionDataList: questionArr, - ['cardList[0].infoList']: questionArr, + cardList: cardList, loading: false }) }) -- Gitblit v1.9.1