From 608eefe5fb03d2f3d3145b11d7de573434451e76 Mon Sep 17 00:00:00 2001 From: 闫增涛 <1829501689@qq.com> Date: 星期五, 29 三月 2024 19:42:58 +0800 Subject: [PATCH] 详情页bug修改 --- packageBookService/pages/bookServices/examination/examination.js | 449 +++++++++++++++++++++++++++++-------------------------- 1 files changed, 237 insertions(+), 212 deletions(-) diff --git a/packageBookService/pages/bookServices/examination/examination.js b/packageBookService/pages/bookServices/examination/examination.js index 9b5823d..fc94dce 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,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) } }, // 鐐瑰嚮绛旈鍗¤烦杞鐩� @@ -269,21 +270,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 @@ -375,7 +400,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 +437,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 +462,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 +495,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 +553,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 +583,7 @@ this.setData({ collectList: JSON.parse(res[0].value) }) - } catch (error) { - } + } catch (error) {} if (this.data.answerType == 'option') { // 鍏堣幏鍙栫敤鎴风瓟棰樿褰� this.getAnswerInfo(async (res) => { @@ -612,8 +631,7 @@ this.setData({ errorList: JSON.parse(res[0].value) }) - } catch (error) { - } + } catch (error) {} }) }, // 鑾峰彇棰樺簱棰樼洰 @@ -678,29 +696,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 +745,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 +816,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 @@ -873,13 +897,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 +957,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 +1000,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 +1043,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 +1052,8 @@ }) wx.showModal({ title: '鎻愮ず', - content: '鏀惰棌澶规殏鏃犳暟鎹�',//editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭 - editable: false,//鏄惁鏄剧ず杈撳叆妗� + content: '鏀惰棌澶规殏鏃犳暟鎹�', //editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭 + editable: false, //鏄惁鏄剧ず杈撳叆妗� showCancel: false, success: (res) => { if (res.confirm) { @@ -1057,12 +1072,10 @@ async getCollectDataList() { let questionArr = [] this.setData({ - cardList: [ - { - catalogName: '鏀惰棌澶�', - infoList: [] - } - ] + cardList: [{ + catalogName: '鏀惰棌澶�', + infoList: [] + }] }) let query = { path: '*', @@ -1089,28 +1102,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, @@ -1185,8 +1191,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 +1200,8 @@ }) wx.showModal({ title: '鎻愮ず', - content: '閿欓闆嗘殏鏃犳暟鎹�',//editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭 - editable: false,//鏄惁鏄剧ず杈撳叆妗� + content: '閿欓闆嗘殏鏃犳暟鎹�', //editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭 + editable: false, //鏄惁鏄剧ず杈撳叆妗� showCancel: false, success: (res) => { if (res.confirm) { @@ -1213,12 +1218,10 @@ // 鑾峰彇閿欓闆� async getErrorDataList() { this.setData({ - cardList: [ - { - catalogName: '閿欓闆�', - infoList: [] - } - ] + cardList: [{ + catalogName: '閿欓闆�', + infoList: [] + }] }) let query = { path: '*', @@ -1245,28 +1248,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, @@ -1361,7 +1357,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 +1374,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 +1454,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 +1502,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 +1573,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 +1662,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 +1678,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