|
|
|
@ -235,7 +235,8 @@ export default { |
|
|
|
|
}, |
|
|
|
|
runCode(isWhile) { // isWhile为true表示代码里有while循环,右边的运行结果需要拼接展示,而不是直接覆盖 |
|
|
|
|
if (!this.isSubmit) { |
|
|
|
|
if (!this.codeVal) { |
|
|
|
|
let code = this.codeVal |
|
|
|
|
if (!code) { |
|
|
|
|
this.$message({ |
|
|
|
|
message: "警告哦,内容为空不可运行", |
|
|
|
|
type: "warning" |
|
|
|
@ -244,7 +245,7 @@ export default { |
|
|
|
|
let inputTextReg = this.inputTextReg |
|
|
|
|
let inputFuncReg = /input\(['|"]/g |
|
|
|
|
// 该正则是验证代码里是否有input,如果有,就要另外做处理,而不是直接传给后端执行 |
|
|
|
|
if (inputTextReg.test(this.codeVal)) { |
|
|
|
|
if (inputTextReg.test(code)) { |
|
|
|
|
let sourceCode = this.codeVal |
|
|
|
|
sourceCode = sourceCode.replace(inputTextReg,val => { |
|
|
|
|
return val.replace(/\\n/g,"") |
|
|
|
@ -272,7 +273,6 @@ export default { |
|
|
|
|
}else{ |
|
|
|
|
this.runResult = modify |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.errLine = parseInt(modify.substring(modify.indexOf("line") + 4, modify.length)) |
|
|
|
|
this.isError = res.message.isError |
|
|
|
|
}else if(result.includes('validing:')){ |
|
|
|
@ -284,9 +284,13 @@ export default { |
|
|
|
|
this.loadIns = Loading.service({ |
|
|
|
|
background: 'transparent' |
|
|
|
|
}) |
|
|
|
|
// 如果代码有savefig(python里的保存图片的方法),则要把savefig里的图片名字加上个时间戳,防止后台保存图片到服务器的时候图片名字重复导致覆盖 |
|
|
|
|
code = code.replace(/\.savefig\(([\u4e00-\u9fa5\w]*?['"])/mg, str => { |
|
|
|
|
return str + Date.now() |
|
|
|
|
}) |
|
|
|
|
// 把代码传给后端,在后端运行Python代码 |
|
|
|
|
this.$post(this.api.runPythonCode, { |
|
|
|
|
code: this.codeVal, |
|
|
|
|
code, |
|
|
|
|
bcId: this.workbench1, |
|
|
|
|
cid: this.courseId, |
|
|
|
|
projectId: this.projectId |
|
|
|
@ -296,10 +300,12 @@ export default { |
|
|
|
|
const result = data.runResult |
|
|
|
|
this.loadIns.close() |
|
|
|
|
this.picSrc = '' |
|
|
|
|
this.$emit('update:codeId', res.codeId) |
|
|
|
|
if(photo){ |
|
|
|
|
this.isError = data.retResult |
|
|
|
|
this.runResult = '' |
|
|
|
|
this.picSrc = `${photo}?id=${new Date().getTime()}` |
|
|
|
|
const text = result.replace(photo, '') |
|
|
|
|
this.runResult = text |
|
|
|
|
this.picSrc = photo |
|
|
|
|
}else{ |
|
|
|
|
// 这段是为要下载图片的项目案例写的,后端会返回图片名称的数组,前端负责循环这个数组,然后下载下来 |
|
|
|
|
// 只有该系统有这段代码,因为其他7个系统没有下载图片的项目,后续如果加了,直接把这段代码复制过去即可 |
|
|
|
@ -319,7 +325,6 @@ export default { |
|
|
|
|
this.isError = data.retResult |
|
|
|
|
this.runResult = result |
|
|
|
|
this.errLine = parseInt(result.substring(result.indexOf("line") + 4, result.length)) |
|
|
|
|
this.$emit('update:codeId', res.codeId) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}).catch(res => { |
|
|
|
|