input修复

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

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

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

@ -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
// inputexit"validing:"便 // inputexit"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

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

Loading…
Cancel
Save