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