From 253245731d2b0c5ea4994a9c4e17ad6b60136f2c Mon Sep 17 00:00:00 2001 From: 闫增涛 <1829501689@qq.com> Date: 星期二, 09 四月 2024 15:38:26 +0800 Subject: [PATCH] 答题器提交功能优化 --- packageBookService/pages/bookServices/examination/examination.js | 299 +++++++++++++++++++++++++++-------------------------------- 1 files changed, 139 insertions(+), 160 deletions(-) diff --git a/packageBookService/pages/bookServices/examination/examination.js b/packageBookService/pages/bookServices/examination/examination.js index 108f1e6..f3924ad 100644 --- a/packageBookService/pages/bookServices/examination/examination.js +++ b/packageBookService/pages/bookServices/examination/examination.js @@ -1,4 +1,6 @@ -import { getPublicImage } from "../../../../assets/js/middleGround/tool"; +import { + getPublicImage +} from "../../../../assets/js/middleGround/tool"; const app = getApp(); Page({ /** @@ -193,6 +195,12 @@ }, }); }, + // 鏀瑰彉loading鐘舵�� + changeLoadingState() { + this.setData({ + loading: true + }) + }, // 杩斿洖鎷︽埅 beforeleave() { wx.showModal({ @@ -201,8 +209,7 @@ confirmColor: "#ff6c00", cancelColor: "#949494", complete: (res) => { - if (res.cancel) { - } + if (res.cancel) {} if (res.confirm) { this.setData({ submitStatus: true, @@ -456,6 +463,7 @@ loading: true, }); const child = this.selectComponent("#question-options"); + debugger if ( this.data.answerType == "option" || this.data.answerType == "errorQuestion" || @@ -505,16 +513,14 @@ }); } app.MG.identity.setUserKey({ - setKeyRequests: [ - { - domain: "mockAnswerData", - key: this.data.uuid, - value: JSON.stringify({ - time: this.data.countdownTime, - answerData: saveData, - }), - }, - ], + setKeyRequests: [{ + domain: "mockAnswerData", + key: this.data.uuid, + value: JSON.stringify({ + time: this.data.countdownTime, + answerData: saveData, + }), + }, ], }); child.openTestReportDialog(); } @@ -633,16 +639,14 @@ // 缁勫嵎妯″紡 // 娓呯┖绛旈璁板綍 await app.MG.identity.setUserKey({ - setKeyRequests: [ - { - domain: "mockAnswerData", - key: this.data.uuid, - value: JSON.stringify({ - time: this.data.countdownTime, - answerData: [], - }), - }, - ], + setKeyRequests: [{ + domain: "mockAnswerData", + key: this.data.uuid, + value: JSON.stringify({ + time: this.data.countdownTime, + answerData: [], + }), + }, ], }); this.init(); } else { @@ -783,34 +787,26 @@ // num: index, // 棰樺彿 id: item.id, type: pathitem.name, - stem: - item.Embedded_QuestionBank_QuestionType == "completion" - ? JSON.parse(item.Embedded_QuestionBank_Stem) - .stemTxt.replaceAll("<vacancy>", ",input,") - .split(",") - : JSON.parse(item.Embedded_QuestionBank_Stem), // 棰樺共 + 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) - : "", // 閫夋嫨棰橀�夐」 + 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.userAnswer - : item.Embedded_QuestionBank_QuestionType == "completion" || - item.Embedded_QuestionBank_QuestionType == "multipleChoice" - ? [] - : "", + difficulty: item.Embedded_QuestionBank_Difficulty ? + 4 - item.Embedded_QuestionBank_Difficulty : 0, // 闅惧害绛夌骇 + userAnswer: oldObj ? + oldObj.userAnswer : 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, - isCollect: - this.data.collectList.indexOf(item.id) > -1 ? true : false, + isCollect: this.data.collectList.indexOf(item.id) > -1 ? true : false, isUnfold: "", // 鎺у埗瑙f瀽鐨勬姌鍙犻潰鏉挎槸鍚﹀睍寮� }; // 澶氶�夊拰濉┖绛旀鑲负鏁扮粍锛岃杞崲JSON鏍煎紡 @@ -859,8 +855,8 @@ 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"'); + .replace(/\<img/gi, '<img class="option-rich-img"') + .replace(/\<p/gi, '<p class="stem-rich-p"'); }); } // 瑙f瀽瀵屾枃鏈鐞� @@ -1047,13 +1043,11 @@ // 璁板綍閿欓 app.MG.identity .setUserKey({ - setKeyRequests: [ - { - domain: "errorData", - key: this.data.rootCmsItemId, - value: JSON.stringify(this.data.errorList), - }, - ], + setKeyRequests: [{ + domain: "errorData", + key: this.data.rootCmsItemId, + value: JSON.stringify(this.data.errorList), + }, ], }) .then((res) => { console.log(res); @@ -1111,13 +1105,11 @@ } app.MG.identity .setUserKey({ - setKeyRequests: [ - { - domain: "collectData", - key: this.data.rootCmsItemId, - value: JSON.stringify(this.data.collectList), - }, - ], + setKeyRequests: [{ + domain: "collectData", + key: this.data.rootCmsItemId, + value: JSON.stringify(this.data.collectList), + }, ], }) .then((res) => {}); }, @@ -1156,17 +1148,15 @@ setAnswerInfo(data) { app.MG.identity .setUserKey({ - setKeyRequests: [ - { - domain: "answerData", - key: this.data.productLinkPath, - value: JSON.stringify(data), - }, - ], + setKeyRequests: [{ + domain: "answerData", + key: this.data.productLinkPath, + value: JSON.stringify(data), + }, ], }) .then((res) => {}); }, - // 鑾峰彇绛旈鏁版嵁 + // 鑾峰彇鏃х瓟棰樻暟鎹� getAnswerInfo(callback) { app.MG.identity .getUserKey({ @@ -1177,7 +1167,7 @@ if (callback) callback(res); }); }, - // 鍒犻櫎绛旈鏁版嵁 + // 鍒犻櫎鏃х瓟棰樻暟鎹� delAnswerInfo(callback) { app.MG.identity .delUserKey({ @@ -1230,8 +1220,7 @@ async getCollectDataList() { let questionArr = []; this.setData({ - cardList: [ - { + cardList: [{ catalogName: "鍗曢�夐", infoList: [], }, @@ -1285,28 +1274,21 @@ 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), // 棰樺共 + 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) - : "", // 閫夋嫨棰橀�夐」 + 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" - ? [] - : "", + 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, @@ -1377,9 +1359,19 @@ 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"'); + .replace(/\<img/gi, '<img class="option-rich-img"') + .replace(/\<p/gi, '<p class="stem-rich-p"'); }); + } + // 瑙f瀽瀵屾枃鏈鐞� + if ( + questionObj.analysisCon && + typeof questionObj.analysisCon == "string" + ) { + questionObj.analysisCon = questionObj.analysisCon.replace( + /\<img/gi, + '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" ' + ); } if (item.Embedded_QuestionBank_QuestionType == "judge") { questionObj.type = "鍒ゆ柇棰�"; @@ -1467,8 +1459,7 @@ // 鑾峰彇閿欓闆� async getErrorDataList() { this.setData({ - cardList: [ - { + cardList: [{ catalogName: "鍗曢�夐", infoList: [], }, @@ -1520,28 +1511,21 @@ 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), // 棰樺共 + 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) - : "", // 閫夋嫨棰橀�夐」 + 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" - ? [] - : "", + 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, @@ -1614,9 +1598,19 @@ 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"'); + .replace(/\<img/gi, '<img class="option-rich-img"') + .replace(/\<p/gi, '<p class="stem-rich-p"'); }); + } + // 瑙f瀽瀵屾枃鏈鐞� + if ( + questionObj.analysisCon && + typeof questionObj.analysisCon == "string" + ) { + questionObj.analysisCon = questionObj.analysisCon.replace( + /\<img/gi, + '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" ' + ); } if (item.Embedded_QuestionBank_QuestionType == "judge") { questionObj.type = "鍒ゆ柇棰�"; @@ -1798,35 +1792,27 @@ 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), // 棰樺共 + 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) - : "", // 閫夋嫨棰橀�夐」 + 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, + 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.answer) : false, isRight: oldObj ? oldObj.isRight : null, // isComplete: oldObj ? oldObj.isComplete : false, isComplete: this.data.mockData.state == "3" ? true : false, - isCollect: - this.data.collectList.indexOf(item.id) > -1 ? true : false, + isCollect: this.data.collectList.indexOf(item.id) > -1 ? true : false, isUnfold: "", // 鎺у埗瑙f瀽鐨勬姌鍙犻潰鏉挎槸鍚﹀睍寮� }; // 澶氶�夊拰濉┖绛旀鑲负鏁扮粍锛岃杞崲JSON鏍煎紡 @@ -1957,26 +1943,22 @@ // 璁板綍璐拱缁勫嵎鏃堕棿 setMockInfo(data) { app.MG.identity.setUserKey({ - setKeyRequests: [ - { - domain: "mockData", - key: this.data.bookId + "", - value: JSON.stringify(data), - }, - ], + 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), - }, - ], + setKeyRequests: [{ + domain: "mockQuestionData", + key: this.data.uuid, + value: JSON.stringify(data), + }, ], }) .then((res) => { console.log("妯¤�冮鐩垪琛ㄥ凡璁板綍"); @@ -2008,9 +1990,8 @@ 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, + 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)); @@ -2054,17 +2035,15 @@ // app.MG.identity .setUserKey({ - setKeyRequests: [ - { - domain: "mockAnswerData", - key: this.data.uuid, - value: JSON.stringify({ - currentIndex: this.data.currentIndex, - time: this.data.countdownTime, - answerData: saveData, - }), - }, - ], + setKeyRequests: [{ + domain: "mockAnswerData", + key: this.data.uuid, + value: JSON.stringify({ + currentIndex: this.data.currentIndex, + time: this.data.countdownTime, + answerData: saveData, + }), + }, ], }) .then((res) => { this.setData({ @@ -2110,4 +2089,4 @@ ); return newContent; }, -}); +}); \ No newline at end of file -- Gitblit v1.9.1