From 81b30e7fb0763bce403431f0c1f64d5a9e36dfb2 Mon Sep 17 00:00:00 2001 From: litian <C21AF165> Date: 星期三, 20 三月 2024 15:42:13 +0800 Subject: [PATCH] Merge refs/remotes/origin/master into refs/heads/master --- packageBookService/pages/bookServices/examination/examination.js | 532 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 504 insertions(+), 28 deletions(-) diff --git a/packageBookService/pages/bookServices/examination/examination.js b/packageBookService/pages/bookServices/examination/examination.js index a880c26..d948903 100644 --- a/packageBookService/pages/bookServices/examination/examination.js +++ b/packageBookService/pages/bookServices/examination/examination.js @@ -29,6 +29,19 @@ total: 0, // 棰樼洰鎬绘暟 cardList: [], // 鎻愪氦椤�, questionDataList: [], // 鏄剧ず棰樼洰鍒楄〃 + mockid: 0, + uuid: 0, + mockData: { + // 缁勫嵎淇℃伅 + state: '0', + score: 0, // 鎬诲垎 + sumTime: 0, + time: 0, // 绛旈鍓╀綑鏃堕棿 + datas: [], // 鎵�鏈夋ā鑰冭褰曟暟鎹�(棰樼洰鍒楄〃锛岀敤鎴风瓟棰橈紝鑰冭瘯鎶ュ憡) + answer: [] + }, + saveTime: 20, + isNight: false }, /** @@ -46,8 +59,14 @@ productLinkPath: options.productLinkPath ? options.productLinkPath : '', rootCmsItemId: options.rootCmsItemId, idPathList: options.idPathList ? JSON.parse(options.idPathList) : [], - answerType: options.answerType + answerType: options.answerType, }); + if (this.data.answerType == 'mock') { + this.setData({ + uuid: options.uuid, + mockid: options.mockid + }) + } this.init() console.log('浼犲弬', options); }, @@ -63,7 +82,19 @@ * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず */ onShow() { - + if (this.data.answerType == 'mock') { + if (wx.timer) { + clearInterval(wx.timer) + } + wx.timer = setInterval(() => { + this.setData({ + saveTime: this.data.saveTime - 1 + }) + if (this.data.saveTime == 0) { + this.saveMockData() + } + }, 1000) + } }, /** @@ -105,7 +136,12 @@ goBack() { wx.navigateBack(); }, - + //璁剧疆鑳屾櫙鑹� + changeBGColor(e) { + this.setData({ + isNight: e.detail.value + }) + }, // 鑾峰彇淇濆瓨鐨勫�掕鏃舵椂闂� getSavedTime() { const savedTime = wx.getStorageSync('countdownTime') @@ -172,7 +208,6 @@ }, // 鐐瑰嚮绛旈鍗¤烦杞鐩� goQuestion(e) { - console.log(e); const id = e.detail.id this.data.questionDataList.forEach((item, index) => { if (item.id == id) { @@ -191,12 +226,17 @@ questionList.forEach(item => { if (item.id == id) { item.userAnswer = radioChecked + item.isUserAnswer = this.isHaveAnswer(radioChecked) } }) this.setData({ questionDataList: questionList }) - console.log(this.data.questionDataList); + if (this.data.answerType == 'mock') { + this.setData({ + saveTime: 20 + }) + } }, // 杈撳叆妗嗚Е鍙� onChangeInput(e) { @@ -206,13 +246,18 @@ const questionList = this.data.questionDataList questionList.forEach(item => { if (item.id == id) { - item.userAnswer[index] = inputData + item.userAnswer[index] = inputData, + item.isUserAnswer = this.isHaveAnswer(item.userAnswer) } }) this.setData({ questionDataList: questionList }) - console.log(this.data.questionDataList); + if (this.data.answerType == 'mock') { + this.setData({ + saveTime: 20 + }) + } }, // 鏁扮粍杞负瀛楃涓叉柟娉� arrayToString(data) { @@ -251,23 +296,61 @@ this.setData({ submitStatus: true }) + const child = this.selectComponent('#question-options') + if (this.data.answerType == 'option' || this.data.answerType == 'errorQuestion' || this.data.answerType == 'mock') { + // 鍏堥亶鍘嗘墍鏈夐鐩紝灏嗘湭鎵规敼鐨勯鐩壒鏀� + 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 (this.data.answerType == 'option') { this.toggleCountdown() - const child = this.selectComponent('#question-options') - if (this.data.answerType == 'option' || this.data.answerType == 'errorQuestion') { - // 鍏堥亶鍘嗘墍鏈夐鐩紝灏嗘湭鎵规敼鐨勯鐩壒鏀� - 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 (this.data.answerType == 'option') { - this.recordAnswerData() - child.openTestReportDialog() - } + this.recordAnswerData() + child.openTestReportDialog() } else if (this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') { this.goBack() + } else if (this.data.answerType == 'mock') { + this.toggleCountdown() + // 璁剧疆妯¤�冪姸鎬佷负宸插畬鎴� + const mockData = this.data.mockData + mockData.datas.forEach((item) => { + if (item.id == this.data.uuid) { + item.state = '3' + item.report = { + userScore: this.data.subjectiveNum + } + } + }) + this.setData({ + mockData: mockData, + submitStatus: true + }) + this.setMockInfo(mockData.datas) + // 璁板綍鐢ㄦ埛绛旈鏁版嵁 + let saveData = [] + for (let index = 0; index < this.data.questionDataList.length; index++) { + const item = this.data.questionDataList[index]; + saveData.push({ + id: item.id, + answer: item.userAnswer, + isRight: item.isRight + }) + } + app.MG.identity.setUserKey({ + setKeyRequests: [ + { + domain: 'mockAnswerData', + key: this.data.uuid, + value: JSON.stringify({ + time: this.data.countdownTime, + answerData: saveData + }) + } + ] + }) + child.openTestReportDialog() } }, @@ -296,6 +379,47 @@ // loadings.value = true await this.getErrorIdList() await this.getCollectIdList() // 鑾峰彇鏀惰棌id鍒楄〃 + } else if (this.data.answerType == 'mock') { + this.getErrorList() + this.getCollectIdList() + this.getMockInfo(async (res) => { + let mocklist + try { + mocklist = JSON.parse(res[0].value) + } catch (error) { + mocklist = [] + } + if (mocklist.length && this.data.uuid) { + const oldMockData = mocklist.find((mockItem) => mockItem.id == this.data.uuid) + this.setData({ + 'mockData.state': oldMockData.state, + 'mockData.score': oldMockData.score, + 'mockData.datas': mocklist, + }) + if (oldMockData.state == '0') { + // 缁勫嵎璐拱浜嗭紝浣嗘湭杩涘叆椤甸潰 + await this.getEduQuizConfig() + } else if (oldMockData.state == '1' || oldMockData.state == '2' || oldMockData.state == '3') { + // 缁勫嵎鍚庤繘鍏ヨ繃椤甸潰锛屼絾鏄湭绛旇繃棰� + let oldQuestionList = [] + oldQuestionList = await this.getMockQuestionList() + const userAnswerList = await this.getMockAnswer() + await this.getMockDataList(oldQuestionList, userAnswerList) + this.setData({ + 'mockData.sumTime': oldMockData.time, + cardList: oldQuestionList + }) + } + if (oldMockData.state == '0' || oldMockData.state == '1' || oldMockData.state == '2') { + this.startCountdown() + } + if (oldMockData.state == '3') { + this.setData({ + submitStatus: true + }) + } + } + }) } }, async restart() { @@ -327,9 +451,9 @@ setKeyRequests: [ { domain: 'mockAnswerData', - key: route.query.uuid, + key: this.data.uuid, value: JSON.stringify({ - time: countDownRef.value.countdownTime, + time: this.data.countdownTime, answerData: [] }) } @@ -492,6 +616,7 @@ item.Embedded_QuestionBank_QuestionType == 'multipleChoice' ? [] : '', + isUserAnswer: oldObj ? this.isHaveAnswer(oldObj.userAnswer) : false, isRight: oldObj ? oldObj.isRight : null, isComplete: oldObj ? oldObj.isComplete : false, isCollect: this.data.collectList.indexOf(item.id) > -1 ? true : false, @@ -573,7 +698,7 @@ aitem.infoList.forEach((bitem, bindex) => { questionList.push(bitem) bitem.number = bindex + 1 - bitem.grade = 2 + bitem.score = 2 }) }) this.setData({ @@ -635,13 +760,13 @@ if (item.questionType != 'shortAnswer') { this.setData({ subjectiveTotal: this.data.subjectiveTotal + 1, - subjectiveGrade: this.data.subjectiveGrade + item.grade + subjectiveGrade: this.data.subjectiveGrade + item.score }) } if (questionList[index].isRight && item.questionType != 'shortAnswer') { // 瀹㈣棰樺洖绛旀纭� this.setData({ - subjectiveNum: this.data.subjectiveNum + item.grade, + subjectiveNum: this.data.subjectiveNum + item.score, correctNum: this.data.correctNum + 1 }) } @@ -675,6 +800,7 @@ console.log(res) }) } + this.setData({ questionDataList: questionList }) @@ -689,7 +815,6 @@ this.setData({ cardList: cardUpdatedList }) - // console.log(this.data.questionDataList, this.data.cardList); }, // 棰樼洰鏀惰棌鎸夐挳,鏀惰棌鍜屽彇娑堝悓涓�鎺ュ彛锛屽彇娑堟暟缁勫噺鍘昏椤筰d setCollect() { @@ -841,7 +966,6 @@ } }) } - // console.log('鏀惰棌', collectList.value) }) }, // 鑾峰彇鏀惰棌澶� @@ -1118,6 +1242,358 @@ }) }) // loadings.value = false - // console.log('閿欓闆�', topicList.value) + }, + // 鑾峰彇缁勫嵎缁撴灉 + async getEduQuizConfig() { + await app.MG.edu + .getEduQuizConfigResult({ + idOrRefCode: this.data.mockid + }) + .then(async (configRes) => { + // 鑾峰彇 鍒嗘暟 鏃堕棿 + this.setData({ + 'mockData.score': configRes.score + }) + try { + this.setData({ + 'mockData.time': JSON.parse(configRes.config).time * 1000, + countdownTime: JSON.parse(configRes.config).time * 1000 + }) + } catch (error) { + this.setData({ + 'mockData.time': 3600 * 1000, + countdownTime: 3600 * 1000, + }) + } + this.setData({ + 'mockData.sumTime': this.data.mockData.time + }) + let itemIds = [] + let numberIndex = 1 + // 鑾峰彇鎶介缁撴灉 + const cardList = configRes.eduQuizConfigStageResultList.map((item) => { + let questionIds = [] + // 鑾峰彇蹇呭惈棰樼洰 + let list = item.cmsItemList.map((idItem) => { + itemIds.push(idItem.id + '') + questionIds.push({ id: idItem.id + '', score: idItem.score }) + numberIndex++ + return { + number: numberIndex, + id: idItem.id, + score: idItem.score + } + }) + // 鑾峰彇鎶介棰樼洰 + let extractList = [] + for (let i = 0; i < item.generatorResultList.length; i++) { + const extractItem = item.generatorResultList[i] + let extractItemList = extractItem.cmsItemList.map((extractCmsItem) => { + itemIds.push(extractCmsItem.id + '') + questionIds.push({ id: extractCmsItem.id + '', score: extractCmsItem.score }) + numberIndex++ + return { + number: numberIndex, + id: extractCmsItem.id, + score: extractCmsItem.score + } + }) + extractList = extractList.concat(extractItemList) + } + return { + path: item.id, + catalogName: item.name, + infoList: list.concat(extractList) + } + }) + this.setData({ + cardList: cardList + }) + // 鏇存柊璇ユ潯缁勫嵎鐨勬暟鎹姸鎬侊紝鍖呮嫭璁板綍鏀硅瘯鍗锋�诲垎锛屾洿鏀圭粍鍗风姸鎬乻tate涓�1锛岃〃绀哄凡缁忔娊棰樺畬鎴愶紝骞惰灏嗘娊灞夋暟鎹褰曚笅鏉� + if (this.data.mockData.datas && this.data.mockData.datas.length) { + const mockData = this.data.mockData + mockData.datas.forEach((item, index) => { + if (item.id == this.data.uuid) { + item.state = '1' + item.time = mockData.time + item.score = configRes.score + mockData.state = '1' + } + }) + this.setData({ + mockData: mockData + }) + } + this.setMockInfo(this.data.mockData.datas) // 璁板綍璇曞嵎鎬诲垎 鏃堕暱锛屼慨鏀箂tate涓� 1 + // 鏇存柊鏈湴mockData + this.saveMockQuestionList(this.data.cardList) // 璁板綍棰樼洰鍒楄〃 + await this.getMockDataList(this.data.cardList) // 璇锋眰棰樼洰鏁版嵁 + }) + }, + // 鑾峰彇缁勫嵎棰樼洰鍒楄〃 + async getMockDataList(questionList, oldList) { + console.log(questionList, oldList); + const questionDataList = this.data.questionDataList + questionList.forEach(async (pathitem, 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) + 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 + // if (flag == this.data.idPathList.length) { + cardUpdatedList.forEach(aitem => { + aitem.infoList.forEach((bitem, bindex) => { + questionList.push(bitem) + bitem.number = bindex + 1 + }) + }) + this.setData({ + questionDataList: questionList, + cardList: cardUpdatedList + }) + }) + }) + }) + this.setData({ + // questionDataList: questionDataList, + loading: false + }) + }, + // 鑾峰彇缁勫嵎鏁版嵁 + getMockInfo(callback) { + app.MG.identity + .getUserKey({ + domain: 'mockData', + keys: [this.data.bookId] + }) + .then((res) => { + if (callback) callback(res) + }) + }, + // 璁板綍璐拱缁勫嵎鏃堕棿 + setMockInfo(data) { + app.MG.identity.setUserKey({ + setKeyRequests: [ + { + domain: 'mockData', + key: this.data.bookId + '', + value: JSON.stringify(data) + } + ] + }) + }, + // 璁板綍缁勫嵎棰樼洰鍒楄〃 + saveMockQuestionList(data) { + app.MG.identity + .setUserKey({ + setKeyRequests: [ + { + domain: 'mockQuestionData', + key: this.data.uuid, + value: JSON.stringify(data) + } + ] + }) + .then((res) => { + console.log('妯¤�冮鐩垪琛ㄥ凡璁板綍') + }) + }, + // 鑾峰彇璁板綍缁勫嵎棰樼洰鍒楄〃 + async getMockQuestionList() { + let list = [] + await app.MG.identity + .getUserKey({ + domain: 'mockQuestionData', + keys: [this.data.uuid] + }) + .then((res) => { + list = JSON.parse(res[0].value) + }) + return list + }, + // 鑾峰彇妯¤�冪敤鎴风瓟棰樻暟鎹� + async getMockAnswer() { + let data + await app.MG.identity + .getUserKey({ + domain: 'mockAnswerData', + keys: [this.data.uuid] + }) + .then((res) => { + if (res[0]) { + this.setData({ + currentIndex: JSON.parse(res[0].value).currentIndex, + 'mockData.time': JSON.parse(res[0].value).time, + countdownTime: JSON.parse(res[0].value).time ? JSON.parse(res[0].value).time : this.data.mockData.sumTime, + 'mockData.answer': JSON.parse(res[0].value).answerData + }) + console.log(JSON.parse(res[0].value)); + data = JSON.parse(res[0].value).answerData + } + }) + return data + }, + + // 璁板綍妯¤�冪瓟棰樻暟鎹� + saveMockData() { + const data = this.data.mockData.datas.find((itme) => itme.id == this.data.uuid) + if (data.state == '3') return true + const saveData = this.data.mockData.answer + for (let i = 0; i < this.data.questionDataList.length; i++) { + const item = this.data.questionDataList[i] + if (this.isHaveAnswer(item.userAnswer)) { + const index = saveData.findIndex((saveitem) => saveitem.id == item.id) + if (index + '' != '-1') { + saveData[index].answer = item.userAnswer + } else { + saveData.push({ + id: item.id, + answer: item.userAnswer + }) + } + } + } + // + if (this.data.mockData.state == '1') { + const datas = this.data.mockData.datas + datas.forEach((item) => { + if (item.id == this.data.uuid) { + item.state = '2' + } + }) + this.setMockInfo(datas) + } + // + app.MG.identity + .setUserKey({ + setKeyRequests: [ + { + domain: 'mockAnswerData', + key: this.data.uuid, + value: JSON.stringify({ + currentIndex: this.data.currentIndex, + time: this.data.countdownTime, + answerData: saveData + }) + } + ] + }) + .then((res) => { + this.setData({ + saveTime: 20 + }) + console.log('妯¤�冪瓟棰樻暟鎹凡璁板綍') + }) } }) \ No newline at end of file -- Gitblit v1.9.1