From cf4bbfabdd5da60ac78cc43a4febbb7e7d559f92 Mon Sep 17 00:00:00 2001 From: 闫增涛 <1829501689@qq.com> Date: 星期五, 22 十一月 2024 11:11:40 +0800 Subject: [PATCH] 公式输入框样式 --- src/views/examination/index.vue | 151 +++++++++++++++++++++++++------------------------- 1 files changed, 75 insertions(+), 76 deletions(-) diff --git a/src/views/examination/index.vue b/src/views/examination/index.vue index cf4cefa..41dfcc6 100644 --- a/src/views/examination/index.vue +++ b/src/views/examination/index.vue @@ -85,6 +85,7 @@ :cardList="examination.cardList" @setCollect="setCollect" @onChangeRadio="onChangeRadio" + @onChangeInput="onChangeInput" /> </div> </li> @@ -190,7 +191,7 @@ getErrorList() } else if (props.type == 'collectQuestion') { examination.submitStatus = true - await getcollectId() // 鑾峰彇鏀惰棌棰樼洰 + await getcollectId() // 鑾峰彇鏀惰棌棰樼洰id // 鏀惰棌澶� } else if (props.type == 'errorQuestion') { examination.submitStatus = true @@ -210,7 +211,7 @@ examination.loading = true examination.submitStatus = false examination.cardList = [] - examination.collectList = [] + // examination.collectList = [] examination.errorList = [] goTop() if (props.type == 'option') { @@ -244,7 +245,7 @@ } else if (item.questionType == 'singleChoice' || item.questionType == 'judge') { // 鍗曢�� 鍒ゆ柇 item.isRight = item.answer == item.userAnswer - } else if (item.questionType == 'shortAnswer') { + } else if (item.questionType == 'shortAnswer' || item.questionType == 'formula') { // 绠�绛� 缈昏瘧 item.isRight = null } else if (item.questionType == 'completion') { @@ -275,7 +276,7 @@ citem.isUnfold = '' examination.isCollapse = false } else { - citem.questionType == 'shortAnswer' ? (citem.isUnfold = true) : (citem.isUnfold = citem.id) + citem.questionType == 'shortAnswer' || citem.questionType == 'formula' ? (citem.isUnfold = true) : (citem.isUnfold = citem.id) examination.isCollapse = true } } @@ -289,8 +290,13 @@ examination.submitStatus = true } // 棰樼洰鏀惰棌鎸夐挳,鏀惰棌鍜屽彇娑堝悓涓�鎺ュ彛锛屽彇娑堟暟缁勫噺鍘昏椤筰d -const setCollect = (num: number, number: number) => { - const item = examination.cardList[num].infoList[number] +const setCollect = (num: number, number?: number) => { + let item = null + if(number) { + item = examination.cardList[num].infoList[number] + } else { + item = examination.cardList[num] + } item.isCollect = !item.isCollect if (item.isJson) { // json棰樼洰鏀惰棌鍙栨秷 @@ -349,24 +355,24 @@ domain: 'collectData', keys: [props.activeBook.bookId] }) - .then((res) => { + .then((res:any) => { console.log('鏀惰棌鏁版嵁', res) try { const collect = JSON.parse(res[0].value) if (collect.length) { - examination.collectList = collect.find((citem) => citem.type == 'bits').collectList + examination.collectList = collect.find((citem:any) => citem.type == 'bits').collectList examination.allCollect[0].collectList = collect.find( - (citem) => citem.type == 'bits' + (citem:any) => citem.type == 'bits' ).collectList examination.allCollect[1].collectList = collect.find( - (citem) => citem.type == 'json' + (citem:any) => citem.type == 'json' ).collectList } } catch (error) { console.log('鏆傛棤鏁版嵁') } if (props.type == 'option') { - getAnswerInfo(async (res) => { + getAnswerInfo(async (res:any) => { if (res.length) { // 鏈夎褰曪紝涓嶈兘绛旈锛岀姸鎬佽涓哄凡鎻愪氦 examination.submitStatus = true @@ -624,16 +630,16 @@ domain: 'collectData', keys: [props.activeBook.bookId] }) - .then(async (res) => { + .then(async (res:any) => { try { const collect = JSON.parse(res[0].value) if (collect.length) { - examination.collectList = collect.find((citem) => citem.type == 'bits').collectList + examination.collectList = collect.find((citem:any) => citem.type == 'bits').collectList examination.allCollect[0].collectList = collect.find( - (citem) => citem.type == 'bits' + (citem:any) => citem.type == 'bits' ).collectList examination.allCollect[1].collectList = collect.find( - (citem) => citem.type == 'json' + (citem:any) => citem.type == 'json' ).collectList } } catch (error) {} @@ -663,14 +669,10 @@ } // 鑾峰彇鏀惰棌澶� const getCollectDataList = async () => { - if (!examination.collectList.length) { - examination.loading = false - examination.noData = true - return false - } + console.log('鏀惰棌id',examination.allCollect) // 寮�濮嬭姹� let oldData = null - let oldList = [] + let oldList:any = [] let cardList = [ { catalogName: '鍗曢�夐', @@ -693,11 +695,11 @@ infoList: [] } ] - let singleChoiceArr = [] // 鍗曢�� - let judgeArr = [] // 鍒ゆ柇 - let shortArr = [] // 绠�绛� - let multipleChoiceArr = [] // 澶氶�� - let completionArr = [] // 濉┖ + let singleChoiceArr:any = [] // 鍗曢�� + let judgeArr:any = [] // 鍒ゆ柇 + let shortArr:any = [] // 绠�绛� + let multipleChoiceArr:any = [] // 澶氶�� + let completionArr:any = [] // 濉┖ // 11 for (let qindex = 0; qindex < examination.collectList.length; qindex++) { const qitem = examination.collectList[qindex] @@ -757,7 +759,7 @@ isSubmit: false, // 鏌ョ湅瑙f瀽 isRight: null, // 鏄惁姝g‘ isComplete: false, - isCollect: examination.collectList.indexOf(item.id) > -1 ? true : false, + isCollect: true, isUnfold: '' } // 澶氶�夊拰濉┖绛旀鑲负鏁扮粍锛岃杞崲JSON鏍煎紡 @@ -791,7 +793,7 @@ questionObj.stem.stemImage = getPublicImage(questionObj.stem.stemImage, 150) } if (questionObj.optionStyle == 'Image' || questionObj.optionStyle == 'TxtAndImage') { - questionObj.option.forEach((optionItem) => { + questionObj.option.forEach((optionItem:any) => { if (optionItem.img) optionItem.img = getPublicImage(optionItem.img, 150) }) } @@ -813,7 +815,7 @@ questionObj.questionType == 'judge' || questionObj.questionType == 'multipleChoice') ) { - questionObj.option.forEach((item) => { + questionObj.option.forEach((item:any) => { if (item.txt) item.txt = item.txt .replace(/\<img/gi, '<img class="option-rich-img"') @@ -894,12 +896,10 @@ } } } - + console.log('鏀惰棌json',jsonCollectList); for (let index = 0; index < jsonCollectList.length; index++) { const item = jsonCollectList[index] - if (item.type && item.type == 'material') { - examination.cardList.push(item) - } else if (item.questionType == 'singleChoice') { + if (item.questionType == 'singleChoice') { examination.cardList[0].infoList.push(item) } else if (item.questionType == 'judge') { examination.cardList[1].infoList.push(item) @@ -907,9 +907,11 @@ examination.cardList[2].infoList.push(item) } else if (item.questionType == 'completion') { examination.cardList[3].infoList.push(item) - } else if (item.questionType == 'shortAnswer') { + } else if (item.questionType == 'shortAnswer' || item.questionType == 'formula') { examination.cardList[4].infoList.push(item) - } + } else if (item.type && item.type == 'material') { + examination.cardList[examination.cardList.length] = item + } } examination.cardList = examination.cardList.filter((item) => item.infoList.length > 0) console.log('鎷兼帴棰�', examination.cardList) @@ -921,20 +923,21 @@ domain: 'errorData', keys: [props.activeBook.bookId] }) - .then(async (res) => { + .then(async (res:any) => { try { const error = JSON.parse(res[0].value) if (error.length) { console.log('鏈夊悧', error) - examination.errorList = error.find((citem) => citem.type == 'bits').errorList - examination.allError[0].errorList = error.find((citem) => citem.type == 'bits').errorList - examination.allError[1].errorList = error.find((citem) => citem.type == 'json').errorList + examination.errorList = error.find((citem:any) => citem.type == 'bits').errorList + examination.allError[0].errorList = error.find((citem:any) => citem.type == 'bits').errorList + examination.allError[1].errorList = error.find((citem:any) => citem.type == 'json').errorList } } catch (error) {} if (examination.allError[0].errorList || examination.allError[1].errorList) { examination.cardList = (await getErrorDataList()) as any await getJsonError() } else { + examination.noData = true examination.loading = false ElMessageBox.confirm('閿欓闆嗘殏鏃犳暟鎹�!', '鎻愮ず', { confirmButtonText: '纭畾', @@ -953,14 +956,8 @@ } // 鑾峰彇閿欓闆� const getErrorDataList = async () => { - if (!examination.errorList.length) { - examination.loading = false - examination.noData = true - return false - } - // 寮�濮嬭姹� let oldData = null - let oldList = [] + let oldList:any = [] let cardList = [ { catalogName: '鍗曢�夐', @@ -983,11 +980,11 @@ infoList: [] } ] - let singleChoiceArr = [] // 鍗曢�� - let judgeArr = [] // 鍒ゆ柇 - let shortArr = [] // 绠�绛� - let multipleChoiceArr = [] // 澶氶�� - let completionArr = [] // 濉┖ + let singleChoiceArr:any = [] // 鍗曢�� + let judgeArr:any = [] // 鍒ゆ柇 + let shortArr:any = [] // 绠�绛� + let multipleChoiceArr:any = [] // 澶氶�� + let completionArr:any = [] // 濉┖ // 11 for (let qindex = 0; qindex < examination.errorList.length; qindex++) { const qitem = examination.errorList[qindex] @@ -1013,10 +1010,10 @@ } const res = await MG.store.getProductDetail(query) if (!res.datas) return false - res.datas.cmsDatas[0].datas.forEach((item, index) => { + res.datas.cmsDatas[0].datas.forEach((item:any, index:number) => { let oldObj = {} if (oldList) { - oldObj = oldList.find((item) => item.id == qitem) + oldObj = oldList.find((item:any) => item.id == qitem) } const questionObj = { number: index + 1, // 棰樺彿 @@ -1081,7 +1078,7 @@ questionObj.stem.stemImage = getPublicImage(questionObj.stem.stemImage, 150) } if (questionObj.optionStyle == 'Image' || questionObj.optionStyle == 'TxtAndImage') { - questionObj.option.forEach((optionItem) => { + questionObj.option.forEach((optionItem:any) => { if (optionItem.img) optionItem.img = getPublicImage(optionItem.img, 150) }) } @@ -1103,7 +1100,7 @@ questionObj.questionType == 'judge' || questionObj.questionType == 'multipleChoice') ) { - questionObj.option.forEach((item) => { + questionObj.option.forEach((item:any) => { if (item.txt) item.txt = item.txt .replace(/\<img/gi, '<img class="option-rich-img"') @@ -1138,7 +1135,7 @@ } else if (item.Embedded_QuestionBank_QuestionType == 'completion') { questionObj.type = '濉┖棰�' completionArr.push(questionObj) - } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer') { + } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer' ) { questionObj.type = '绠�绛旈' shortArr.push(questionObj) } @@ -1162,7 +1159,6 @@ } // 閿欓闆嗘ā寮忎笅锛岃幏鍙栧亣鐨勯敊棰�(json) const getJsonError = async () => { - console.log('閿欓id', examination.allError[1].errorList) if (!props.activeBook.jsonQUestion) { examination.cardList = examination.cardList.filter((item) => item.infoList.length > 0) return false @@ -1188,9 +1184,7 @@ for (let index = 0; index < jsonCollectList.length; index++) { const item = jsonCollectList[index] - if (item.type && item.type == 'material') { - examination.cardList.push(item) - } else if (item.questionType == 'singleChoice') { + if (item.questionType == 'singleChoice') { examination.cardList[0].infoList.push(item) } else if (item.questionType == 'judge') { examination.cardList[1].infoList.push(item) @@ -1198,8 +1192,10 @@ examination.cardList[2].infoList.push(item) } else if (item.questionType == 'completion') { examination.cardList[3].infoList.push(item) - } else if (item.questionType == 'shortAnswer') { + } else if (item.questionType == 'shortAnswer' || item.questionType == 'formula') { examination.cardList[4].infoList.push(item) + } else if (item.type && item.type == 'material') { + examination.cardList[examination.cardList.length] = item } } examination.cardList = examination.cardList.filter((item) => item.infoList.length > 0) @@ -1226,7 +1222,7 @@ } else if (citem.questionType == 'singleChoice' || citem.questionType == 'judge') { if (citem.id == '63825') console.log('i', item) citem.isRight = citem.answer == citem.userAnswer - } else if (citem.questionType == 'shortAnswer') { + } else if (citem.questionType == 'shortAnswer' || item.questionType == 'formula') { // 绠�绛� 缈昏瘧 citem.isRight = null } else if (citem.questionType == 'completion') { @@ -1241,7 +1237,7 @@ } } } - if (!citem.isRight && citem.questionType != 'shortAnswer') { + if (!citem.isRight && citem.questionType != 'shortAnswer' && citem.questionType != 'formula') { // 瀹㈣棰樺洖绛旈敊璇� 璁板綍閿欓 if (citem.isJson) { @@ -1287,7 +1283,7 @@ } ] }) - .then((res) => { + .then((res:any) => { console.log('閿欓宸蹭繚瀛�', examination.allError) }) if (props.type == 'option') { @@ -1332,7 +1328,7 @@ setUserAnswer(arr) } // 鏈彁浜ら��鍑虹瓟棰橈紝淇濆瓨鐢ㄦ埛绛旀 -const setUserAnswer = (data) => { +const setUserAnswer = (data:any) => { MG.identity .setUserKey({ setKeyRequests: [ @@ -1343,7 +1339,7 @@ } ] }) - .then((res) => { + .then((res:any) => { console.log('鎻愪氦鐢ㄦ埛绛旈鏁版嵁鎴愬姛') }) } @@ -1355,21 +1351,21 @@ domain: 'beforeAnswerData', keys: [props.info.id] }) - .then((res) => { - if(res) { + .then((res:any) => { + if(res.length) { data = JSON.parse(res[0].value) } }) return data } // 鑾峰彇鐢ㄦ埛鏃х瓟棰樻暟鎹�(鎻愪氦鍚�) -const getAnswerInfo = (callback) => { +const getAnswerInfo = (callback:any) => { MG.identity .getUserKey({ domain: 'answerData', keys: [props.info.id] }) - .then((res) => { + .then((res:any) => { if (callback) callback(res) }) } @@ -1385,18 +1381,18 @@ } ] }) - .then((res) => { + .then((res:any) => { console.log('鎻愪氦鐢ㄦ埛绛旈鏁版嵁鎴愬姛') }) } // 鍒犻櫎鐢ㄦ埛绛旈鏁版嵁 -const deleteAnswerInfo = (callback) => { +const deleteAnswerInfo = (callback:any) => { MG.identity .delUserKey({ domain: 'answerData', keys: [props.info.id] }) - .then((res) => { + .then((res:any) => { if (callback) callback() }) } @@ -1411,7 +1407,7 @@ } ] }) - .then((res) => { + .then((res:any) => { console.log('鏀惰棌/鍙栨秷鎴愬姛') }) } @@ -1426,10 +1422,13 @@ } ] }) - .then((res) => { - console.log('閿欓宸蹭繚瀛�', examination.allError) + .then((res:any) => { + console.log('閿欓宸叉竻绌�') }) } +const onChangeInput = (value:any,index:number,cindex:number,dindex:number) => { + examination.cardList[index].infoList[cindex].userAnswer[dindex] = value +} defineExpose({ handleExaminationDialog }) </script> -- Gitblit v1.9.1