From f1e20feafa89c8d50af5e69c0333a9efc239ee49 Mon Sep 17 00:00:00 2001 From: 闫增涛 <1829501689@qq.com> Date: 星期一, 01 四月 2024 14:09:11 +0800 Subject: [PATCH] 图书详情页bug修改,我的错题、收藏模式下答题卡添加题目类型,非单选题添加查看解析按钮 --- packageBookService/pages/bookServices/examination/examination.js | 642 ++++++++++++++++++++++++++++++++++++---------------------- 1 files changed, 400 insertions(+), 242 deletions(-) diff --git a/packageBookService/pages/bookServices/examination/examination.js b/packageBookService/pages/bookServices/examination/examination.js index 9b5823d..c90f3bc 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({ @@ -9,26 +11,26 @@ barHeight: "", navBarHeight: "", loading: false, - answerTitle: "", // 瀵艰埅鏍忔爣棰� - countdownInterval: null, // 璁℃椂鍣� + answerTitle: "", // 瀵艰埅鏍忔爣棰� + countdownInterval: null, // 璁℃椂鍣� isCountdownRunning: true, // 鏄惁鍊掕鏃� - countdownTime: 0, // 鍊掕鏃舵椂闂� + countdownTime: 0, // 鍊掕鏃舵椂闂� bookId: "", productLinkPath: "", rootCmsItemId: "", - idPathList: [], // 棰樼洰鍒楄〃 - answerType: "", // 绛旈妯″紡 - submitStatus: false, // 鎻愪氦鐘舵�� + idPathList: [], // 棰樼洰鍒楄〃 + answerType: "", // 绛旈妯″紡 + submitStatus: false, // 鎻愪氦鐘舵�� currentIndex: 0, // 褰撳墠鏄剧ず鐨勯鍙� - collectList: [], // 鏀惰棌棰樼洰鍒楄〃 - errorList: [], // 閿欓鍒楄〃 - subjectiveTotal: 0, // 瀹㈣棰樻�绘暟 + collectList: [], // 鏀惰棌棰樼洰鍒楄〃 + errorList: [], // 閿欓鍒楄〃 + subjectiveTotal: 0, // 瀹㈣棰樻�绘暟 subjectiveNum: 0, // 瀹㈣棰樺緱鍒� subjectiveGrade: 0, // 瀹㈣棰樻�诲垎 - correctNum: 0, // 姝g‘棰樼洰鏁伴噺 - total: 0, // 棰樼洰鎬绘暟 - cardList: [], // 鎻愪氦椤�, - questionDataList: [], // 鏄剧ず棰樼洰鍒楄〃 + correctNum: 0, // 姝g‘棰樼洰鏁伴噺 + total: 0, // 棰樼洰鎬绘暟 + cardList: [], // 鎻愪氦椤�, + questionDataList: [], // 鏄剧ず棰樼洰鍒楄〃 mockid: 0, uuid: 0, mockData: { @@ -84,8 +86,7 @@ /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚 */ - onReady() { - }, + onReady() {}, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず @@ -149,8 +150,7 @@ /** * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜� */ - onShareAppMessage() { - }, + onShareAppMessage() {}, // 鐩戝惉watch watch(context, variableName, callback) { @@ -246,10 +246,18 @@ this.setData({ currentIndex: 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) + } + }, + // 鎴戠殑閿欓锛屾敹钘忔煡鐪嬭В鏋愭寜閽� + viewParsing() { 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) + const item = this.data.questionDataList[this.data.currentIndex] + if (!item.isComplete) this.handleQuestion(this.data.currentIndex) } }, // 鐐瑰嚮绛旈鍗¤烦杞鐩� @@ -269,21 +277,45 @@ 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) { + this.handleQuestion(this.data.currentIndex) + } } - }) + } + // 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 @@ -362,7 +394,6 @@ }, // 鎻愪氦閫昏緫 submitPaper() { - // 鍏抽棴閫�鍑洪〉闈㈢洃鍚� wx.disableAlertBeforeUnload() this.setData({ @@ -375,7 +406,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') { @@ -412,16 +443,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() } @@ -439,13 +468,13 @@ }) 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鍒楄〃 + await this.getErrorList() // 鑾峰彇閿欓id鍒楄〃 } else if (this.data.answerType == 'collectQuestion') { this.setData({ submitStatus: true @@ -472,7 +501,6 @@ } if (mocklist.length && this.data.uuid) { const oldMockData = mocklist.find((mockItem) => mockItem.id == this.data.uuid) - debugger this.setData({ 'mockData.state': oldMockData.state, 'mockData.score': oldMockData.score, @@ -531,16 +559,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 { @@ -563,8 +589,7 @@ this.setData({ collectList: JSON.parse(res[0].value) }) - } catch (error) { - } + } catch (error) {} if (this.data.answerType == 'option') { // 鍏堣幏鍙栫敤鎴风瓟棰樿褰� this.getAnswerInfo(async (res) => { @@ -612,8 +637,7 @@ this.setData({ errorList: JSON.parse(res[0].value) }) - } catch (error) { - } + } catch (error) {} }) }, // 鑾峰彇棰樺簱棰樼洰 @@ -678,29 +702,22 @@ // 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, @@ -734,6 +751,18 @@ index++ } } + } + // 棰樺共瀵屾枃鏈鐞� + 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 (questionObj.stemStyle == 'Image' || questionObj.stemStyle == 'TxtAndImage') { @@ -793,14 +822,15 @@ }) }) } + // 鏈夐鐩啀寮�濮嬪�掕鏃� + if (this.data.questionDataList.length) this.startCountdown() this.setData({ loading: false }) }, // 鎵规敼棰樼洰 锛堢粌涔狅紝鎴戠殑閿欓锛屾垜鐨勬敹钘�,锛岀粍鍗凤級 - handleQuestion(num) { + handleQuestion(index) { const questionList = this.data.questionDataList - const index = num - 1 >= 0 ? num - 1 : 0 if (questionList[index].isComplete) { // 棰樼洰宸插畬鎴愶紝璺宠繃 return true @@ -828,7 +858,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] @@ -873,13 +913,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) @@ -935,27 +973,23 @@ } 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) => { }) + .then((res) => {}) }, // 澶勭悊绛旈鏁版嵁 recordAnswerData() { - this.data.cardList.push( - { - name: '瀹㈣棰樺緱鍒�', - score: this.data.subjectiveNum, - path: this.data.productLinkPath, - // infoList: [], - // catalogName: '' - } - ) + this.data.cardList.push({ + name: '瀹㈣棰樺緱鍒�', + score: this.data.subjectiveNum, + path: this.data.productLinkPath, + // infoList: [], + // catalogName: '' + }) let setInfoData = { currentIndex: this.data.currentIndex, dataList: JSON.parse(JSON.stringify(this.data.cardList)) @@ -982,15 +1016,13 @@ 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) => { }) + .then((res) => {}) }, // 鑾峰彇绛旈鏁版嵁 getAnswerInfo(callback) { @@ -1027,8 +1059,7 @@ collectList: JSON.parse(res[0].value) }) // total.value = collectList.value.length - } catch (error) { - } + } catch (error) {} if (this.data.collectList && this.data.collectList.length) { await this.getCollectDataList() } else { @@ -1037,8 +1068,8 @@ }) wx.showModal({ title: '鎻愮ず', - content: '鏀惰棌澶规殏鏃犳暟鎹�',//editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭 - editable: false,//鏄惁鏄剧ず杈撳叆妗� + content: '鏀惰棌澶规殏鏃犳暟鎹�', //editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭 + editable: false, //鏄惁鏄剧ず杈撳叆妗� showCancel: false, success: (res) => { if (res.confirm) { @@ -1056,14 +1087,35 @@ // 鑾峰彇鏀惰棌澶� async getCollectDataList() { let questionArr = [] + // this.setData({ + // cardList: [{ + // catalogName: '鏀惰棌澶�', + // infoList: [] + // }] + // }) this.setData({ - cardList: [ - { - catalogName: '鏀惰棌澶�', - infoList: [] - } - ] + cardList: [{ + 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, @@ -1089,28 +1141,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, @@ -1151,25 +1196,61 @@ 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.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) }) - // 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[0].infoList']: questionArr, - loading: false, + cardList: cardList, + loading: false }) }) }, @@ -1185,8 +1266,7 @@ this.setData({ errorList: JSON.parse(res[0].value) }) - } catch (error) { - } + } catch (error) {} if (this.data.errorList && this.data.errorList.length) { this.getErrorDataList() } else { @@ -1195,8 +1275,8 @@ }) wx.showModal({ title: '鎻愮ず', - content: '閿欓闆嗘殏鏃犳暟鎹�',//editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭 - editable: false,//鏄惁鏄剧ず杈撳叆妗� + content: '閿欓闆嗘殏鏃犳暟鎹�', //editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭 + editable: false, //鏄惁鏄剧ず杈撳叆妗� showCancel: false, success: (res) => { if (res.confirm) { @@ -1212,14 +1292,35 @@ }, // 鑾峰彇閿欓闆� async getErrorDataList() { + // this.setData({ + // cardList: [{ + // catalogName: '閿欓闆�', + // infoList: [] + // }] + // }) this.setData({ - cardList: [ - { - catalogName: '閿欓闆�', - infoList: [] - } - ] + cardList: [{ + 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, @@ -1245,28 +1346,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, @@ -1307,22 +1401,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 }) }) @@ -1361,7 +1490,10 @@ // 鑾峰彇蹇呭惈棰樼洰 let list = item.cmsItemList.map((idItem) => { itemIds.push(idItem.id + '') - questionIds.push({ id: idItem.id + '', score: idItem.score }) + questionIds.push({ + id: idItem.id + '', + score: idItem.score + }) numberIndex++ return { number: numberIndex, @@ -1375,7 +1507,10 @@ const extractItem = item.generatorResultList[i] let extractItemList = extractItem.cmsItemList.map((extractCmsItem) => { itemIds.push(extractCmsItem.id + '') - questionIds.push({ id: extractCmsItem.id + '', score: extractCmsItem.score }) + questionIds.push({ + id: extractCmsItem.id + '', + score: extractCmsItem.score + }) numberIndex++ return { number: numberIndex, @@ -1452,29 +1587,22 @@ // 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), // 棰樺共 + 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' - ? [] - : '', + 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, @@ -1507,6 +1635,17 @@ index++ } } + } + // 棰樺共瀵屾枃鏈鐞� + 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"') + } + // 閫夐」瀵屾枃鏈鐞� + 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') { @@ -1567,26 +1706,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('妯¤�冮鐩垪琛ㄥ凡璁板綍') @@ -1660,17 +1795,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({ @@ -1678,5 +1811,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