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 | 2650 ++++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 1,748 insertions(+), 902 deletions(-) diff --git a/packageBookService/pages/bookServices/examination/examination.js b/packageBookService/pages/bookServices/examination/examination.js index 9b5823d..320d1a5 100644 --- a/packageBookService/pages/bookServices/examination/examination.js +++ b/packageBookService/pages/bookServices/examination/examination.js @@ -1,7 +1,11 @@ -import { getPublicImage } from '../../../../assets/js/middleGround/tool' -const app = getApp() +import { + getPublicImage +} from "../../../../assets/js/middleGround/tool"; +import { + loginInfo +} from '../../../../assets/js/login'; +const app = getApp(); Page({ - /** * 椤甸潰鐨勫垵濮嬫暟鎹� */ @@ -9,106 +13,127 @@ barHeight: "", navBarHeight: "", loading: false, - answerTitle: "", // 瀵艰埅鏍忔爣棰� - countdownInterval: null, // 璁℃椂鍣� + answerTitle: "", // 瀵艰埅鏍忔爣棰� + countdownInterval: null, // 璁℃椂鍣� isCountdownRunning: true, // 鏄惁鍊掕鏃� - countdownTime: 0, // 鍊掕鏃舵椂闂� + countdownTime: 0, // 鍊掕鏃舵椂闂� + storeInfo: '', + jslx: '', 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: [], // 鏄剧ず棰樼洰鍒楄〃 + noData: false, mockid: 0, uuid: 0, mockData: { // 缁勫嵎淇℃伅 - state: '0', + state: "0", score: 0, // 鎬诲垎 sumTime: 0, time: 0, // 绛旈鍓╀綑鏃堕棿 datas: [], // 鎵�鏈夋ā鑰冭褰曟暟鎹�(棰樼洰鍒楄〃锛岀敤鎴风瓟棰橈紝鑰冭瘯鎶ュ憡) - answer: [] + answer: [], }, saveTime: 20, isNight: false, sliderValue: 0, // 瀛椾綋婊戝潡 + startTime: "", //杩涘叆椤甸潰褰撳墠鏃堕棿 + pauseTime: 0, //鏆傚仠鏃堕棿 + showDialog: false, // 鏈彁浜ら��鍑烘嫤鎴脊绐� + showId: '', + isShowDialog: false, // 娴嬭瘯鎶ュ憡寮圭獥鏄惁鏄剧ず + joinGroup: false, // 鏄惁鍔犲叆鐝骇 + visible: false, // 鍔犲叆鐝骇寮圭獥鏄惁鎵撳紑 + classList: [] // 鐝骇鍒楄〃 }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 */ 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 = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴� + const navBarHeight = + (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴� this.setData({ barHeight: systInfo.statusBarHeight, navBarHeight: navBarHeight, answerTitle: options.answerTitle, bookId: options.bookId, - productLinkPath: options.productLinkPath ? options.productLinkPath : '', + productLinkPath: options.productLinkPath ? options.productLinkPath : "", rootCmsItemId: options.rootCmsItemId, idPathList: options.idPathList ? JSON.parse(options.idPathList) : [], answerType: options.answerType, + storeInfo: options.storeInfo, + jslx: options.jslx, }); - if (this.data.answerType == 'mock') { + wx.setNavigationBarTitle({ + title: options.answerTitle, + }) + if (this.data.answerType == "mock") { this.setData({ uuid: options.uuid, - mockid: options.mockid - }) + 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() + } }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚 */ - onReady() { - }, + onReady() {}, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず */ onShow() { - if (this.data.answerType != 'mock') { + if (this.data.answerType != "mock") { if (wx.timer) { - clearInterval(wx.timer) + clearInterval(wx.timer); } } - if (this.data.answerType == 'mock') { + if (this.data.answerType == "mock") { if (wx.timer) { - clearInterval(wx.timer) + clearInterval(wx.timer); } wx.timer = setInterval(() => { this.setData({ - saveTime: this.data.saveTime - 1 - }) + saveTime: this.data.saveTime - 1, + }); if (this.data.saveTime == 0) { - this.saveMockData() + this.saveMockData(); } - }, 1000) + }, 1000); } + this.setData({ + startTime: Date.now(), + }); }, /** @@ -116,7 +141,14 @@ */ onHide() { if (wx.timer) { - clearInterval(wx.timer) + clearInterval(wx.timer); + } + this.setData({ + pauseTime: Date.now(), + }); + if (wx.getStorageSync(app.config.tokenKey)) { + let duration = this.data.pauseTime - this.data.startTime; + this.count(duration); } }, @@ -125,37 +157,58 @@ */ onUnload(e) { if (wx.timer) { - clearInterval(wx.timer) + clearInterval(wx.timer); } if (this.data.countdownInterval !== null) { - clearInterval(this.data.countdownInterval) + clearInterval(this.data.countdownInterval); } + this.setData({ + pauseTime: Date.now(), + }); + if (wx.getStorageSync(app.config.tokenKey)) { + let duration = this.data.pauseTime - this.data.startTime; + this.count(duration); + } + }, + + count(timeStr) { + const data = { + appRefCode: app.config.appRefCode, + type: "LearningTime", //缁熻绫诲瀷--闃呰鏃堕暱 + data: timeStr + "", //缁熻鍐呭--鏃堕暱姣 + event: "LearningTime", + sysType: "App", + }; + //闃呰鍟嗗搧鐨刬d + if (this.data.bookId) { + data.productId = this.data.bookId; + } + //闃呰璧勬簮鐨刬d + // if (product.cmsItemId) { + // data.cmsItemId = product.cmsItemId + // } + app.MG.job.newJobWithApiNewEvent(data).then((res) => {}); }, /** * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 */ - onPullDownRefresh() { - - }, + onPullDownRefresh() {}, /** * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁� */ - onReachBottom() { - - }, + onReachBottom() {}, /** * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜� */ - onShareAppMessage() { - }, + onShareAppMessage() {}, + onShareTimeline() {}, // 鐩戝惉watch watch(context, variableName, callback) { let value = context.data[variableName]; // 鑾峰彇琚洃鍚睘鎬х殑褰撳墠鍊� - // 浣跨敤 Object.defineProperty 鏂规硶鍦ㄦ暟鎹璞′笂瀹氫箟灞炴�х殑 getter 鍜� setter Object.defineProperty(context.data, variableName, { configurable: true, // 鍙厤缃� @@ -167,163 +220,294 @@ const oldVal = value; // 璁板綍灞炴�х殑鏃у�� value = newVal; // 鏇存柊灞炴�х殑鍊� callback.call(context, newVal, oldVal); // 璋冪敤鍥炶皟鍑芥暟锛屼紶閫掓柊鍊煎拰鏃у�� - } + }, }); + }, + // 淇敼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() { + 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); + sliderValue: 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() { - const savedTime = wx.getStorageSync('countdownTime') - return savedTime ? parseInt(savedTime) : null + const savedTime = wx.getStorageSync("countdownTime"); + return savedTime ? parseInt(savedTime) : null; }, // 淇濆瓨鍊掕鏃舵椂闂村埌鏈湴瀛樺偍 saveTime() { - wx.setStorageSync('countdownTime', this.data.countdownTime.toString()) + wx.setStorageSync("countdownTime", this.data.countdownTime.toString()); }, clearTime() { this.setData({ - countdownTime: 2 * 60 * 60 * 1000 - }) + countdownTime: 2 * 60 * 60 * 1000, + }); }, // 鏆傚仠鎴栫户缁�掕鏃� toggleCountdown() { if (this.data.countdownInterval) { - clearInterval(this.data.countdownInterval) + clearInterval(this.data.countdownInterval); this.setData({ countdownInterval: null, - isCountdownRunning: false - }) + isCountdownRunning: false, + }); } else { - this.startCountdown() + this.startCountdown(); this.setData({ - isCountdownRunning: true - }) + isCountdownRunning: true, + }); } }, // 寮�濮嬪�掕鏃� startCountdown() { // 濡傛灉璁℃椂鍣ㄥ凡缁忓瓨鍦紝鍏堟竻闄や箣鍓嶇殑璁℃椂鍣� if (this.data.countdownInterval) { - clearInterval(this.data.countdownInterval) + clearInterval(this.data.countdownInterval); this.setData({ - countdownInterval: null - }) + countdownInterval: null, + }); } this.setData({ countdownInterval: setInterval(() => { this.setData({ - countdownTime: this.data.countdownTime - 1000 - }) + countdownTime: this.data.countdownTime - 1000, + }); if (this.data.countdownTime <= 0) { - clearInterval(this.data.countdownInterval) + clearInterval(this.data.countdownInterval); this.setData({ countdownTime: 0, - isCountdownRunning: false - }) + isCountdownRunning: false, + }); } - this.saveTime() - }, 1000) - }) + this.saveTime(); + }, 1000), + }); }, // 鍒囨崲棰樼洰 changeSwiper(e) { + 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 - }) - 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) + currentIndex: e.detail.index, + showId: lastItem.id + }); + 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" + ) { + const item = this.data.questionDataList[this.data.currentIndex]; + if (!item.isComplete) { + this.handleQuestion(this.data.currentIndex); + } } }, // 鐐瑰嚮绛旈鍗¤烦杞鐩� goQuestion(e) { - const id = e.detail.id + const id = e.detail.id; this.data.questionDataList.forEach((item, index) => { if (item.id == id) { this.setData({ - currentIndex: index - }) + currentIndex: index, + }); } - }) + }); }, // 鍗曢�� 澶氶�� 瑙﹀彂 onChangeRadio(e) { - const radioData = e.detail.value.currentTarget.dataset.value - 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) { - item.userAnswer = radioChecked - item.isUserAnswer = this.isHaveAnswer(radioChecked) - } - }) - const cardListUpdata = this.data.cardList - cardListUpdata.forEach(item => { - item.infoList.forEach(citem => { - if (citem.id == id) { - citem.userAnswer = radioChecked - citem.isUserAnswer = this.isHaveAnswer(radioChecked) + const radioData = e.detail.value.currentTarget.dataset.value; + const id = e.detail.value.currentTarget.dataset.id; + const radioChecked = e.detail.value.detail.value; + const questionList = this.data.questionDataList; + // 鎴戠殑閿欓鍜屾垜鐨勬敹钘忔ā寮忎笅锛屽崟閫夐閫夋嫨浜嗙洿鎺ユ壒鏀� + 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; + 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 - }) - if (this.data.answerType == 'mock') { + cardList: cardListUpdata, + }); + if (this.data.answerType == "mock") { this.setData({ - saveTime: 20 - }) + saveTime: 20, + }); } }, // 杈撳叆妗嗚Е鍙� onChangeInput(e) { - 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 => { + const inputData = e.detail.value.detail.value; + const id = e.detail.value.currentTarget.dataset.id; + const index = Number(e.detail.value.currentTarget.dataset.index); + const questionList = this.data.questionDataList; + questionList.forEach((item) => { if (item.id == id) { - item.userAnswer[index] = inputData - return item.isUserAnswer = this.isHaveAnswer(inputData) + item.userAnswer[index] = inputData; + return (item.isUserAnswer = this.isHaveAnswer(inputData)); } - }) - const cardListUpdata = this.data.cardList - cardListUpdata.forEach(item => { - item.infoList.forEach(citem => { + }); + const cardListUpdata = this.data.cardList; + cardListUpdata.forEach((item) => { + item.infoList.forEach((citem) => { if (citem.id == id) { - citem.userAnswer[index] = inputData - return citem.isUserAnswer = this.isHaveAnswer(inputData) + citem.userAnswer[index] = inputData; + return (citem.isUserAnswer = this.isHaveAnswer(inputData)); } - }) - }) + }); + }); this.setData({ questionDataList: questionList, cardList: cardListUpdata, - }) - if (this.data.answerType == 'mock') { + }); + if (this.data.answerType == "mock") { this.setData({ - saveTime: 20 - }) + saveTime: 20, + }); } }, // 鏁扮粍杞负瀛楃涓叉柟娉� @@ -331,103 +515,118 @@ // 妫�鏌ユ槸鍚︿负鏁扮粍 if (Array.isArray(data)) { // 浣跨敤 join 鏂规硶灏嗘暟缁勮浆鎹负瀛楃涓诧紝榛樿浣跨敤閫楀彿鍒嗛殧 - return data.join(',').replace(/<[^>]*>/g, '') + return data.join(",").replace(/<[^>]*>/g, ""); } else { // 濡傛灉涓嶆槸鏁扮粍锛岀洿鎺ヨ繑鍥炲師濮嬪�� - return data.replace(/<[^>]*>/g, '') + return data.replace(/<[^>]*>/g, ""); } }, // 鍒ゆ柇鏄惁鏈夌敤鎴风瓟妗� isHaveAnswer(data) { - if (typeof data == 'string') { + if (typeof data == "string") { data = data - .replace(/<[^>]*>/g, '') - .replace(/ /g, '') - .trim() + .replace(/<[^>]*>/g, "") + .replace(/ /g, "") + .trim(); if (data.length) { - return true + return true; } else { - return false + return false; } - } else if (typeof data == 'object') { - const answer = data.find((item) => item.length > 0) + } else if (typeof data == "object") { + const answer = data.find((item) => item.length > 0); if (answer) { - return true + return true; } else { - return false + return false; } } else { - return false + return false; } }, // 鎻愪氦閫昏緫 submitPaper() { - - // 鍏抽棴閫�鍑洪〉闈㈢洃鍚� - wx.disableAlertBeforeUnload() this.setData({ submitStatus: true, - loading: true - }) - const child = this.selectComponent('#question-options') - if (this.data.answerType == 'option' || this.data.answerType == 'errorQuestion' || this.data.answerType == 'mock') { + loading: true, + }); + const child = this.selectComponent('#question-options'); + + if ( + this.data.answerType == "option" || + this.data.answerType == "errorQuestion" || + this.data.answerType == "mock" || + this.data.answerType == 'interaction' + ) { // 鍏堥亶鍘嗘墍鏈夐鐩紝灏嗘湭鎵规敼鐨勯鐩壒鏀� - const qustionList = this.data.questionDataList + 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') { - this.toggleCountdown() - this.recordAnswerData() - child.openTestReportDialog() - } else if (this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') { - this.goBack() - } else if (this.data.answerType == 'mock') { - this.toggleCountdown() + if (this.data.answerType == "option") { + this.toggleCountdown(); + this.recordAnswerData(); + // this.selectComponent 鎷夸笉鍒� 缁勪欢浜嗭紝 鏀逛负鐩戝惉缁勪欢浼犲�� 鎵撳紑寮圭獥 + // child.openTestReportDialog(); + this.setData({ + isShowDialog: true + }) + } else if ( + this.data.answerType == "collectQuestion" || + this.data.answerType == "errorQuestion" + ) { + this.goBack(); + } else if (this.data.answerType == "mock") { + this.toggleCountdown(); // 璁剧疆妯¤�冪姸鎬佷负宸插畬鎴� - const mockData = this.data.mockData + const mockData = this.data.mockData; mockData.datas.forEach((item) => { if (item.id == this.data.uuid) { - item.state = '3' + item.state = "3"; item.report = { - userScore: this.data.subjectiveNum - } + userScore: this.data.subjectiveNum, + }; } - }) + }); this.setData({ mockData: mockData, - submitStatus: true - }) - this.setMockInfo(mockData.datas) + submitStatus: true, + }); + this.setMockInfo(mockData.datas); // 璁板綍鐢ㄦ埛绛旈鏁版嵁 - let saveData = [] + let saveData = []; for (let index = 0; index < this.data.questionDataList.length; index++) { const item = this.data.questionDataList[index]; saveData.push({ id: item.id, answer: item.userAnswer, - isRight: item.isRight - }) + isRight: item.isRight, + }); } 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(); + this.setData({ + isShowDialog: true }) - child.openTestReportDialog() + } else if (this.data.answerType == 'interaction') { + this.toggleCountdown(); + this.handleClassQuestion() } this.setData({ - loading: false - }) + loading: false, + showDialog: false, + }); }, // 鍒濆鍖栧嚱鏁� async init() { @@ -435,78 +634,96 @@ loading: true, subjectiveTotal: 0, subjectiveNum: 0, - subjectiveGrade: 0 - }) - if (this.data.answerType == 'option') { + subjectiveGrade: 0, + }); + if (this.data.answerType == "option") { if (this.data) - this.startCountdown() - this.setData({ - countdownTime: 2 * 60 * 60 * 1000 - }) + this.setData({ + countdownTime: 2 * 60 * 60 * 1000, + }); // 娴嬭瘯绛旈 - await this.getCollectIdList() // 鑾峰彇鏀惰棌id鍒楄〃 - await this.getErrorList() // 鑾峰彇閿欓id鍒楄〃 - } else if (this.data.answerType == 'collectQuestion') { + await this.getCollectIdList(); // 鑾峰彇鏀惰棌id鍒楄〃 + await this.getErrorList(); // 鑾峰彇閿欓id鍒楄〃 + } else if (this.data.answerType == "interaction") { this.setData({ - submitStatus: true - }) + countdownTime: 2 * 60 * 60 * 1000, + }); + this.getCurrentClassList() + this.getinteractionInfo() + // 鏁欏浜掑姩 + } else if (this.data.answerType == "collectQuestion") { + this.setData({ + submitStatus: true, + }); // 鎴戠殑鏀惰棌 - await this.getcollectId() // 鑾峰彇鏀惰棌棰樼洰 - } else if (this.data.answerType == 'errorQuestion') { + await this.getcollectId(); // 鑾峰彇鏀惰棌棰樼洰 + } else if (this.data.answerType == "errorQuestion") { this.setData({ - submitStatus: true - }) + submitStatus: true, + }); // 鎴戠殑閿欓 // loadings.value = true - await this.getErrorIdList() - await this.getCollectIdList() // 鑾峰彇鏀惰棌id鍒楄〃 - } else if (this.data.answerType == 'mock') { - this.getErrorList() - this.getCollectIdList() + await this.getErrorIdList(); + await this.getCollectIdList(); // 鑾峰彇鏀惰棌id鍒楄〃 + } else if (this.data.answerType == "mock") { + this.getErrorList(); + this.getCollectIdList(); this.getMockInfo(async (res) => { - let mocklist + let mocklist; try { - mocklist = JSON.parse(res[0].value) + mocklist = JSON.parse(res[0].value); } catch (error) { - mocklist = [] + mocklist = []; } if (mocklist.length && this.data.uuid) { - const oldMockData = mocklist.find((mockItem) => mockItem.id == this.data.uuid) - debugger + const oldMockData = mocklist.find( + (mockItem) => mockItem.id == this.data.uuid + ); this.setData({ - 'mockData.state': oldMockData.state, - 'mockData.score': oldMockData.score, - 'mockData.datas': mocklist, - }) - if (oldMockData.state == '0') { + "mockData.state": oldMockData.state, + "mockData.score": oldMockData.score, + "mockData.datas": mocklist, + }); + if (oldMockData.state == "0") { // 缁勫嵎璐拱浜嗭紝浣嗘湭杩涘叆椤甸潰 - await this.getEduQuizConfig() - } else if (oldMockData.state == '1' || oldMockData.state == '2' || oldMockData.state == '3') { + await this.getEduQuizConfig(); + } else if ( + oldMockData.state == "1" || + oldMockData.state == "2" || + oldMockData.state == "3" + ) { // 缁勫嵎鍚庤繘鍏ヨ繃椤甸潰锛屼絾鏄湭绛旇繃棰� - let oldQuestionList = [] - oldQuestionList = await this.getMockQuestionList() - const userAnswerList = await this.getMockAnswer() + let oldQuestionList = []; + oldQuestionList = await this.getMockQuestionList(); + const userAnswerList = await this.getMockAnswer(); this.setData({ - 'mockData.sumTime': oldMockData.time, - cardList: oldQuestionList + "mockData.sumTime": oldMockData.time, + cardList: oldQuestionList, + }); + await this.getMockDataList(oldQuestionList, userAnswerList); + } + if ( + oldMockData.state == "0" || + oldMockData.state == "1" || + oldMockData.state == "2" + ) { + this.startCountdown(); + this.setData({ + showDialog: true }) - await this.getMockDataList(oldQuestionList, userAnswerList) } - if (oldMockData.state == '0' || oldMockData.state == '1' || oldMockData.state == '2') { - this.startCountdown() - } - if (oldMockData.state == '3') { + if (oldMockData.state == "3") { this.setData({ submitStatus: true, - subjectiveNum: oldMockData.report.userScore - }) + subjectiveNum: oldMockData.report.userScore, + }); } } - }) + }); } }, async restart() { - const countDownRef = this.selectComponent('#countDownRef') + const countDownRef = this.selectComponent("#countDownRef"); this.setData({ loading: true, total: 0, @@ -514,40 +731,47 @@ subjectiveTotal: 0, subjectiveNum: 0, currentIndex: 0, - submitStatus: false - }) - if (this.data.answerType == 'option') { + submitStatus: false, + showDialog: true + }); + if (this.data.answerType == "option") { this.setData({ - countdownTime: 2 * 60 * 60 * 1000 - }) + countdownTime: 2 * 60 * 60 * 1000, + }); this.delAnswerInfo(() => { - this.getQuestionList() - this.clearTime() - }) + this.getQuestionList(); + this.clearTime(); + }); if (!this.data.submitStatus) { - this.startCountdown() + this.startCountdown(); } - } else if (this.data.answerType == 'mock') { + } else if (this.data.answerType == "mock") { // 缁勫嵎妯″紡 // 娓呯┖绛旈璁板綍 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(); }) - this.init() } else { - this.init() - this.clearTime() + this.init(); + this.clearTime(); if (submitStatus.value) { - this.startCountdown() + this.startCountdown(); } } }, @@ -555,90 +779,93 @@ getCollectIdList() { app.MG.identity .getUserKey({ - domain: 'collectData', - keys: [this.data.rootCmsItemId] + domain: "collectData", + keys: [this.data.rootCmsItemId], }) .then((res) => { try { this.setData({ - collectList: JSON.parse(res[0].value) - }) - } catch (error) { - } - if (this.data.answerType == 'option') { + collectList: JSON.parse(res[0].value), + }); + } catch (error) {} + if (this.data.answerType == "option") { // 鍏堣幏鍙栫敤鎴风瓟棰樿褰� this.getAnswerInfo(async (res) => { if (res.length) { // 鏈夎褰曪紝涓嶈兘绛旈锛岀姸鎬佽涓哄凡鎻愪氦 this.setData({ - submitStatus: true - }) - let value = JSON.parse(res[0].value) + submitStatus: true, + }); + let value = JSON.parse(res[0].value); // 鏈夌瓟棰樿褰曪紝寰楀垎璧嬪�� if (value) { - wx.disableAlertBeforeUnload() this.setData({ - submitStatus: true - }) + submitStatus: true, + }); value.dataList.forEach((item) => { - if (item.name == '瀹㈣棰樺緱鍒�' && item.path == this.data.productLinkPath) + if ( + item.name == "瀹㈣棰樺緱鍒�" && + item.path == this.data.productLinkPath + ) this.setData({ - subjectiveNum: item.score - }) - }) + subjectiveNum: item.score, + }); + }); } this.setData({ - currentIndex: value.currentIndex - }) - console.log(this.data.submitStatus); + currentIndex: value.currentIndex, + }); // 鎼哄甫绛旈璁板綍 鑾峰彇棰樼洰 - await this.getQuestionList(value.dataList) + await this.getQuestionList(value.dataList); } else { - await this.getQuestionList() // 鑾峰彇棰樺簱棰樼洰 + await this.getQuestionList(); // 鑾峰彇棰樺簱棰樼洰 + this.setData({ + showDialog: true + }) } - }) + }); } - }) + }); }, // 鑾峰彇閿欓id鍒楄〃 getErrorList() { app.MG.identity .getUserKey({ - domain: 'errorData', - keys: [this.data.rootCmsItemId] + domain: "errorData", + keys: [this.data.rootCmsItemId], }) .then((res) => { try { this.setData({ - errorList: JSON.parse(res[0].value) - }) - } catch (error) { - } - }) + errorList: JSON.parse(res[0].value), + }); + } catch (error) {} + }); }, // 鑾峰彇棰樺簱棰樼洰 async getQuestionList(oldData) { // 娓呯┖姝g‘棰樻暟璁板綍 this.setData({ + noData: false, cardList: [], correctNum: 0, - }) - let flag = 0 + }); + let flag = 0; for (let index = 0; index < this.data.idPathList.length; index++) { const pathitem = this.data.idPathList[index]; - const pathList = this.data.cardList + const pathList = this.data.cardList; pathList.push({ path: pathitem.productLinkPath, catalogName: pathitem.name, - infoList: [] - }) + infoList: [], + }); this.setData({ - cardList: pathList - }) + cardList: pathList, + }); // 鑾峰彇棰樼洰 let query = { - path: '*', - queryType: '*', + path: "*", + queryType: "*", productId: this.data.bookId, cmsPath: pathitem.productLinkPath, itemFields: { @@ -651,245 +878,337 @@ Embedded_QuestionBank_StemStyle: [], Embedded_QuestionBank_OptionStyle: [], Embedded_QuestionBank_KnowledgePoint: [], - Embedded_QuestionBank_Difficulty: [] + Embedded_QuestionBank_Difficulty: [], }, pading: { start: 0, - size: 999 - } + 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 - }) + total: res.datas.cmsDatas[0].datas.length, + }); // total.value += res.datas.cmsDatas[0].datas.length - let oldList + let oldList; if (oldData) { // 鎻愪氦杩囷紝瀛樺湪绛旈璁板綍 - oldList = oldData.find((item) => item.path == pathitem.productLinkPath).infoList - this.setData({ - submitStatus: true - }) + oldList = oldData.find( + (item) => item.path == pathitem.productLinkPath + ).infoList; } res.datas.cmsDatas[0].datas.forEach((item, index) => { - let oldObj = '' - if (oldList) oldObj = oldList.find((oldItem) => oldItem.id == item.id) + 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); let questionObj = { // 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, - isUnfold: '' // 鎺у埗瑙f瀽鐨勬姌鍙犻潰鏉挎槸鍚﹀睍寮� - } + isUnfold: "", // 鎺у埗瑙f瀽鐨勬姌鍙犻潰鏉挎槸鍚﹀睍寮� + }; // 澶氶�夊拰濉┖绛旀鑲负鏁扮粍锛岃杞崲JSON鏍煎紡 if ( - questionObj.questionType == 'completion' || - questionObj.questionType == 'multipleChoice' + questionObj.questionType == "completion" || + questionObj.questionType == "multipleChoice" ) { try { + // questionObj.answer = JSON.parse(questionObj.answer).toString(); questionObj.answer = JSON.parse(questionObj.answer) } catch (error) { - questionObj.answer = item.Embedded_QuestionBank_Answer + questionObj.answer = item.Embedded_QuestionBank_Answer; } } - // questionObj.userAnswer = this.arrayToString(questionObj.userAnswer) - // questionObj.isHaveAnswer = this.isHaveAnswer(questionObj.userAnswer) // 濉┖棰樻敼閫� - if (questionObj.questionType == 'completion') { - let index = 0 + if (questionObj.questionType == "completion") { + let index = 0; for (let i = 0; i < questionObj.stem.length; i++) { - const item = questionObj.stem[i] - if (item == 'input') { + const item = questionObj.stem[i]; + if (item == "input") { questionObj.stem[i] = { num: index, - data: 'input' - } - if (!oldObj) questionObj.userAnswer[index] = '' - index++ + data: "input", + }; + if (!oldObj) questionObj.userAnswer[index] = ""; + index++; } } } - // 鑾峰彇鍥剧墖 - if (questionObj.stemStyle == 'Image' || questionObj.stemStyle == 'TxtAndImage') { - questionObj.stem.stemImage = getPublicImage(questionObj.stem.stemImage, 150) + // 棰樺共瀵屾枃鏈鐞� + 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"').replace('../file', app.config.requestCtx + '/file'); } - if (questionObj.optionStyle == 'Image' || questionObj.optionStyle == 'TxtAndImage') { - questionObj.option.forEach(optionItem => { - if (optionItem.img) optionItem.img = getPublicImage(optionItem.img, 150) - }) + // 閫夐」瀵屾枃鏈鐞� + 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"').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 ( + questionObj.stemStyle == "Image" || + questionObj.stemStyle == "TxtAndImage" + ) { + questionObj.stem.stemImage = getPublicImage( + questionObj.stem.stemImage, + 150 + ); + } + if ( + questionObj.optionStyle == "Image" || + questionObj.optionStyle == "TxtAndImage" + ) { + questionObj.option.forEach((optionItem) => { + if (optionItem.img) + optionItem.img = getPublicImage(optionItem.img, 150); + }); + } + // 瀹㈣棰樻�诲垎璧嬪�� + if (questionObj.questionType !== "shortAnswer") { + this.setData({ + subjectiveGrade: this.data.subjectiveGrade + 2, + }); } // if (questionObj.optionStyle == 'RichText') { // questionObj.option.forEach(optionItem => { // optionItem.txt.replace(/<img>/g, "<img class='imgClass'>") // }) // } - // 鏃ф暟鎹噷 棰樼洰宸茬粡浣滅瓟锛屼慨鏀瑰凡绛旈鐩暟閲� - // if (oldObj && oldObj.userAnswer.length > 0) countDownRef.value.changeAlready() // 鏃ф暟鎹噷 棰樼洰姝g‘ 璁板綍姝g‘鏁伴噺 if (questionObj.isRight) { this.setData({ - correctNum: this.data.correctNum + 1 - }) + correctNum: this.data.correctNum + 1, + }); } - if (pathitem.name == '鍒ゆ柇棰�' || pathitem.name == '濉┖棰�' || pathitem.name == '澶氶�夐' || pathitem.name == '鍗曢�夐' || pathitem.name == '鍚姏棰�') { + if ( + pathitem.name == "鍒ゆ柇棰�" || + pathitem.name == "濉┖棰�" || + pathitem.name == "澶氶�夐" || + pathitem.name == "鍗曢�夐" || + pathitem.name == "鍚姏棰�" + ) { if (oldObj) { this.setData({ - subjectiveTotal: this.data.subjectiveTotal + 1 - }) + subjectiveTotal: this.data.subjectiveTotal + 1, + }); } - } // cardList璧嬪�� - let cardIndex = this.data.cardList.findIndex((item) => item.path == pathitem.productLinkPath) - let infoList = this.data.cardList[cardIndex].infoList - infoList.push(questionObj) + let cardIndex = this.data.cardList.findIndex( + (item) => item.path == pathitem.productLinkPath + ); + let infoList = this.data.cardList[cardIndex].infoList; + infoList.push(questionObj); this.setData({ - [`cardList[${cardIndex}].infoList`]: infoList - }) - // this.data.cardList[this.data.cardList.findIndex((item) => item.path == pathitem.productLinkPath)] - // .infoList - // infoList.push(questionObj) + [`cardList[${cardIndex}].infoList`]: infoList, + }); flag++; - let questionList = [] - const cardUpdatedList = this.data.cardList + let questionList = []; + let grade = 0; + const cardUpdatedList = this.data.cardList; // if (flag == this.data.idPathList.length) { - cardUpdatedList.forEach(aitem => { + cardUpdatedList.forEach((aitem) => { aitem.infoList.forEach((bitem, bindex) => { - questionList.push(bitem) - bitem.number = bindex + 1 - bitem.score = 2 - }) - }) + questionList.push(bitem); + bitem.number = bindex + 1; + bitem.score = 2; + }); + }); this.setData({ questionDataList: questionList, cardList: cardUpdatedList, - }) - }) + }); + }); + }); + } + // 鏈夐鐩啀寮�濮嬪�掕鏃� + if (this.data.questionDataList.length) { + this.startCountdown(); + this.setData({ + loading: false, + showId: this.data.questionDataList[0].id + }) + } else { + this.setData({ + noData: true, + loading: false, }) } - this.setData({ - loading: false - }) }, // 鎵规敼棰樼洰 锛堢粌涔狅紝鎴戠殑閿欓锛屾垜鐨勬敹钘�,锛岀粍鍗凤級 - handleQuestion(num) { - const questionList = this.data.questionDataList - const index = num - 1 >= 0 ? num - 1 : 0 + handleQuestion(index) { + const questionList = this.data.questionDataList; if (questionList[index].isComplete) { // 棰樼洰宸插畬鎴愶紝璺宠繃 - return true + return true; } - questionList[index].isComplete = true - const item = questionList[index] + questionList[index].isComplete = true; + const item = questionList[index]; // 鎵规敼棰樼洰 - if (item.questionType == 'multipleChoice') { + if (item.questionType == "multipleChoice") { // 澶氶�夐 - // subjectiveGrade.value += item.score if (item.answer.length == item.userAnswer.length) { - const sortedArr1 = item.answer.slice().sort() - const sortedArr2 = item.userAnswer.slice().sort() + const sortedArr1 = item.answer.slice().sort(); + const sortedArr2 = item.userAnswer.slice().sort(); questionList[index].isRight = sortedArr1.every( (value, valueIndex) => value === sortedArr2[valueIndex] - ) + ); } else { - questionList[index].isRight = false + questionList[index].isRight = false; } - } else if (item.questionType == 'singleChoice' || item.questionType == 'judge') { + } else if ( + item.questionType == "singleChoice" || + item.questionType == "judge" + ) { // 鍗曢�� 鍒ゆ柇 - // subjectiveGrade.value += item.score - questionList[index].isRight = item.answer == item.userAnswer - } else if (item.questionType == 'shortAnswer') { + questionList[index].isRight = item.answer == item.userAnswer; + } else if (item.questionType == "shortAnswer") { // 绠�绛� 缈昏瘧 - questionList[index].isRight = null - } else if (item.questionType == 'completion') { - // 濉┖ - // subjectiveGrade.value += item.score - if (typeof item.answer == 'string') { - questionList[index].isRight = item.answer == item.userAnswer[0] + questionList[index].isRight = null; + } else if (item.questionType == "completion") { + if (typeof item.answer == "string") { + item.isRight = item.answer == item.userAnswer[0]; } else { if (item.answer.length != item.userAnswer.length) { - questionList[index].isRight = false + item.isRight = false; + } else { + item.isRight = item.answer.every( + (value, index) => value === item.userAnswer[index] + ); + } + } + if (typeof item.answer == "string") { + questionList[index].isRight = item.answer == item.userAnswer[0]; + } else { + if (item.answer.length != item.userAnswer.length) { + questionList[index].isRight = false; } else { questionList[index].isRight = item.answer.every( (value, valueIndex) => value === item.userAnswer[valueIndex] - ) + ); } } } - if (item.questionType != 'shortAnswer') { + if (item.questionType != "shortAnswer") { this.setData({ subjectiveTotal: this.data.subjectiveTotal + 1, - subjectiveGrade: this.data.subjectiveGrade + item.score - }) + }); } - if (questionList[index].isRight && item.questionType != 'shortAnswer') { + if (questionList[index].isRight && item.questionType != "shortAnswer") { // 瀹㈣棰樺洖绛旀纭� this.setData({ subjectiveNum: this.data.subjectiveNum + item.score, - correctNum: this.data.correctNum + 1 - }) + correctNum: this.data.correctNum + 1, + }); } - if (!questionList[index].isRight && item.questionType != 'shortAnswer') { + if (!questionList[index].isRight && item.questionType != "shortAnswer") { // 瀹㈣棰樺洖绛旈敊璇� 璁板綍閿欓 - if (this.data.errorList.findIndex((errorItem) => errorItem == item.id) == -1) { - this.data.errorList.push(item.id) + if ( + this.data.errorList.findIndex((errorItem) => errorItem == item.id) == -1 + ) { + this.data.errorList.push(item.id); } } else { - if (this.data.answerType == 'errorQuestion' || this.data.answerType == 'option') { + if ( + this.data.answerType == "errorQuestion" || + this.data.answerType == "option" + ) { // 浠庨敊棰橀泦涓Щ闄� - let errorIndex = this.data.errorList.findIndex((erroritem) => erroritem == item.id) + let errorIndex = this.data.errorList.findIndex( + (erroritem) => erroritem == item.id + ); if (errorIndex > -1) { - this.data.errorList.splice(errorIndex, 1) + this.data.errorList.splice(errorIndex, 1); } } } - if (this.data.answerType != 'collectQuestion') { + if (this.data.answerType != "collectQuestion") { // 璁板綍閿欓 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) - }) + console.log(res); + }); } this.setData({ - questionDataList: questionList - }) - const cardUpdatedList = this.data.cardList + questionDataList: questionList, + }); + const cardUpdatedList = this.data.cardList; cardUpdatedList.forEach((item) => { item.infoList.forEach((citem) => { if (citem.id == questionList[index].id) { @@ -898,335 +1217,447 @@ }); }); this.setData({ - cardList: cardUpdatedList - }) + cardList: cardUpdatedList, + }); }, // 棰樼洰鏀惰棌鎸夐挳,鏀惰棌鍜屽彇娑堝悓涓�鎺ュ彛锛屽彇娑堟暟缁勫噺鍘昏椤筰d setCollect() { - const citem = this.data.questionDataList[this.data.currentIndex] - const questionList = this.data.questionDataList + const citem = this.data.questionDataList[this.data.currentIndex]; + const questionList = this.data.questionDataList; for (let index = 0; index < questionList.length; index++) { const item = questionList[index]; if (item.id == citem.id) { - item.isCollect = !item.isCollect + item.isCollect = !item.isCollect; } } this.setData({ - questionDataList: questionList - }) + questionDataList: questionList, + }); if (this.data.collectList.length == 0) { this.setData({ - collectList: [citem.id] - }) + collectList: [citem.id], + }); } else { - const collectItme = this.data.collectList.filter((item) => item == citem.id) + const collectItme = this.data.collectList.filter( + (item) => item == citem.id + ); if (collectItme.length) { - const arr = this.data.collectList.filter((item) => item != citem.id) + const arr = this.data.collectList.filter((item) => item != citem.id); this.setData({ - collectList: arr - }) + collectList: arr, + }); } else { - const collectArr = this.data.collectList - collectArr.push(citem.id) + const collectArr = this.data.collectList; + collectArr.push(citem.id); this.setData({ - collectList: collectArr - }) + collectList: collectArr, + }); } } 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)) - } + dataList: JSON.parse(JSON.stringify(this.data.cardList)), + }; for (let i = 0; i < setInfoData.dataList.length; i++) { - const item = setInfoData.dataList[i] - if (!item.name && !item.name == '瀹㈣棰樺緱鍒�') { + const item = setInfoData.dataList[i]; + if (!item.name && !item.name == "瀹㈣棰樺緱鍒�") { for (let j = 0; j < item.infoList.length; j++) { let obj = { id: item.infoList[j].id, userAnswer: item.infoList[j].userAnswer, isComplete: item.infoList[j].isComplete, isRight: item.infoList[j].isRight, - isCollect: item.infoList[j].isCollect - } - item.infoList[j] = obj + isCollect: item.infoList[j].isCollect, + }; + item.infoList[j] = obj; } } } - - this.setAnswerInfo(setInfoData) + 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) => { }) + .then((res) => {}); }, - // 鑾峰彇绛旈鏁版嵁 + // 鑾峰彇鏃х瓟棰樻暟鎹� getAnswerInfo(callback) { app.MG.identity .getUserKey({ - domain: 'answerData', - keys: [this.data.productLinkPath] + domain: "answerData", + keys: [this.data.productLinkPath], }) .then((res) => { - if (callback) callback(res) - }) + if (callback) callback(res); + }); }, - // 鍒犻櫎绛旈鏁版嵁 + // 鍒犻櫎鏃х瓟棰樻暟鎹� delAnswerInfo(callback) { app.MG.identity .delUserKey({ - domain: 'answerData', - keys: [this.data.productLinkPath] + domain: "answerData", + keys: [this.data.productLinkPath], }) .then((res) => { - if (callback) callback() - }) + if (callback) callback(); + }); }, // 鎴戠殑鏀惰棌妯″紡涓嬭幏鍙栨敹钘忛鐩甶d async getcollectId() { app.MG.identity .getUserKey({ - domain: 'collectData', - keys: [this.data.rootCmsItemId] + domain: "collectData", + keys: [this.data.rootCmsItemId], }) .then(async (res) => { try { this.setData({ - collectList: JSON.parse(res[0].value) - }) - // total.value = collectList.value.length - } catch (error) { - } + collectList: JSON.parse(res[0].value), + }); + } catch (error) {} if (this.data.collectList && this.data.collectList.length) { - await this.getCollectDataList() + await this.getCollectDataList(); } else { this.setData({ - loading: false - }) + loading: false, + noData: true + }); wx.showModal({ - title: '鎻愮ず', - content: '鏀惰棌澶规殏鏃犳暟鎹�',//editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭 - editable: false,//鏄惁鏄剧ず杈撳叆妗� + title: "鎻愮ず", + content: "鏀惰棌澶规殏鏃犳暟鎹�", //editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭 + confirmColor: "#ff6c00", + cancelColor: "#949494", + editable: false, //鏄惁鏄剧ず杈撳叆妗� showCancel: false, success: (res) => { if (res.confirm) { this.setData({ - submitStatus: true - }) - this.goBack() + submitStatus: true, + }); + this.goBack(); } - - } - }) + }, + }); } - }) + }); }, // 鑾峰彇鏀惰棌澶� async getCollectDataList() { - let questionArr = [] + let questionArr = []; this.setData({ - cardList: [ + cardList: [{ + catalogName: "鍗曢�夐", + infoList: [], + }, { - catalogName: '鏀惰棌澶�', - infoList: [] - } - ] - }) - let query = { - path: '*', - cmsPath: this.data.rootCmsItemId, - cmsType: '*', - productId: this.data.bookId, - queryType: '*', - itemIds: this.data.collectList.map((item) => item + ''), - itemFields: { - Embedded_QuestionBank_Stem: [], - Embedded_QuestionBank_AnalysisCon: [], - Embedded_QuestionBank_Answer: [], - Embedded_QuestionBank_Option: [], - Embedded_QuestionBank_QuestionType: [], - Embedded_QuestionBank_StemStyle: [], - Embedded_QuestionBank_OptionStyle: [], - Embedded_QuestionBank_KnowledgePoint: [], - Embedded_QuestionBank_Difficulty: [] + catalogName: "鍒ゆ柇棰�", + infoList: [], + }, + { + catalogName: "澶氶�夐", + infoList: [], + }, + { + catalogName: "濉┖棰�", + infoList: [], + }, + { + catalogName: "绠�绛旈", + infoList: [], + }, + ], + }); + let singleChoiceArr = []; // 鍗曢�� + let judgeArr = []; // 鍒ゆ柇 + let shortArr = []; // 绠�绛� + let multipleChoiceArr = []; // 澶氶�� + let completionArr = []; // 濉┖ + for (let qindex = 0; qindex < this.data.collectList.length; qindex++) { + const qitem = this.data.collectList[qindex]; + let query = { + path: "*", + cmsPath: this.data.rootCmsItemId, + cmsType: "*", + productId: this.data.bookId, + queryType: "*", + itemIds: qitem + "", + itemFields: { + Embedded_QuestionBank_Stem: [], + Embedded_QuestionBank_AnalysisCon: [], + Embedded_QuestionBank_Answer: [], + Embedded_QuestionBank_Option: [], + Embedded_QuestionBank_QuestionType: [], + Embedded_QuestionBank_StemStyle: [], + Embedded_QuestionBank_OptionStyle: [], + Embedded_QuestionBank_KnowledgePoint: [], + Embedded_QuestionBank_Difficulty: [], + }, + }; + if (this.data.storeInfo) { + query.storeInfo = this.data.storeInfo } - } - 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), // 棰樺共 - answer: item.Embedded_QuestionBank_Answer, // 绛旀 - 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' - ? [] - : '', - isSubmit: false, // 鏌ョ湅瑙f瀽 - isRight: null, // 鏄惁姝g‘ - isComplete: false, - isCollect: true - } - // 澶氶�夊拰濉┖绛旀鑲负鏁扮粍锛岃杞崲JSON鏍煎紡 - if ( - questionObj.questionType == 'completion' || - questionObj.questionType == 'multipleChoice' - ) { - try { - questionObj.answer = JSON.parse(questionObj.answer) - } catch (error) { - // - } - } - // 濉┖棰樻敼閫� - if (questionObj.questionType == 'completion') { - let index = 0 - for (let i = 0; i < questionObj.stem.length; i++) { - const item = questionObj.stem[i] - if (item == 'input') { - questionObj.stem[i] = { - num: index, - data: 'input' - } - questionObj.userAnswer[index] = '' - index++ + 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), // 棰樺共 + answer: item.Embedded_QuestionBank_Answer, // 绛旀 + 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" ? [] : "", + isSubmit: false, // 鏌ョ湅瑙f瀽 + isRight: null, // 鏄惁姝g‘ + isComplete: false, + isCollect: true, + }; + // 澶氶�夊拰濉┖绛旀鑲负鏁扮粍锛岃杞崲JSON鏍煎紡 + if ( + questionObj.questionType == "completion" || + questionObj.questionType == "multipleChoice" + ) { + console.log(questionObj.answer, "111") + try { + questionObj.answer = JSON.parse(questionObj.answer).toString(); + } catch (error) { + questionObj.answer = item.Embedded_QuestionBank_Answer; } } - } - // 鑾峰彇鍥剧墖 - if (questionObj.stemStyle == 'Image' || questionObj.stemStyle == 'TxtAndImage') { - questionObj.stem.stemImage = getPublicImage(questionObj.stem.stemImage, 150) - } - if (questionObj.optionStyle == 'Image' || questionObj.optionStyle == 'TxtAndImage') { - questionObj.option.forEach(optionItem => { - 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) - }) - // loadings.value = false - this.setData({ - questionDataList: questionArr, - ['cardList[0].infoList']: questionArr, - loading: false, - }) - }) + // 濉┖棰樻敼閫� + if (questionObj.questionType == "completion") { + let index = 0; + for (let i = 0; i < questionObj.stem.length; i++) { + const item = questionObj.stem[i]; + if (item == "input") { + questionObj.stem[i] = { + num: index, + data: "input", + }; + questionObj.userAnswer[index] = ""; + index++; + } + } + } + // 鑾峰彇鍥剧墖 + if ( + questionObj.stemStyle == "Image" || + questionObj.stemStyle == "TxtAndImage" + ) { + questionObj.stem.stemImage = getPublicImage( + questionObj.stem.stemImage, + 150 + ); + } + if ( + questionObj.optionStyle == "Image" || + questionObj.optionStyle == "TxtAndImage" + ) { + questionObj.option.forEach((optionItem) => { + if (optionItem.img) + optionItem.img = getPublicImage(optionItem.img, 150); + }); + } + // 棰樺共瀵屾枃鏈鐞� + 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"').replace('../file', app.config.requestCtx + '/file'); + } + // 閫夐」瀵屾枃鏈鐞� + 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"').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 = "鍒ゆ柇棰�"; + 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); + } + }); + }); + } + this.setData({ + ["cardList[0].infoList"]: singleChoiceArr, + ["cardList[1].infoList"]: judgeArr, + ["cardList[2].infoList"]: multipleChoiceArr, + ["cardList[3].infoList"]: completionArr, + ["cardList[4].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, + showId: questionArr[0].id, + cardList: cardList, + loading: false, + }); }, // 鎴戠殑閿欓妯″紡涓嬭幏鍙栭敊棰榠d鍒楄〃 async getErrorIdList() { await app.MG.identity .getUserKey({ - domain: 'errorData', - keys: [this.data.rootCmsItemId] + domain: "errorData", + keys: [this.data.rootCmsItemId], }) .then((res) => { try { this.setData({ - errorList: JSON.parse(res[0].value) - }) - } catch (error) { - } + errorList: JSON.parse(res[0].value), + }); + } catch (error) {} if (this.data.errorList && this.data.errorList.length) { - this.getErrorDataList() + this.getErrorDataList(); } else { this.setData({ - loading: true - }) + loading: false, + noData: true + }); wx.showModal({ - title: '鎻愮ず', - content: '閿欓闆嗘殏鏃犳暟鎹�',//editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭 - editable: false,//鏄惁鏄剧ず杈撳叆妗� + title: "鎻愮ず", + content: "閿欓闆嗘殏鏃犳暟鎹�", //editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭 + confirmColor: "#ff6c00", + cancelColor: "#949494", + editable: false, //鏄惁鏄剧ず杈撳叆妗� showCancel: false, success: (res) => { if (res.confirm) { this.setData({ - submitStatus: true - }) - this.goBack() + submitStatus: true, + }); + this.goBack(); } - } - }) + }, + }); } - }) + }); }, // 鑾峰彇閿欓闆� async getErrorDataList() { this.setData({ - cardList: [ + cardList: [{ + catalogName: "鍗曢�夐", + infoList: [], + }, { - catalogName: '閿欓闆�', - infoList: [] - } - ] - }) + catalogName: "鍒ゆ柇棰�", + infoList: [], + }, + { + catalogName: "澶氶�夐", + infoList: [], + }, + { + catalogName: "濉┖棰�", + infoList: [], + }, + { + catalogName: "绠�绛旈", + infoList: [], + }, + ], + }); + let singleChoiceArr = []; // 鍗曢�� + let judgeArr = []; // 鍒ゆ柇 + let shortArr = []; // 绠�绛� + let multipleChoiceArr = []; // 澶氶�� + let completionArr = []; // 濉┖ let query = { - path: '*', + path: "*", cmsPath: this.data.rootCmsItemId, - cmsType: '*', + cmsType: "*", productId: this.data.bookId, - queryType: '*', - itemIds: this.data.errorList.map((item) => item + ''), + queryType: "*", + itemIds: this.data.errorList.map((item) => item + ""), itemFields: { Embedded_QuestionBank_Stem: [], Embedded_QuestionBank_AnalysisCon: [], @@ -1236,200 +1667,285 @@ Embedded_QuestionBank_StemStyle: [], Embedded_QuestionBank_OptionStyle: [], Embedded_QuestionBank_KnowledgePoint: [], - Embedded_QuestionBank_Difficulty: [] - } + Embedded_QuestionBank_Difficulty: [], + }, + }; + if (this.data.storeInfo) { + query.storeInfo = this.data.storeInfo } await app.MG.store.getProductDetail(query).then((res) => { - let questionArr = [] + 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, - isCollect: this.data.collectList.some((collectItem) => collectItem == item.id) - } + isCollect: this.data.collectList.some( + (collectItem) => collectItem == item.id + ), + }; // 澶氶�夊拰濉┖绛旀鑲负鏁扮粍锛岃杞崲JSON鏍煎紡 if ( - questionObj.questionType == 'completion' || - questionObj.questionType == 'multipleChoice' + questionObj.questionType == "completion" || + questionObj.questionType == "multipleChoice" ) { try { - questionObj.answer = JSON.parse(questionObj.answer) + questionObj.answer = JSON.parse(questionObj.answer).toString(); } catch (error) { - // + questionObj.answer = item.Embedded_QuestionBank_Answer; } } // 濉┖棰樻敼閫� - if (questionObj.questionType == 'completion') { - let index = 0 + if (questionObj.questionType == "completion") { + let index = 0; for (let i = 0; i < questionObj.stem.length; i++) { - const item = questionObj.stem[i] - if (item == 'input') { + const item = questionObj.stem[i]; + if (item == "input") { questionObj.stem[i] = { num: index, - data: 'input' - } - questionObj.userAnswer[index] = '' - index++ + data: "input", + }; + questionObj.userAnswer[index] = ""; + index++; } } } // 鑾峰彇鍥剧墖 - if (questionObj.stemStyle == 'Image' || questionObj.stemStyle == 'TxtAndImage') { - questionObj.stem.stemImage = getPublicImage(questionObj.stem.stemImage, 150) + if ( + questionObj.stemStyle == "Image" || + questionObj.stemStyle == "TxtAndImage" + ) { + questionObj.stem.stemImage = getPublicImage( + questionObj.stem.stemImage, + 150 + ); } - if (questionObj.optionStyle == 'Image' || questionObj.optionStyle == 'TxtAndImage') { - questionObj.option.forEach(optionItem => { - if (optionItem.img) optionItem.img = getPublicImage(optionItem.img, 150) - }) + if ( + questionObj.optionStyle == "Image" || + questionObj.optionStyle == "TxtAndImage" + ) { + questionObj.option.forEach((optionItem) => { + 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"').replace('../file', app.config.requestCtx + '/file'); + } + // 閫夐」瀵屾枃鏈鐞� + 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"').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 = "鍒ゆ柇棰�"; + 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[4].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, - loading: false - }) - }) - // loadings.value = false + showId: questionArr[0].id, + cardList: cardList, + loading: false, + }); + console.log(this.data.questionDataList, "questionDataList"); + }); }, // 鑾峰彇缁勫嵎缁撴灉 async getEduQuizConfig() { await app.MG.edu .getEduQuizConfigResult({ - idOrRefCode: this.data.mockid + idOrRefCode: this.data.mockid, }) .then(async (configRes) => { // 鑾峰彇 鍒嗘暟 鏃堕棿 this.setData({ - 'mockData.score': configRes.score - }) + "mockData.score": configRes.score, + }); try { this.setData({ - 'mockData.time': JSON.parse(configRes.config).time * 1000, - countdownTime: JSON.parse(configRes.config).time * 1000 - }) + "mockData.time": JSON.parse(configRes.config).time * 1000, + countdownTime: JSON.parse(configRes.config).time * 1000, + }); } catch (error) { this.setData({ - 'mockData.time': 3600 * 1000, + "mockData.time": 3600 * 1000, countdownTime: 3600 * 1000, - }) + }); } this.setData({ - 'mockData.sumTime': this.data.mockData.time - }) - let itemIds = [] - let numberIndex = 1 + "mockData.sumTime": this.data.mockData.time, + }); + let itemIds = []; + let numberIndex = 1; // 鑾峰彇鎶介缁撴灉 const cardList = configRes.eduQuizConfigStageResultList.map((item) => { - let questionIds = [] + let questionIds = []; // 鑾峰彇蹇呭惈棰樼洰 let list = item.cmsItemList.map((idItem) => { - itemIds.push(idItem.id + '') - questionIds.push({ id: idItem.id + '', score: idItem.score }) - numberIndex++ + itemIds.push(idItem.id + ""); + questionIds.push({ + id: idItem.id + "", + score: idItem.score, + }); + numberIndex++; return { number: numberIndex, id: idItem.id, - score: idItem.score - } - }) + score: idItem.score, + }; + }); // 鑾峰彇鎶介棰樼洰 - let extractList = [] + let extractList = []; for (let i = 0; i < item.generatorResultList.length; i++) { - const extractItem = item.generatorResultList[i] - let extractItemList = extractItem.cmsItemList.map((extractCmsItem) => { - itemIds.push(extractCmsItem.id + '') - questionIds.push({ id: extractCmsItem.id + '', score: extractCmsItem.score }) - numberIndex++ - return { - number: numberIndex, - id: extractCmsItem.id, - score: extractCmsItem.score + const extractItem = item.generatorResultList[i]; + let extractItemList = extractItem.cmsItemList.map( + (extractCmsItem) => { + itemIds.push(extractCmsItem.id + ""); + questionIds.push({ + id: extractCmsItem.id + "", + score: extractCmsItem.score, + }); + numberIndex++; + return { + number: numberIndex, + id: extractCmsItem.id, + score: extractCmsItem.score, + }; } - }) - extractList = extractList.concat(extractItemList) + ); + extractList = extractList.concat(extractItemList); } return { path: item.id, catalogName: item.name, - infoList: list.concat(extractList) - } - }) + infoList: list.concat(extractList), + }; + }); this.setData({ - cardList: cardList - }) + cardList: cardList, + }); // 鏇存柊璇ユ潯缁勫嵎鐨勬暟鎹姸鎬侊紝鍖呮嫭璁板綍鏀硅瘯鍗锋�诲垎锛屾洿鏀圭粍鍗风姸鎬乻tate涓�1锛岃〃绀哄凡缁忔娊棰樺畬鎴愶紝骞惰灏嗘娊灞夋暟鎹褰曚笅鏉� if (this.data.mockData.datas && this.data.mockData.datas.length) { - const mockData = this.data.mockData + const mockData = this.data.mockData; mockData.datas.forEach((item, index) => { if (item.id == this.data.uuid) { - item.state = '1' - item.time = mockData.time - item.score = configRes.score - mockData.state = '1' + item.state = "1"; + item.time = mockData.time; + item.score = configRes.score; + mockData.state = "1"; } - }) + }); this.setData({ - mockData: mockData - }) + mockData: mockData, + }); } - this.setMockInfo(this.data.mockData.datas) // 璁板綍璇曞嵎鎬诲垎 鏃堕暱锛屼慨鏀箂tate涓� 1 + this.setMockInfo(this.data.mockData.datas); // 璁板綍璇曞嵎鎬诲垎 鏃堕暱锛屼慨鏀箂tate涓� 1 // 鏇存柊鏈湴mockData - this.saveMockQuestionList(this.data.cardList) // 璁板綍棰樼洰鍒楄〃 - await this.getMockDataList(this.data.cardList) // 璇锋眰棰樼洰鏁版嵁 - }) + this.saveMockQuestionList(this.data.cardList); // 璁板綍棰樼洰鍒楄〃 + await this.getMockDataList(this.data.cardList); // 璇锋眰棰樼洰鏁版嵁 + }); }, // 鑾峰彇缁勫嵎棰樼洰鍒楄〃 async getMockDataList(questionList, oldList) { - const questionDataList = this.data.questionDataList + const questionDataList = this.data.questionDataList; for (let pathindex = 0; pathindex < questionList.length; pathindex++) { const pathitem = questionList[pathindex]; - let itemIds = [] - pathitem.infoList.forEach(item => { - itemIds.push(item.id + '') - }) + let itemIds = []; + pathitem.infoList.forEach((item) => { + itemIds.push(item.id + ""); + }); let query = { - path: '*', + path: "*", cmsPath: this.data.rootCmsItemId, - cmsType: '*', + cmsType: "*", productId: this.data.bookId, - queryType: '*', + queryType: "*", itemIds, itemFields: { Embedded_QuestionBank_Stem: [], @@ -1440,243 +1956,573 @@ Embedded_QuestionBank_StemStyle: [], Embedded_QuestionBank_OptionStyle: [], Embedded_QuestionBank_KnowledgePoint: [], - Embedded_QuestionBank_Difficulty: [] - } + 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,缁欐瘡棰樿祴鍊煎垎鏁� - let oldObj - if (oldList) oldObj = oldList.find((oldItem) => oldItem.id == item.id) + let oldObj; + if (oldList) + oldObj = oldList.find((oldItem) => oldItem.id == item.id); let questionObj = { // 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), // 棰樺共 + 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), // 棰樺共 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, + isComplete: this.data.mockData.state == "3" ? true : false, isCollect: this.data.collectList.indexOf(item.id) > -1 ? true : false, - isUnfold: '' // 鎺у埗瑙f瀽鐨勬姌鍙犻潰鏉挎槸鍚﹀睍寮� - } + isUnfold: "", // 鎺у埗瑙f瀽鐨勬姌鍙犻潰鏉挎槸鍚﹀睍寮� + }; // 澶氶�夊拰濉┖绛旀鑲负鏁扮粍锛岃杞崲JSON鏍煎紡 if ( - questionObj.questionType == 'completion' || - questionObj.questionType == 'multipleChoice' + questionObj.questionType == "completion" || + questionObj.questionType == "multipleChoice" ) { try { - questionObj.answer = JSON.parse(questionObj.answer) + questionObj.answer = JSON.parse(questionObj.answer).toString(); } catch (error) { - questionObj.answer = item.Embedded_QuestionBank_Answer + questionObj.answer = item.Embedded_QuestionBank_Answer; } } // 濉┖棰樻敼閫� - if (questionObj.questionType == 'completion') { - let index = 0 + if (questionObj.questionType == "completion") { + let index = 0; for (let i = 0; i < questionObj.stem.length; i++) { - const item = questionObj.stem[i] - if (item == 'input') { + const item = questionObj.stem[i]; + if (item == "input") { questionObj.stem[i] = { num: index, - data: 'input' - } - if (!oldObj) questionObj.userAnswer[index] = '' - index++ + data: "input", + }; + if (!oldObj) questionObj.userAnswer[index] = ""; + index++; } } } - // 鑾峰彇鍥剧墖 - if (questionObj.stemStyle == 'Image' || questionObj.stemStyle == 'TxtAndImage') { - questionObj.stem.stemImage = getPublicImage(questionObj.stem.stemImage, 150) + // 棰樺共瀵屾枃鏈鐞� + 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"').replace('../file', app.config.requestCtx + '/file'); } - if (questionObj.optionStyle == 'Image' || questionObj.optionStyle == 'TxtAndImage') { - questionObj.option.forEach(optionItem => { - if (optionItem.img) optionItem.img = getPublicImage(optionItem.img, 150) - }) + // 閫夐」瀵屾枃鏈鐞� + 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"').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 ( + questionObj.stemStyle == "Image" || + questionObj.stemStyle == "TxtAndImage" + ) { + questionObj.stem.stemImage = getPublicImage( + questionObj.stem.stemImage, + 150 + ); + } + if ( + questionObj.optionStyle == "Image" || + questionObj.optionStyle == "TxtAndImage" + ) { + questionObj.option.forEach((optionItem) => { + if (optionItem.img) + optionItem.img = getPublicImage(optionItem.img, 150); + }); + } + // 瀹㈣棰樻�诲垎璧嬪�� + if (questionObj.questionType !== "shortAnswer") { + this.setData({ + subjectiveGrade: this.data.subjectiveGrade + questionObj.score, + }); } if (oldObj && oldObj.isRight) { this.setData({ - correctNum: this.data.correctNum + 1 - }) + correctNum: this.data.correctNum + 1, + }); } - if (item.questionType != 'shortAnswer' && item.isComplete) { + if (item.questionType != "shortAnswer" && item.isComplete) { this.setData({ - subjectiveTotal: this.data.subjectiveTotal + 1 - }) + subjectiveTotal: this.data.subjectiveTotal + 1, + }); } // if (oldObj && isHaveAnswer(oldObj.answer)) countDownRef.value.changeAlready() // cardList璧嬪�� - let cardIndex = this.data.cardList.findIndex((item) => item.catalogName == pathitem.catalogName) - let infoIndex = this.data.cardList[cardIndex].infoList.findIndex(infoItem => infoItem.id == item.id) + let cardIndex = this.data.cardList.findIndex( + (item) => item.catalogName == pathitem.catalogName + ); + let infoIndex = this.data.cardList[cardIndex].infoList.findIndex( + (infoItem) => infoItem.id == item.id + ); this.setData({ - [`cardList[${cardIndex}].infoList[${infoIndex}]`]: questionObj - }) - let questionList = [] - const cardUpdatedList = this.data.cardList - cardUpdatedList.forEach(aitem => { + [`cardList[${cardIndex}].infoList[${infoIndex}]`]: questionObj, + }); + let questionList = []; + const cardUpdatedList = this.data.cardList; + cardUpdatedList.forEach((aitem) => { aitem.infoList.forEach((bitem, bindex) => { - questionList.push(bitem) - bitem.number = bindex + 1 - }) - }) + questionList.push(bitem); + bitem.number = bindex + 1; + }); + }); this.setData({ questionDataList: questionList, - cardList: cardUpdatedList - }) - }) - }) + cardList: cardUpdatedList, + }); + }); + }); } this.setData({ - loading: false - }) + loading: false, + showId: this.data.questionDataList[0].id + }); }, // 鑾峰彇缁勫嵎鏁版嵁 getMockInfo(callback) { app.MG.identity .getUserKey({ - domain: 'mockData', - keys: [this.data.bookId] + domain: "mockData", + keys: [this.data.bookId], }) .then((res) => { - if (callback) callback(res) - }) + if (callback) callback(res); + }); }, // 璁板綍璐拱缁勫嵎鏃堕棿 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('妯¤�冮鐩垪琛ㄥ凡璁板綍') - }) + console.log("妯¤�冮鐩垪琛ㄥ凡璁板綍"); + }); }, // 鑾峰彇璁板綍缁勫嵎棰樼洰鍒楄〃 async getMockQuestionList() { - let list = [] + let list = []; await app.MG.identity .getUserKey({ - domain: 'mockQuestionData', - keys: [this.data.uuid] + domain: "mockQuestionData", + keys: [this.data.uuid], }) .then((res) => { - list = JSON.parse(res[0].value) - }) - return list + list = JSON.parse(res[0].value); + }); + return list; }, // 鑾峰彇妯¤�冪敤鎴风瓟棰樻暟鎹� async getMockAnswer() { - let data + let data; await app.MG.identity .getUserKey({ - domain: 'mockAnswerData', - keys: [this.data.uuid] + domain: "mockAnswerData", + keys: [this.data.uuid], }) .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, - 'mockData.answer': JSON.parse(res[0].value).answerData - }) + "mockData.time": JSON.parse(res[0].value).time, + 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)); - data = JSON.parse(res[0].value).answerData + data = JSON.parse(res[0].value).answerData; } - }) - return data + }); + return data; }, // 璁板綍妯¤�冪瓟棰樻暟鎹� saveMockData() { - const data = this.data.mockData.datas.find((itme) => itme.id == this.data.uuid) - if (data.state == '3') return true - const saveData = this.data.mockData.answer + const data = this.data.mockData.datas.find( + (itme) => itme.id == this.data.uuid + ); + if (data.state == "3") return true; + const saveData = this.data.mockData.answer; for (let i = 0; i < this.data.questionDataList.length; i++) { - const item = this.data.questionDataList[i] + const item = this.data.questionDataList[i]; if (this.isHaveAnswer(item.userAnswer)) { - const index = saveData.findIndex((saveitem) => saveitem.id == item.id) - if (index + '' != '-1') { - saveData[index].answer = item.userAnswer + const index = saveData.findIndex((saveitem) => saveitem.id == item.id); + if (index + "" != "-1") { + saveData[index].answer = item.userAnswer; } else { saveData.push({ id: item.id, - answer: item.userAnswer - }) + answer: item.userAnswer, + }); } } } - // - if (this.data.mockData.state == '1') { - const datas = this.data.mockData.datas + // + if (this.data.mockData.state == "1") { + const datas = this.data.mockData.datas; datas.forEach((item) => { if (item.id == this.data.uuid) { - item.state = '2' + item.state = "2"; } - }) - this.setMockInfo(datas) + }); + this.setMockInfo(datas); } - // + // 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({ - saveTime: 20 + saveTime: 20, + }); + console.log("妯¤�冪瓟棰樻暟鎹凡璁板綍"); + }); + }, + + // 瀵屾枃鏈鐞� + formatRichText(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; + }, + // 鏁欏浜掑姩妯″紡鐩稿叧 + // 鑾峰彇鐝骇鍒楄〃 + 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 }) - console.log('妯¤�冪瓟棰樻暟鎹凡璁板綍') + // 鍒ゆ柇鐝骇 鏄惁鎵�灞炰簬璇ヤ功 + 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