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 | 330 ++++++++++++++++++++++++++---------------------------- 1 files changed, 160 insertions(+), 170 deletions(-) diff --git a/packageBookService/pages/bookServices/examination/examination.js b/packageBookService/pages/bookServices/examination/examination.js index d864f29..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({ /** @@ -50,15 +52,6 @@ * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 */ onLoad(options) { - // wx.enableAlertBeforeUnload({ - // message: "鏈彁浜わ紝鏄惁閫�鍑虹瓟棰橈紵", - // success: function (res) { - // console.log('纭畾', res); - // }, - // fail: function (err) { - // console.log("澶辫触锛�", err); - // }, - // }); const systInfo = wx.getSystemInfoSync(); const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅 const navBarHeight = @@ -199,6 +192,30 @@ const oldVal = value; // 璁板綍灞炴�х殑鏃у�� value = newVal; // 鏇存柊灞炴�х殑鍊� callback.call(context, newVal, oldVal); // 璋冪敤鍥炶皟鍑芥暟锛屼紶閫掓柊鍊煎拰鏃у�� + }, + }); + }, + // 鏀瑰彉loading鐘舵�� + changeLoadingState() { + this.setData({ + loading: true + }) + }, + // 杩斿洖鎷︽埅 + beforeleave() { + wx.showModal({ + title: "鎻愮ず", + content: "鏈彁浜わ紝鏄惁閫�鍑虹瓟棰�", + confirmColor: "#ff6c00", + cancelColor: "#949494", + complete: (res) => { + if (res.cancel) {} + if (res.confirm) { + this.setData({ + submitStatus: true, + }); + wx.navigateBack(); + } }, }); }, @@ -441,13 +458,12 @@ }, // 鎻愪氦閫昏緫 submitPaper() { - // 鍏抽棴閫�鍑洪〉闈㈢洃鍚� - wx.disableAlertBeforeUnload(); this.setData({ submitStatus: true, loading: true, }); const child = this.selectComponent("#question-options"); + debugger if ( this.data.answerType == "option" || this.data.answerType == "errorQuestion" || @@ -497,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(); } @@ -625,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 { @@ -669,7 +681,6 @@ let value = JSON.parse(res[0].value); // 鏈夌瓟棰樿褰曪紝寰楀垎璧嬪�� if (value) { - wx.disableAlertBeforeUnload(); this.setData({ submitStatus: true, }); @@ -776,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鏍煎紡 @@ -852,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瀽瀵屾枃鏈鐞� @@ -1040,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); @@ -1104,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) => {}); }, @@ -1149,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({ @@ -1170,7 +1167,7 @@ if (callback) callback(res); }); }, - // 鍒犻櫎绛旈鏁版嵁 + // 鍒犻櫎鏃х瓟棰樻暟鎹� delAnswerInfo(callback) { app.MG.identity .delUserKey({ @@ -1203,6 +1200,8 @@ wx.showModal({ title: "鎻愮ず", content: "鏀惰棌澶规殏鏃犳暟鎹�", //editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭 + confirmColor: "#ff6c00", + cancelColor: "#949494", editable: false, //鏄惁鏄剧ず杈撳叆妗� showCancel: false, success: (res) => { @@ -1221,8 +1220,7 @@ async getCollectDataList() { let questionArr = []; this.setData({ - cardList: [ - { + cardList: [{ catalogName: "鍗曢�夐", infoList: [], }, @@ -1276,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, @@ -1368,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 = "鍒ゆ柇棰�"; @@ -1439,6 +1440,8 @@ wx.showModal({ title: "鎻愮ず", content: "閿欓闆嗘殏鏃犳暟鎹�", //editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭 + confirmColor: "#ff6c00", + cancelColor: "#949494", editable: false, //鏄惁鏄剧ず杈撳叆妗� showCancel: false, success: (res) => { @@ -1456,8 +1459,7 @@ // 鑾峰彇閿欓闆� async getErrorDataList() { this.setData({ - cardList: [ - { + cardList: [{ catalogName: "鍗曢�夐", infoList: [], }, @@ -1509,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, @@ -1603,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 = "鍒ゆ柇棰�"; @@ -1787,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鏍煎紡 @@ -1946,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("妯¤�冮鐩垪琛ㄥ凡璁板綍"); @@ -1997,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)); @@ -2043,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({ @@ -2099,4 +2089,4 @@ ); return newContent; }, -}); +}); \ No newline at end of file -- Gitblit v1.9.1