|
|
|
@ -11,7 +11,7 @@ |
|
|
|
|
<div v-if="isSubmit" class="code-mask"></div> |
|
|
|
|
<el-button |
|
|
|
|
type="warning" |
|
|
|
|
@click="runCode" |
|
|
|
|
@click="runCode(false)" |
|
|
|
|
:disabled="runEnable" |
|
|
|
|
style="width:100px;position:absolute;z-index:99;background:#FDCA17;color:black;right: 50px;bottom:15px;" |
|
|
|
|
>运行</el-button> |
|
|
|
@ -88,12 +88,14 @@ import "codemirror/theme/base16-light.css"; |
|
|
|
|
import { Loading } from 'element-ui'; |
|
|
|
|
import axios from 'axios'; |
|
|
|
|
import util from '@/util' |
|
|
|
|
import config from '@/config' |
|
|
|
|
const CANCEL_TOKEN = axios.CancelToken // 用于input中中断请求 |
|
|
|
|
export default { |
|
|
|
|
props: ['workbench1', 'code', 'codeId', 'projectId'], |
|
|
|
|
data() { |
|
|
|
|
return { |
|
|
|
|
assessmentId: util.getCookie(';assessmentId'), // 考核id |
|
|
|
|
token: util.getCookie('admin-token'), |
|
|
|
|
assessmentId: util.getCookie('assessmentId'), // 考核id |
|
|
|
|
courseId: util.getCookie('courseId'), // 课程id |
|
|
|
|
showTips: false, // 显示隐藏提示按钮 |
|
|
|
|
answer: '', // 正确答案 |
|
|
|
@ -168,17 +170,17 @@ export default { |
|
|
|
|
* 下面这个函数就是递归执行这个input输入过程的函数 |
|
|
|
|
*/ |
|
|
|
|
confirmInput(msg){ |
|
|
|
|
let receiveResult = msg.replace('validing:','') |
|
|
|
|
const receiveResult = msg.replace('validing:', '') |
|
|
|
|
this.runResult += receiveResult |
|
|
|
|
this.$prompt(receiveResult, "提示", { |
|
|
|
|
this.$prompt(receiveResult, '提示', { |
|
|
|
|
confirmButtonText: "确定" |
|
|
|
|
}).then(({ value }) => { |
|
|
|
|
this.runResult += `${value}<br>` |
|
|
|
|
// 把exit函数替换成用户输入的值 |
|
|
|
|
this.sourceCode = this.sourceCode.replace(`exit('validing:${receiveResult.replace(/[\r\n]*/g,'')}')`,val => { |
|
|
|
|
this.sourceCode = this.sourceCode.replace(`exit('validing:${receiveResult.replace(/[\r\n]*/g,'')}')`, _ => { |
|
|
|
|
return `'${value}'` |
|
|
|
|
}) |
|
|
|
|
this.sourceCode = this.sourceCode.replace(`exit("validing:${receiveResult.replace(/[\r\n]*/g,'')}")`,val => { |
|
|
|
|
this.sourceCode = this.sourceCode.replace(`exit("validing:${receiveResult.replace(/[\r\n]*/g,'')}")`, _ => { |
|
|
|
|
return `'${value}'` |
|
|
|
|
}) |
|
|
|
|
clearTimeout(this.requestTimer) |
|
|
|
@ -188,28 +190,31 @@ export default { |
|
|
|
|
this.requestList.map(n => n('interrupt')) |
|
|
|
|
}, 1000) |
|
|
|
|
|
|
|
|
|
axios.post(this.api.runPythonCode,{ |
|
|
|
|
code: this.codeVal, |
|
|
|
|
axios.post(config.host + this.api.runPythonCode, { |
|
|
|
|
code: this.sourceCode, |
|
|
|
|
bcId: this.workbench1, |
|
|
|
|
cid: this.courseId, |
|
|
|
|
projectId: this.projectId |
|
|
|
|
}, { |
|
|
|
|
headers: { |
|
|
|
|
token: this.token |
|
|
|
|
}, |
|
|
|
|
cancelToken: new CANCEL_TOKEN(c => { //强行中断请求要用到的,记录请求信息 |
|
|
|
|
this.requestList.push(c) |
|
|
|
|
}) |
|
|
|
|
}).then(response => { |
|
|
|
|
let res = response.data |
|
|
|
|
let result = res.message.result |
|
|
|
|
const data = res.code |
|
|
|
|
const result = data.runResult |
|
|
|
|
if (result.includes('File ')) { |
|
|
|
|
let modify = res.message.result |
|
|
|
|
this.runResult = modify |
|
|
|
|
this.errLine = parseInt(modify.substring(modify.indexOf("line") + 4, modify.length)) |
|
|
|
|
this.isError = res.message.isError |
|
|
|
|
this.runResult = result |
|
|
|
|
this.errLine = parseInt(result.substring(result.indexOf('line') + 4, result.length)) |
|
|
|
|
this.isError = data.retResult |
|
|
|
|
} else if (result.includes('validing:')) { |
|
|
|
|
this.isError = 0 |
|
|
|
|
this.isError = 1 |
|
|
|
|
this.confirmInput(result) |
|
|
|
|
}else if(!res.message.isError){ |
|
|
|
|
this.isError = 0 |
|
|
|
|
} else if(data.retResult) { |
|
|
|
|
this.isError = 1 |
|
|
|
|
this.runResult += result |
|
|
|
|
} |
|
|
|
|
}).catch(e => { |
|
|
|
@ -231,41 +236,43 @@ export default { |
|
|
|
|
type: "warning" |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
let inputTextReg = this.inputTextReg |
|
|
|
|
let inputFuncReg = /input\(['|"]/g |
|
|
|
|
const inputTextReg = this.inputTextReg |
|
|
|
|
const inputFuncReg = /input\(['|"]/g |
|
|
|
|
const bcId = this.workbench1 |
|
|
|
|
const cid = this.courseId |
|
|
|
|
const projectId = this.projectId |
|
|
|
|
// 该正则是验证代码里是否有input,如果有,就要另外做处理,而不是直接传给后端执行 |
|
|
|
|
if (inputTextReg.test(code)) { |
|
|
|
|
let sourceCode = this.codeVal |
|
|
|
|
sourceCode = sourceCode.replace(inputTextReg,val => { |
|
|
|
|
code = code.replace(inputTextReg, val => { |
|
|
|
|
return val.replace(/\\n/g,"") |
|
|
|
|
}) |
|
|
|
|
this.codeVal = sourceCode |
|
|
|
|
this.codeVal = code |
|
|
|
|
|
|
|
|
|
// 把input函数替换成exit函数,加上"validing:"作为特定标识,好方便后面的识别 |
|
|
|
|
sourceCode = sourceCode.replace(inputFuncReg,val => { |
|
|
|
|
code = code.replace(inputFuncReg,val => { |
|
|
|
|
return `exit(${val[val.length - 1]}validing:` |
|
|
|
|
}) |
|
|
|
|
this.sourceCode = sourceCode |
|
|
|
|
this.sourceCode = code |
|
|
|
|
|
|
|
|
|
if(!isWhile) this.runResult = '' |
|
|
|
|
this.$post(this.api.runPythonCode, { |
|
|
|
|
code: this.codeVal, |
|
|
|
|
bcId: this.workbench1, |
|
|
|
|
cid: this.courseId, |
|
|
|
|
projectId: this.projectId |
|
|
|
|
code, |
|
|
|
|
bcId, |
|
|
|
|
cid, |
|
|
|
|
projectId |
|
|
|
|
}).then(res => { |
|
|
|
|
let result = res.message.result |
|
|
|
|
const data = res.code |
|
|
|
|
const result = data.runResult |
|
|
|
|
if(result.includes('File ')){ |
|
|
|
|
let modify = res.message.result |
|
|
|
|
if (isWhile) { |
|
|
|
|
this.runResult += modify |
|
|
|
|
this.runResult += result |
|
|
|
|
} else { |
|
|
|
|
this.runResult = modify |
|
|
|
|
this.runResult = result |
|
|
|
|
} |
|
|
|
|
this.errLine = parseInt(modify.substring(modify.indexOf("line") + 4, modify.length)) |
|
|
|
|
this.isError = res.message.isError |
|
|
|
|
this.errLine = parseInt(result.substring(result.indexOf('line') + 4, result.length)) |
|
|
|
|
this.isError = data.retResult |
|
|
|
|
}else if(result.includes('validing:')){ |
|
|
|
|
this.isError = 0 |
|
|
|
|
this.isError = 1 |
|
|
|
|
this.confirmInput(result) |
|
|
|
|
} |
|
|
|
|
}).catch(err => {}) |
|
|
|
@ -280,9 +287,9 @@ export default { |
|
|
|
|
// 把代码传给后端,在后端运行Python代码 |
|
|
|
|
this.$post(this.api.runPythonCode, { |
|
|
|
|
code, |
|
|
|
|
bcId: this.workbench1, |
|
|
|
|
cid: this.courseId, |
|
|
|
|
projectId: this.projectId |
|
|
|
|
bcId, |
|
|
|
|
cid, |
|
|
|
|
projectId |
|
|
|
|
}).then(res => { |
|
|
|
|
const data = res.code |
|
|
|
|
const photo = data.photoUrl |
|
|
|
|