From 6df96b3e7a7da1985ee875e84711e9f15c5fbff0 Mon Sep 17 00:00:00 2001 From: litian <C21AF165> Date: 星期二, 24 十二月 2024 18:25:02 +0800 Subject: [PATCH] Merge refs/remotes/origin/master into refs/heads/master --- packageBookService/pages/bookServices/examination/examination.js | 831 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 623 insertions(+), 208 deletions(-) diff --git a/packageBookService/pages/bookServices/examination/examination.js b/packageBookService/pages/bookServices/examination/examination.js index 108f1e6..320d1a5 100644 --- a/packageBookService/pages/bookServices/examination/examination.js +++ b/packageBookService/pages/bookServices/examination/examination.js @@ -1,4 +1,9 @@ -import { getPublicImage } from "../../../../assets/js/middleGround/tool"; +import { + getPublicImage +} from "../../../../assets/js/middleGround/tool"; +import { + loginInfo +} from '../../../../assets/js/login'; const app = getApp(); Page({ /** @@ -12,6 +17,8 @@ countdownInterval: null, // 璁℃椂鍣� isCountdownRunning: true, // 鏄惁鍊掕鏃� countdownTime: 0, // 鍊掕鏃舵椂闂� + storeInfo: '', + jslx: '', bookId: "", productLinkPath: "", rootCmsItemId: "", @@ -28,6 +35,7 @@ total: 0, // 棰樼洰鎬绘暟 cardList: [], // 鎻愪氦椤�, questionDataList: [], // 鏄剧ず棰樼洰鍒楄〃 + noData: false, mockid: 0, uuid: 0, mockData: { @@ -44,6 +52,12 @@ sliderValue: 0, // 瀛椾綋婊戝潡 startTime: "", //杩涘叆椤甸潰褰撳墠鏃堕棿 pauseTime: 0, //鏆傚仠鏃堕棿 + showDialog: false, // 鏈彁浜ら��鍑烘嫤鎴脊绐� + showId: '', + isShowDialog: false, // 娴嬭瘯鎶ュ憡寮圭獥鏄惁鏄剧ず + joinGroup: false, // 鏄惁鍔犲叆鐝骇 + visible: false, // 鍔犲叆鐝骇寮圭獥鏄惁鎵撳紑 + classList: [] // 鐝骇鍒楄〃 }, /** @@ -63,15 +77,31 @@ rootCmsItemId: options.rootCmsItemId, idPathList: options.idPathList ? JSON.parse(options.idPathList) : [], answerType: options.answerType, + storeInfo: options.storeInfo, + jslx: options.jslx, }); + wx.setNavigationBarTitle({ + title: options.answerTitle, + }) if (this.data.answerType == "mock") { this.setData({ uuid: options.uuid, mockid: options.mockid, }); } - this.init(); - console.log("浼犲弬", options); + + const token = wx.getStorageSync(app.config.tokenKey) + if (!token) { + loginInfo(app, (data) => { + if (data) { + this.init(); + } else { + this.init(); + } + }) + } else { + this.init() + } }, /** @@ -174,11 +204,11 @@ * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜� */ onShareAppMessage() {}, + onShareTimeline() {}, // 鐩戝惉watch watch(context, variableName, callback) { let value = context.data[variableName]; // 鑾峰彇琚洃鍚睘鎬х殑褰撳墠鍊� - // 浣跨敤 Object.defineProperty 鏂规硶鍦ㄦ暟鎹璞′笂瀹氫箟灞炴�х殑 getter 鍜� setter Object.defineProperty(context.data, variableName, { configurable: true, // 鍙厤缃� @@ -193,41 +223,105 @@ }, }); }, + // 淇敼nav棰滆壊 + changeNavBarColor(e) { + if (type == 'night') { + wx.setNavigationBarColor({ + backgroundColor: '#000000', + frontColor: '#ffffff', + }) + } else { + wx.setNavigationBarColor({ + backgroundColor: '#ffffff', + frontColor: '#000000', + }) + } + }, + // 姝e垯鎵惧嚭鍚姏src + extractSourceSrc(htmlString) { + // 姝e垯琛ㄨ揪寮忓尮閰�<source>鏍囩涓殑src灞炴�у�� + var srcRegex = /<source\s+src="([^"]+)"/i; + var srcTwo = /<audio\s+src="([^"]+)"/i; + + // 鎵ц姝e垯鍖归厤 + var match = srcRegex.exec(htmlString); + const local = srcTwo.exec(htmlString) + // 濡傛灉鍖归厤鎴愬姛锛岃繑鍥炵涓�涓崟鑾风粍鐨勫唴瀹癸紙src灞炴�х殑鍊硷級 + if (match && match[1]) { + return match[1].replace('../file', app.config.requestCtx + '/file'); + } else if (local && local[1]) { + return local[1].replace('../file', app.config.requestCtx + '/file') + } else { + // 濡傛灉娌℃湁鍖归厤鍒帮紝杩斿洖null + return null; + } + }, + + // 鎷垮埌鍚姏棰橀櫎audio鏍囩澶栧叾浠栧唴瀹� + removeVideoAndAudioTags(htmlString) { + // 浣跨敤姝e垯琛ㄨ揪寮忓尮閰嶅苟绉婚櫎鎵�鏈夌殑 <video> 鍜� <audio> 鏍囩 + var cleanedHtml = htmlString.replace(/<video[^>]*>[\s\S]*?<\/video>|<audio[^>]*>[\s\S]*?<\/audio>/gi, ''); + + return cleanedHtml; + }, + + // 鏀瑰彉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(); - } - }, - }); + if ((this.data.answerType == 'option' || this.data.answerType == 'mock') && !this.data.submitStatus) { + wx.showModal({ + title: "鎻愮ず", + content: "鏈彁浜わ紝鏄惁閫�鍑虹瓟棰�", + confirmColor: "#ff6c00", + cancelColor: "#949494", + complete: (res) => { + if (res.cancel) { + this.setData({ + showDialog: true + }) + } + if (res.confirm) { + this.setData({ + submitStatus: true, + showDialog: false + }); + wx.navigateBack(); + } + }, + }); + } }, onChangeSlider(e) { this.setData({ sliderValue: e.detail.value, }); - console.log(e.detail.value); }, // 杩斿洖 goBack() { - console.log(this.data.submitStatus); wx.navigateBack(); }, //璁剧疆鑳屾櫙鑹� changeBGColor(e) { + const flag = e.detail.value this.setData({ - isNight: e.detail.value, + isNight: flag, }); + if (flag) { + wx.setNavigationBarColor({ + backgroundColor: '#000000', + frontColor: '#ffffff', + }) + } else { + wx.setNavigationBarColor({ + backgroundColor: '#ffffff', + frontColor: '#000000', + }) + } }, // 鑾峰彇淇濆瓨鐨勫�掕鏃舵椂闂� getSavedTime() { @@ -285,11 +379,13 @@ }, // 鍒囨崲棰樼洰 changeSwiper(e) { - this.setData({ - currentIndex: e.detail.index, - }); let index = e.detail.index - 1 >= 0 ? e.detail.index - 1 : 0; const item = this.data.questionDataList[index]; + const lastItem = this.data.questionDataList[index + 1]; + this.setData({ + currentIndex: e.detail.index, + showId: lastItem.id + }); if ( (this.data.answerType == "collectQuestion" || this.data.answerType == "errorQuestion") && @@ -388,7 +484,6 @@ const inputData = e.detail.value.detail.value; const id = e.detail.value.currentTarget.dataset.id; const index = Number(e.detail.value.currentTarget.dataset.index); - console.log(index); const questionList = this.data.questionDataList; questionList.forEach((item) => { if (item.id == id) { @@ -455,11 +550,13 @@ submitStatus: true, loading: true, }); - const child = this.selectComponent("#question-options"); + const child = this.selectComponent('#question-options'); + if ( this.data.answerType == "option" || this.data.answerType == "errorQuestion" || - this.data.answerType == "mock" + this.data.answerType == "mock" || + this.data.answerType == 'interaction' ) { // 鍏堥亶鍘嗘墍鏈夐鐩紝灏嗘湭鎵规敼鐨勯鐩壒鏀� const qustionList = this.data.questionDataList; @@ -471,7 +568,11 @@ if (this.data.answerType == "option") { this.toggleCountdown(); this.recordAnswerData(); - child.openTestReportDialog(); + // this.selectComponent 鎷夸笉鍒� 缁勪欢浜嗭紝 鏀逛负鐩戝惉缁勪欢浼犲�� 鎵撳紑寮圭獥 + // child.openTestReportDialog(); + this.setData({ + isShowDialog: true + }) } else if ( this.data.answerType == "collectQuestion" || this.data.answerType == "errorQuestion" @@ -505,21 +606,26 @@ }); } 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(); + // child.openTestReportDialog(); + this.setData({ + isShowDialog: true + }) + } else if (this.data.answerType == 'interaction') { + this.toggleCountdown(); + this.handleClassQuestion() } this.setData({ loading: false, + showDialog: false, }); }, // 鍒濆鍖栧嚱鏁� @@ -532,13 +638,19 @@ }); if (this.data.answerType == "option") { if (this.data) - // this.startCountdown() this.setData({ countdownTime: 2 * 60 * 60 * 1000, }); // 娴嬭瘯绛旈 await this.getCollectIdList(); // 鑾峰彇鏀惰棌id鍒楄〃 await this.getErrorList(); // 鑾峰彇閿欓id鍒楄〃 + } else if (this.data.answerType == "interaction") { + this.setData({ + countdownTime: 2 * 60 * 60 * 1000, + }); + this.getCurrentClassList() + this.getinteractionInfo() + // 鏁欏浜掑姩 } else if (this.data.answerType == "collectQuestion") { this.setData({ submitStatus: true, @@ -596,6 +708,9 @@ oldMockData.state == "2" ) { this.startCountdown(); + this.setData({ + showDialog: true + }) } if (oldMockData.state == "3") { this.setData({ @@ -617,6 +732,7 @@ subjectiveNum: 0, currentIndex: 0, submitStatus: false, + showDialog: true }); if (this.data.answerType == "option") { this.setData({ @@ -633,18 +749,24 @@ // 缁勫嵎妯″紡 // 娓呯┖绛旈璁板綍 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 if (this.data.answerType == 'interaction') { + this.setData({ + countdownTime: 2 * 60 * 60 * 1000, + }); + this.delinteractionInfo(() => { + this.getQuestionList() + this.clearTime(); + }) } else { this.init(); this.clearTime(); @@ -693,11 +815,13 @@ this.setData({ currentIndex: value.currentIndex, }); - console.log(this.data.submitStatus); // 鎼哄甫绛旈璁板綍 鑾峰彇棰樼洰 await this.getQuestionList(value.dataList); } else { await this.getQuestionList(); // 鑾峰彇棰樺簱棰樼洰 + this.setData({ + showDialog: true + }) } }); } @@ -722,6 +846,7 @@ async getQuestionList(oldData) { // 娓呯┖姝g‘棰樻暟璁板綍 this.setData({ + noData: false, cardList: [], correctNum: 0, }); @@ -760,6 +885,9 @@ size: 999, }, }; + if (this.data.storeInfo) { + query.storeInfo = this.data.storeInfo + } await app.MG.store.getProductDetail(query).then((res) => { this.setData({ total: res.datas.cmsDatas[0].datas.length, @@ -771,11 +899,21 @@ oldList = oldData.find( (item) => item.path == pathitem.productLinkPath ).infoList; - this.setData({ - submitStatus: true, - }); } res.datas.cmsDatas[0].datas.forEach((item, index) => { + if (this.data.storeInfo || this.data.jslx) { + if (item.Embedded_QuestionBank_QuestionType == 'singleChoice') { + pathitem.name = "鍗曢�夐" + } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer') { + pathitem.name = "绠�绛旈" + } else if (item.Embedded_QuestionBank_QuestionType == "completion") { + pathitem.name = "濉┖棰�"; + } else if (item.Embedded_QuestionBank_QuestionType == "multipleChoice") { + pathitem.name = "澶氶�夐"; + } else if (item.Embedded_QuestionBank_QuestionType == "judge") { + pathitem.name = "鍒ゆ柇棰�"; + } + } let oldObj = ""; if (oldList) oldObj = oldList.find((oldItem) => oldItem.id == item.id); @@ -783,34 +921,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鏍煎紡 @@ -819,7 +949,8 @@ questionObj.questionType == "multipleChoice" ) { try { - questionObj.answer = JSON.parse(questionObj.answer).toString(); + // questionObj.answer = JSON.parse(questionObj.answer).toString(); + questionObj.answer = JSON.parse(questionObj.answer) } catch (error) { questionObj.answer = item.Embedded_QuestionBank_Answer; } @@ -847,7 +978,7 @@ /\<img/gi, '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" ' ) - .replace(/\<p/gi, '<p class="stem-rich-p"'); + .replace(/\<p/gi, '<p class="stem-rich-p"').replace('../file', app.config.requestCtx + '/file'); } // 閫夐」瀵屾枃鏈鐞� if ( @@ -859,8 +990,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"').replace('../file', app.config.requestCtx + '/file'); }); } // 瑙f瀽瀵屾枃鏈鐞� @@ -872,6 +1003,14 @@ /\<img/gi, '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" ' ); + } + // 鍚姏棰樹慨鏀� + if (questionObj.questionType == 'singleChoice') { + const src = this.extractSourceSrc(questionObj.stem.stemTxt) + if (src) { + questionObj.src = src + questionObj.stem.stemTxt = this.removeVideoAndAudioTags(questionObj.stem.stemTxt) + } } // 鑾峰彇鍥剧墖 if ( @@ -951,10 +1090,18 @@ }); } // 鏈夐鐩啀寮�濮嬪�掕鏃� - if (this.data.questionDataList.length) this.startCountdown(); - this.setData({ - loading: false, - }); + if (this.data.questionDataList.length) { + this.startCountdown(); + this.setData({ + loading: false, + showId: this.data.questionDataList[0].id + }) + } else { + this.setData({ + noData: true, + loading: false, + }) + } }, // 鎵规敼棰樼洰 锛堢粌涔狅紝鎴戠殑閿欓锛屾垜鐨勬敹钘�,锛岀粍鍗凤級 handleQuestion(index) { @@ -987,7 +1134,7 @@ // 绠�绛� 缈昏瘧 questionList[index].isRight = null; } else if (item.questionType == "completion") { - if (item.answer == "string") { + if (typeof item.answer == "string") { item.isRight = item.answer == item.userAnswer[0]; } else { if (item.answer.length != item.userAnswer.length) { @@ -1047,13 +1194,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 +1256,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,24 +1292,21 @@ } } } - this.setAnswerInfo(setInfoData); }, // 鎻愪氦绛旈鏁版嵁 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 +1317,7 @@ if (callback) callback(res); }); }, - // 鍒犻櫎绛旈鏁版嵁 + // 鍒犻櫎鏃х瓟棰樻暟鎹� delAnswerInfo(callback) { app.MG.identity .delUserKey({ @@ -1206,6 +1346,7 @@ } else { this.setData({ loading: false, + noData: true }); wx.showModal({ title: "鎻愮ず", @@ -1230,8 +1371,7 @@ async getCollectDataList() { let questionArr = []; this.setData({ - cardList: [ - { + cardList: [{ catalogName: "鍗曢�夐", infoList: [], }, @@ -1279,34 +1419,30 @@ Embedded_QuestionBank_Difficulty: [], }, }; + if (this.data.storeInfo) { + query.storeInfo = this.data.storeInfo + } await app.MG.store.getProductDetail(query).then((res) => { let questionArr = []; res.datas.cmsDatas[0].datas.forEach((item, index) => { 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, @@ -1317,6 +1453,7 @@ questionObj.questionType == "completion" || questionObj.questionType == "multipleChoice" ) { + console.log(questionObj.answer, "111") try { questionObj.answer = JSON.parse(questionObj.answer).toString(); } catch (error) { @@ -1365,7 +1502,7 @@ /\<img/gi, '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" ' ) - .replace(/\<p/gi, '<p class="stem-rich-p"'); + .replace(/\<p/gi, '<p class="stem-rich-p"').replace('../file', app.config.requestCtx + '/file'); } // 閫夐」瀵屾枃鏈鐞� if ( @@ -1377,9 +1514,27 @@ 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"').replace('../file', app.config.requestCtx + '/file'); }); + } + // 瑙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 (questionObj.questionType == 'singleChoice') { + const src = this.extractSourceSrc(questionObj.stem.stemTxt) + if (src) { + questionObj.src = src + questionObj.stem.stemTxt = this.removeVideoAndAudioTags(questionObj.stem.stemTxt) + } } if (item.Embedded_QuestionBank_QuestionType == "judge") { questionObj.type = "鍒ゆ柇棰�"; @@ -1422,6 +1577,7 @@ } this.setData({ questionDataList: questionArr, + showId: questionArr[0].id, cardList: cardList, loading: false, }); @@ -1443,7 +1599,8 @@ this.getErrorDataList(); } else { this.setData({ - loading: true, + loading: false, + noData: true }); wx.showModal({ title: "鎻愮ず", @@ -1467,8 +1624,7 @@ // 鑾峰彇閿欓闆� async getErrorDataList() { this.setData({ - cardList: [ - { + cardList: [{ catalogName: "鍗曢�夐", infoList: [], }, @@ -1514,34 +1670,30 @@ Embedded_QuestionBank_Difficulty: [], }, }; + if (this.data.storeInfo) { + query.storeInfo = this.data.storeInfo + } await app.MG.store.getProductDetail(query).then((res) => { let questionArr = []; res.datas.cmsDatas[0].datas.forEach((item, index) => { 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, @@ -1602,7 +1754,7 @@ /\<img/gi, '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" ' ) - .replace(/\<p/gi, '<p class="stem-rich-p"'); + .replace(/\<p/gi, '<p class="stem-rich-p"').replace('../file', app.config.requestCtx + '/file'); } // 閫夐」瀵屾枃鏈鐞� if ( @@ -1614,9 +1766,28 @@ 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"').replace('../file', app.config.requestCtx + '/file'); }); + } + // 瑙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 (questionObj.questionType == 'singleChoice') { + const src = this.extractSourceSrc(questionObj.stem.stemTxt) + if (src) { + questionObj.src = src + questionObj.stem.stemTxt = this.removeVideoAndAudioTags(questionObj.stem.stemTxt) + console.log('棰樺共', questionObj.stem.stemTxt); + } } if (item.Embedded_QuestionBank_QuestionType == "judge") { questionObj.type = "鍒ゆ柇棰�"; @@ -1658,11 +1829,12 @@ } this.setData({ questionDataList: questionArr, + showId: questionArr[0].id, cardList: cardList, loading: false, }); + console.log(this.data.questionDataList, "questionDataList"); }); - // loadings.value = false }, // 鑾峰彇缁勫嵎缁撴灉 async getEduQuizConfig() { @@ -1787,6 +1959,9 @@ Embedded_QuestionBank_Difficulty: [], }, }; + if (this.data.storeInfo) { + query.storeInfo = this.data.storeInfo + } await app.MG.store.getProductDetail(query).then((res) => { res.datas.cmsDatas[0].datas.forEach((item, index) => { // 寰幆questionList,缁欐瘡棰樿祴鍊煎垎鏁� @@ -1798,35 +1973,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鏍煎紡 @@ -1861,7 +2028,7 @@ 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"').replace('../file', app.config.requestCtx + '/file'); } // 閫夐」瀵屾枃鏈鐞� if ( @@ -1875,8 +2042,16 @@ item.txt = item.txt.replace( /\<img/gi, '<img class="option-rich-img"' - ); + ).replace(/\<p/gi, '<p class="stem-rich-p"').replace('../file', app.config.requestCtx + '/file'); }); + } + // 鍚姏棰樹慨鏀� + if (questionObj.questionType == 'singleChoice') { + const src = this.extractSourceSrc(questionObj.stem.stemTxt) + if (src) { + questionObj.src = src + questionObj.stem.stemTxt = this.removeVideoAndAudioTags(questionObj.stem.stemTxt) + } } // 鑾峰彇鍥剧墖 if ( @@ -1941,6 +2116,7 @@ } this.setData({ loading: false, + showId: this.data.questionDataList[0].id }); }, // 鑾峰彇缁勫嵎鏁版嵁 @@ -1957,26 +2133,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("妯¤�冮鐩垪琛ㄥ凡璁板綍"); @@ -2005,12 +2177,12 @@ }) .then((res) => { if (res[0]) { + // 杩欓噷鐨� countdownTime 璧嬪�硷細濡傛灉鏄椂闂村埌浜嗘彁浜わ紝璁板綍鐨勫墿浣欐椂闂村氨鏄�0锛屾墍浠ワ細濡傛灉鏄�0鐨勮瘽璧嬪��1绉掞紝闃叉鐩戝惉鍒版椂闂翠负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, + countdownTime: JSON.parse(res[0].value).time > 0 ? + JSON.parse(res[0].value).time : 1000, "mockData.answer": JSON.parse(res[0].value).answerData, }); console.log(JSON.parse(res[0].value)); @@ -2054,17 +2226,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({ @@ -2076,7 +2246,6 @@ // 瀵屾枃鏈鐞� formatRichText(html) { - console.log(html); let newContent = html.replace(/<img[^>]*>/gi, function (match, capture) { match = match .replace(/style="[^"]+"/gi, "") @@ -2110,4 +2279,250 @@ ); return newContent; }, -}); + // 鏁欏浜掑姩妯″紡鐩稿叧 + // 鑾峰彇鐝骇鍒楄〃 + getCurrentClassList() { + const query = { + start: 0, + size: 999, + infoTypes: [], + } + app.MG.identity.joinedGroupByList(query).then((res) => { + res.datas.forEach(async item => { + item.topicId = null + const data = await this.getTopicInfo(item.id) + if (data) { + item.topicId = data.id + } + }) + console.log('鐝骇', res) + if (res.datas.length) { + this.setData({ + classList: res.datas + }) + // 鍒ゆ柇鐝骇 鏄惁鎵�灞炰簬璇ヤ功 + const classData = res.datas.find(item => item.linkProductDto.product.id == this.data.bookId) + if (classData) { + if (classData.userState == 'Normal') { + // 鍔犲叆鐝骇 + this.setData({ + joinGroup: true + }) + } else if (classData.userState == 'WaitValid') { + this.setData({ + submitStatus: true + }) + // 瀹℃牳涓� + wx.showModal({ + title: '鎻愮ず', + content: '璇风瓑寰呰�佸笀瀹℃牳鍔犲叆鐝骇鍚庣瓟棰�', + confirmColor: "#ff6c00", + complete: (res) => { + if (res.cancel) { + wx.navigateBack() + } + if (res.confirm) { + wx.navigateBack() + } + } + }) + } else { + // 鎷掔粷 + this.setData({ + visible: true + }) + } + } else { + // 鏈姞鍏ョ彮绾� + this.setData({ + visible: true + }) + } + } else { + this.setData({ + visible: true, + }) + } + + }) + }, + // 鍔犲叆鐝骇 + joinClass(e) { + wx.showLoading({ + title: '鍔犺浇涓�' + }) + const data = { + refCode: e.detail.value + } + app.MG.identity.joinGroupByRefCode(data).then((res) => { + wx.hideLoading() + if (res == '缁勪笉瀛樺湪') { + wx.showToast({ + icon: 'error', + title: '鏃犳晥鐨勭彮绾�', + }) + } else if (res == '缁勬垚鍛樻暟閲忓凡鏈�澶�,涓嶈兘鍔犲叆') { + wx.showToast({ + icon: 'error', + title: '鐝骇鎴愬憳鏁伴噺宸叉渶澶э紝涓嶈兘鍔犲叆', + }) + } else if (res == '宸茬粡鐢宠杩囧姞鍏ユ缁�') { + wx.showToast({ + icon: 'error', + title: '宸茬粡鐢宠杩囧姞鍏ユ鐝骇', + }) + } else { + wx.showToast({ + icon: "success", + title: '宸叉垚鍔燂紝绛夊緟瀹℃牳涓�...', + }) + this.setData({ + visible: false + }) + this.getCurrentClassList() + } + }) + }, + // 鑾峰彇鐝骇topic + async getTopicInfo(classId) { + let query = { + classId, + refCodes: ["TeachInteraction"] + } + const res = await app.MG.edu.getClassTopic(query) + return res[0] ?? null + }, + // 鑾峰彇鏃ф暀瀛︿簰鍔ㄧ瓟棰樻暟鎹� + getinteractionInfo() { + app.MG.identity + .getUserKey({ + domain: "interactionData", + keys: [this.data.productLinkPath], + }) + .then((res) => { + if (res.length) { + let value = JSON.parse(res[0].value); + const scoreData = value.dataList.find(item => item.name == "瀹㈣棰樺緱鍒�" && item.path == this.data.productLinkPath) + this.setData({ + currentIndex: value.currentIndex ? value.currentIndex : 0, + subjectiveNum: scoreData ? scoreData.score : 0, + submitStatus: true + }); + // 鎼哄甫绛旈璁板綍 鑾峰彇棰樼洰 + this.getQuestionList(value.dataList); + } else { + this.getQuestionList(); // 鑾峰彇棰樺簱棰樼洰 + this.setData({ + showDialog: true + }) + } + }); + }, + // 鎻愪氦鏁欏浜掑姩绛旈鏁版嵁 + setinteractionInfo() { + const list = [] + this.data.cardList.forEach(item => { + list.push({ + catalogName: item.catalogName, + path: item.path, + infoList: item.infoList.map((citem) => ({ + id: citem.id, + userAnswer: citem.userAnswer + })) + }) + }) + list.push({ + name: "瀹㈣棰樺緱鍒�", + score: this.data.subjectiveNum, + path: this.data.productLinkPath, + }) + app.MG.identity + .setUserKey({ + setKeyRequests: [{ + domain: "interactionData", + key: this.data.productLinkPath, + value: JSON.stringify({ + currentIndex: this.data.currentIndex, + dataList: list + }), + }, ], + }) + .then((res) => {}); + }, + // 澶勭悊鏁欏浜掑姩绛旈 + handleClassQuestion() { + const flag = this.data.questionDataList.some(item => !item.userAnswer) + if (flag) { + // 娌″仛瀹岋紝淇濆瓨鍗冲彲 + const isAnswer = this.data.questionDataList.some(item => item.userAnswer) + if (isAnswer) this.setinteractionInfo() + } else { + // 鍋氬畬浜嗕笖鍔犲叆浜嗙彮绾э紝鎻愪氦鍒癿essage + if (this.data.classList.length && this.data.joinGroup) { + this.data.classList.forEach(item => { + if (item.linkProductDto.product.id == this.data.bookId && item.topicId) + this.newTopicMessage(item.topicId) + }) + this.setinteractionInfo() + } else { + // 鍋氬畬浜嗭紝娌″姞鍏ョ彮绾� + this.setinteractionInfo() + } + this.setData({ + isShowDialog: true + }) + } + this.setData({ + submitStatus: true + }) + }, + + // 鏂板缓topicMessage + newTopicMessage(topicId) { + let content = [] + for (let cindex = 0; cindex < this.data.questionDataList.length; cindex++) { + const citem = this.data.questionDataList[cindex]; + content.push({ + cmsItemId: citem.id, + answer: citem.userAnswer, + state: citem.questionType == 'shortAnswer' ? 'none' : citem.isRight, + type: citem.questionType + }) + const userInfo = JSON.parse(wx.getStorageSync(app.config.userInfoKey)) + const data = { + description: '', + icon: '', + state: 'Normal', + topicIdOrRefCode: String(topicId), + name: this.data.answerTitle, + content: JSON.stringify({ + bookId: this.data.bookId, + userName: userInfo.name ? userInfo.name : userInfo.nickName ? userInfo.nickName : '-', + path: this.data.productLinkPath, + content + }), + type: 'Normal', + cmsTypeRefCode: '', + newDataListRequest: [] + } + app.MG.ugc.newTopicMessage(data).then((res) => { + if (res) { + this.setData({ + isShowDialog: true + }) + } + }) + } + }, + // 鍒犻櫎鏁欏浜掑姩绛旈璁板綍 + delinteractionInfo(callback) { + app.MG.identity + .delUserKey({ + domain: 'interactionData', + keys: [this.data.productLinkPath] + }) + .then((res) => { + if (callback) callback() + }) + } +}) \ No newline at end of file -- Gitblit v1.9.1