From 4b5f1f7ed3460df9465e5071a59b8105cbc9146e Mon Sep 17 00:00:00 2001 From: litian <C21AF165> Date: 星期五, 29 三月 2024 14:35:30 +0800 Subject: [PATCH] 修改 --- packageBookService/pages/bookServices/examination/examination.js | 294 ++++++++++++++++++++++++++-------------------------------- 1 files changed, 132 insertions(+), 162 deletions(-) diff --git a/packageBookService/pages/bookServices/examination/examination.js b/packageBookService/pages/bookServices/examination/examination.js index d99f15b..0762452 100644 --- a/packageBookService/pages/bookServices/examination/examination.js +++ b/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,46 @@ 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) { + 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 +388,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 +401,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 +451,9 @@ }) child.openTestReportDialog() } - + this.setData({ + loading: false + }) }, // 鍒濆鍖栧嚱鏁� async init() { @@ -418,17 +465,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 +511,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 }) } } @@ -706,6 +760,18 @@ } } } + // 棰樺共瀵屾枃鏈鐞� + if (questionObj.stemStyle == 'RichText') { + // questionObj.option.txt = '' + questionObj.stem.stemTxt = questionObj.stem.stemTxt.replace(/\<img/gi, '<img 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 (questionObj.stemStyle == 'Image' || questionObj.stemStyle == 'TxtAndImage') { questionObj.stem.stemImage = getPublicImage(questionObj.stem.stemImage, 150) @@ -764,6 +830,8 @@ }) }) } + // 鏈夐鐩啀寮�濮嬪�掕鏃� + if (this.data.questionDataList.length) this.startCountdown() this.setData({ loading: false }) @@ -771,7 +839,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 +1457,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, // 瑙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: 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: '' // 鎺у埗瑙f瀽鐨勬姌鍙犻潰鏉挎槸鍚﹀睍寮� - // } - // // 澶氶�夊拰濉┖绛旀鑲负鏁扮粍锛岃杞崲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 +1517,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: '' // 鎺у埗瑙f瀽鐨勬姌鍙犻潰鏉挎槸鍚﹀睍寮� } @@ -1611,6 +1546,17 @@ index++ } } + } + // 棰樺共瀵屾枃鏈鐞� + if (questionObj.stemStyle == 'RichText') { + // questionObj.option.txt = '' + questionObj.stem.stemTxt = questionObj.stem.stemTxt.replace(/\<img/gi, '<img class="stem-rich-img"') + } + // 閫夐」瀵屾枃鏈鐞� + 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"') + }) } // 鑾峰彇鍥剧墖 if (questionObj.stemStyle == 'Image' || questionObj.stemStyle == 'TxtAndImage') { @@ -1650,10 +1596,9 @@ questionDataList: questionList, cardList: cardUpdatedList }) - console.log('缁勫嵎棰樼洰鍒楄〃', this.data.questionDataList); }) }) - }) + } this.setData({ loading: false }) @@ -1783,5 +1728,30 @@ }) console.log('妯¤�冪瓟棰樻暟鎹凡璁板綍') }) + }, + + // 瀵屾枃鏈鐞� + formatRichText(html) { + console.log(html); + let newContent = html.replace(/<img[^>]*>/gi, function (match, capture) { + match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, ''); + match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, ''); + match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, ''); + return match; + }); + newContent = newContent.replace(/style="[^"]+"/gi, function (match, capture) { + match = match + .replace(/<p>/gi, '<p class="p_class">') + .replace(/width:[^;]+;/gi, 'max-width:100%;') + .replace(/width:[^;]+;/gi, 'max-width:100%;'); + return match; + }); + newContent = newContent.replace(/<br[^>]*\/>/gi, ""); + newContent = newContent.replace(/<a>/gi, '<a class="p_class "'); + newContent = newContent.replace(/<li>/gi, '<li class="p_class "'); + newContent = newContent.replace(/\<p/gi, '<p class="p_class "'); + newContent = newContent.replace(/\<span/gi, '<span class="p_class "'); + newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;margin-top:0;margin-bottom:0;"'); + return newContent; } }) \ No newline at end of file -- Gitblit v1.9.1