From aa01c8e99a611d2445341def8a2168fc6caba0f5 Mon Sep 17 00:00:00 2001 From: "jialong.yu" Date: Mon, 20 Dec 2021 20:37:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E8=81=94=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/TestPanel.vue | 75 ++++++++++++++++++++--------------- src/components/codemirror.vue | 75 +++++++++++++++-------------------- src/config/index.js | 2 +- src/util/index.js | 18 +++++++++ src/views/Home.vue | 4 +- 5 files changed, 94 insertions(+), 80 deletions(-) diff --git a/src/components/TestPanel.vue b/src/components/TestPanel.vue index 1ee741b..4503f5a 100644 --- a/src/components/TestPanel.vue +++ b/src/components/TestPanel.vue @@ -73,21 +73,25 @@ - + + + + - @@ -302,14 +306,15 @@ export default { localStorage.removeItem('codeCache') this.isSubmit = false newmain.$emit('isSubmit', this.isSubmit) + const points = this.points + points.map(e => { + e.code = '' + e.codeId = '' + e.answer = '' + }) + this.$emit('tell', this.projectId, points) this.$emit('recoveryCode') this.startCount() - // let taskList = this.taskList - // taskList.map(n => { - // delete n.score - // delete n.right - // }) - // this.taskList = JSON.parse(JSON.stringify(taskList)) }, // 提交 submit() { @@ -358,23 +363,20 @@ export default { localStorage.removeItem('codeCache') this.isSubmit = true newmain.$emit('isSubmit', this.isSubmit) - let list = res.message - let result = [] + let list = res.retInfo let taskList = this.taskList - result.map(n => { - if(taskList.find(e => e.judgmentPointsId == n.judgmentPointsId).isError){ - n.score = 0 - n.right = -1 + var score = 0 + taskList.map(e => { + let item = list.find(n => n.judgmentPointsId === e.judgmentId) + if (item) { + e.score = item.score + e.finishedResult = item.finishedResult + } else { + e.score = 0 } + score += e.score }) - this.taskList = result - //计算总分 - var s = 0; - this.taskList.forEach(element => { - // this.test = element.score; - // s += this.test; - this.grade = s; - }); + this.grade = util.handleZero(score) }) .catch(err => {}) }).catch(() => {}) @@ -441,7 +443,6 @@ export default { cursor: pointer; display: block !important; } -//el-main .el-main { width: 60%; background-color: #fff; @@ -689,4 +690,12 @@ export default { border-radius: 0; background: #dddddd; } +.right { + color: #00af00; + font-size: 20px; +} +.wrong { + color: #f00; + font-size: 20px; +} \ No newline at end of file diff --git a/src/components/codemirror.vue b/src/components/codemirror.vue index 2ac3019..2470a67 100644 --- a/src/components/codemirror.vue +++ b/src/components/codemirror.vue @@ -161,24 +161,12 @@ export default { ready() { this.$refs.myCmGenerate.codemirror.setSize("auto", "calc(100vh - 149px)"); }, - // 下载文件 - downloadFile(fileName,url) { - var x = new XMLHttpRequest() - x.open("GET", url, true) - x.responseType = 'blob' - x.onload=function(e) { - var url = window.URL.createObjectURL(x.response) - var a = document.createElement('a') - a.href = url - a.download = fileName - a.click() - } - x.send() - }, - // python代码里如果有input函数的话,是做了单独的处理的,原理是先把所有input函数都替换成exit函数,再在exit函数里加上特定标识,再通过接口传给后端去执行 - // 因为exit函数是跟input有类似的效果,就是都会产生阻塞,所以python引擎一旦遇到exit,进程就会被停止,然后返回exit函数里面的值,而这个值,就是上面说的特定标识加上原本这个input函数里的值 - // 然后就可以通过这个返回的值来提示给用户,让用户继续输入 - // 下面这个函数就是递归执行这个input输入过程的函数 + /** + * python代码里如果有input函数的话,是做了单独的处理的,原理是先把所有input函数都替换成exit函数,再在exit函数里加上特定标识,再通过接口传给后端去执行 + * 因为exit函数是跟input有类似的效果,就是都会产生阻塞,所以python引擎一旦遇到exit,进程就会被停止,然后返回exit函数里面的值,而这个值,就是上面说的特定标识加上原本这个input函数里的值 + * 然后就可以通过这个返回的值来提示给用户,让用户继续输入 + * 下面这个函数就是递归执行这个input输入过程的函数 + */ confirmInput(msg){ let receiveResult = msg.replace('validing:','') this.runResult += receiveResult @@ -299,36 +287,35 @@ export default { const data = res.code const photo = data.photoUrl const result = data.runResult - this.$emit('cache') + this.$emit('cache') // 每次运行代码都要把代码传给后端做缓存 this.loadIns.close() this.picSrc = '' - this.$emit('update:codeId', res.codeId) - this.$emit('update:answer', result) - if(photo){ - this.isError = '' - const text = result.replace(photo, '') + this.$emit('update:codeId', res.codeId) // 更新coddeId + this.$emit('update:answer', result) // 更新运行结果 + let imgList = '' + try { + imgList = eval(result) + } catch (error) {} + // 如果是下载图片的代码,则要显示图片和运行结果,不用显示对错,换成显示下载图片 + if (photo) { + this.isError = '' // 对错隐藏 + const text = result.replace(photo, '') // 结果里包含了图片路径,所以要把图片路径给去掉 this.runResult = text this.picSrc = photo - }else{ - // 这段是为要下载图片的项目案例写的,后端会返回图片名称的数组,前端负责循环这个数组,然后下载下来 - // 只有该系统有这段代码,因为其他7个系统没有下载图片的项目,后续如果加了,直接把这段代码复制过去即可 - if(0){ - if(result instanceof Array && result.length && (result[0].includes('.jpg') || result[0].includes('.png') || result[0].includes('.gif'))){ - result.map((n,i) => { - this.downloadFile(`${i+1}.jpg`,n) - }) - this.isError = 0 - this.runResult = '下载完成' - }else{ - this.isError = 0 - this.runResult = data.runResult - this.errLine = parseInt(result.substring(modify.indexOf("line") + 4, modify.length)) - } - } else { - this.isError = data.retResult - this.runResult = result - this.errLine = parseInt(result.substring(result.indexOf("line") + 4, result.length)) - } + } else if (imgList instanceof Array && imgList.length && (imgList[0].includes('.jpg') || imgList[0].includes('.png') || imgList[0].includes('img'))) { + /** + * 这段是为要下载图片的项目案例写的,后端会返回图片名称的数组,前端负责循环这个数组,然后下载下来 + * 只有该系统有这段代码,因为其他7个系统没有下载图片的项目,后续如果加了,直接把这段代码复制过去即可 + */ + imgList.map((n,i) => { + util.downloadFile(`${i+1}.jpg`,n) + }) + this.isError = 0 + this.runResult = '下载完成' + } else { + this.isError = data.retResult + this.runResult = result + this.errLine = parseInt(result.substring(result.indexOf("line") + 4, result.length)) } }).catch(res => { res.status == 500 && this.$message.error('检测到代码里有非法代码,请检查是否有调用系统命令。') diff --git a/src/config/index.js b/src/config/index.js index becd3f1..75e589d 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -7,7 +7,7 @@ if(isHh) { host = "http://10.196.131.73/"; } else if(isBeta) { host = "http://39.108.250.202:9000/"; - host = "http://192.168.31.151:9000/"; + // host = "http://192.168.31.151:9000/"; } else if(isPro) { host = "http://www.occupationlab.com/"; } else { diff --git a/src/util/index.js b/src/util/index.js index 6fce263..7eae976 100644 --- a/src/util/index.js +++ b/src/util/index.js @@ -38,5 +38,23 @@ export default { } } return fmt + }, + // 下载文件 + downloadFile(fileName,url) { + var x = new XMLHttpRequest() + x.open("GET", url, true) + x.responseType = 'blob' + x.onload=function(e) { + var url = window.URL.createObjectURL(x.response) + var a = document.createElement('a') + a.href = url + a.download = fileName + a.click() + } + x.send() + }, + // 小于0前面加上0 + handleZero (num) { + return num < 10 ? '0' + num : num } } \ No newline at end of file diff --git a/src/views/Home.vue b/src/views/Home.vue index 3d80be5..9e81df9 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -74,7 +74,7 @@ export default { } }, methods: { - // 页面离开的时候保存未提交的代码(只有练习和未提交状态下才会调用该接口) + // 页面离开的时候缓存未提交的代码(只有未提交状态下才会调用该接口) leavePage(){ const list = this.workbench if(!this.$refs.mainindex.isSubmit && list.length && list.some(e => e.code)){ @@ -82,7 +82,7 @@ export default { projectId: this.projectId, judgmentId: list[Number(this.curTab)].judgmentId } - localStorage.setItem('codeCache', JSON.stringify(cache)) + localStorage.setItem('codeCache', JSON.stringify(cache)) // 在本地缓存里保存项目id和判分点id,下次进来通过这两个id去查找缓存代码。之所以不在前端缓存代码是预防更换了浏览器或电脑后依然可以找回缓存代码,只不过更换了客户端后本地缓存就消失了,这种情况就做一个向下处理,就切换项目的时候去恢复代码 list.map(e => { if (e.code) { let data = {