input修复

ui
jialong.yu 3 years ago
parent 26628a094c
commit b367a5cb93
  1. 2
      src/api/index.js
  2. 2
      src/components/TestPanel.vue
  3. 93
      src/components/codemirror.vue
  4. 2
      src/config/index.js

@ -1,5 +1,5 @@
export default {
QueryProject: 'occupationlab/projectManage/getProjectDetail',
getProjectDetail: 'occupationlab/projectManage/getProjectDetail',
submit: 'python/python/submit',
runPythonCode: 'python/python/runPythonCode',
queryBcJudgmentByBcId: 'judgment/bcJudgmentPoint/queryBcJudgmentByBcId',

@ -219,7 +219,7 @@ export default {
getProDetail() {
const projectId = this.projectId
return new Promise((resolve, reject) => {
this.$get(this.api.QueryProject, {
this.$get(this.api.getProjectDetail, {
projectId
}).then(res => {
const points = res.projectJudgmentVos

@ -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)
@ -186,30 +188,33 @@ export default {
// AnswerTips
this.requestTimer = setTimeout(() => {
this.requestList.map(n => n('interrupt'))
},1000)
}, 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
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
}else if(result.includes('validing:')){
this.isError = 0
const data = res.code
const result = data.runResult
if (result.includes('File ')) {
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 = 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
// inputexit"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
}else{
this.runResult = modify
if (isWhile) {
this.runResult += result
} else {
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

@ -3,7 +3,7 @@ const isBeta = process.env.NODE_ENV === 'development' || location.host.includes(
let host = ''
if(isBeta) {
host = 'http://39.108.250.202:9000'
host = 'http://39.108.250.202:9000/'
// host = 'http://192.168.31.151:9000'
} else {
host = location.origin + '/'

Loading…
Cancel
Save