add comment

ui
yujialong 3 years ago
parent 652082414c
commit b810de42ba
  1. 72
      src/components/codemirror.vue
  2. 2
      src/utils/api.js

@ -150,12 +150,10 @@ export default {
theme: "monokai", // theme: "monokai", //
extraKeys: { Ctrl: "autocomplete" } // keyMap extraKeys: { Ctrl: "autocomplete" } // keyMap
}, },
inputTextReg: /^((?!#).*?(,|\(|\[|\{|\s)+)?input(?!\w)\(['|"]([\s\S]+?)['|"]\)/mg, inputTextReg: /^((?!#).*?(,|\(|\[|\{|\s)+)?input(?!\w)\(['|"]([\s\S]+?)['|"]\)/m,// input()
inputReg: /^((?!#).*?(,|\(|\[|\{|\s)+)?(input(?!\w)\(['|"][\s\S]*?['|"]\))/m,
exitTextReg: /exit(?!\w)\(['|"]([\s\S]+?)['|"]\)/m,
exitNotValidReg: /exit(?!\w)\(['|"]([\s\S]+?)['|"]\)/m,
requestList: [], requestList: [],
sourceCode: '' sourceCode: '',
requestTimer: null
}; };
}, },
components: { components: {
@ -220,11 +218,9 @@ export default {
this.$post(this.api.AddCode, { this.$post(this.api.AddCode, {
code: this.exampleData, code: this.exampleData,
projectId: this.projectId, projectId: this.projectId,
// projectId: 305,
judgmentPointsId: this.workbench1, judgmentPointsId: this.workbench1,
userId: parseInt(this.userId), userId: parseInt(this.userId),
studentId: this.studentId, studentId: this.studentId,
// studentId: 54,
submit: this.submit submit: this.submit
}) })
.then(res => { .then(res => {
@ -253,28 +249,41 @@ export default {
} }
x.send() x.send()
}, },
// pythoninputinputexitexit
// exitinputpythonexitexitinput
//
// input
confirmInput(msg){ confirmInput(msg){
let receiveResult = msg.replace('validing:','') let receiveResult = msg.replace('validing:','')
// console.log('',receiveResult)
this.modifys += receiveResult this.modifys += receiveResult
this.$prompt(receiveResult, "提示", { this.$prompt(receiveResult, "提示", {
confirmButtonText: "确定" confirmButtonText: "确定"
}).then(({ value }) => { }).then(({ value }) => {
this.modifys += `${value}<br>` this.modifys += `${value}<br>`
console.log('替换前:',this.sourceCode,`exit('validing:${receiveResult.replace(/[\r\n]*/g,'')}')`) // 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,'')}')`,val => {
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,'')}")`,val => {
return `'${value}'` return `'${value}'`
}) })
console.log('替换后:',this.sourceCode) clearTimeout(this.requestTimer)
this.$post(this.api.UpdateCode,{ // AnswerTips
this.requestTimer = setTimeout(() => {
this.requestList.map(n => n('interrupt'))
},1000)
axios.post(this.api.UpdateCode,{
code: this.sourceCode, code: this.sourceCode,
codeId: this.codeId, codeId: this.codeId,
submit: this.submit submit: this.submit
}).then(res => { },{
cancelToken: new CANCEL_TOKEN(c => { //
this.requestList.push(c)
})
}).then(response => {
let res = response.data
let result = res.message.result let result = res.message.result
if(result.includes('File ')){ if(result.includes('File ')){
let modify = res.message.result let modify = res.message.result
@ -296,18 +305,16 @@ export default {
isError: res.data.isError isError: res.data.isError
}) })
} }
}).catch(err => {}) }).catch(e => {
if(e && e.message == 'interrupt'){
this.AnswerTips(true)
this.requestList = []
}
})
}).catch(err => {}) }).catch(err => {})
}, },
AnswerTips() { AnswerTips(isWhile) {// isWhiletruewhile
// let inputTextReg = this.inputTextReg
// let str = `server = int(input('1 2 3 \n')`
// str = str.replace(inputTextReg,val => {
// console.log(val.replace(/\n/g,''))
// return val.replace(/\n/g,'')
// })
// console.log(str)
// return
if (this.isSubmit == "") { if (this.isSubmit == "") {
this.submit = 1; this.submit = 1;
if (this.codeid == "") { if (this.codeid == "") {
@ -318,19 +325,21 @@ export default {
} else { } else {
let inputTextReg = this.inputTextReg let inputTextReg = this.inputTextReg
let inputFuncReg = /input\(['|"]/g let inputFuncReg = /input\(['|"]/g
// input
if (inputTextReg.test(this.exampleData)) { if (inputTextReg.test(this.exampleData)) {
let sourceCode = this.exampleData let sourceCode = this.exampleData
// sourceCode = sourceCode.replace(inputTextReg,val => { sourceCode = sourceCode.replace(inputTextReg,val => {
// return console.log(val.replace(/\n'/g,"'")) return val.replace(/\\n/g,"")
// }) })
// return console.log(11,sourceCode) this.exampleData = sourceCode
// inputexit"validing:"便
sourceCode = sourceCode.replace(inputFuncReg,val => { sourceCode = sourceCode.replace(inputFuncReg,val => {
return `exit(${val[val.length - 1]}validing:` return `exit(${val[val.length - 1]}validing:`
}) })
this.sourceCode = sourceCode this.sourceCode = sourceCode
this.modifys = '' if(!isWhile) this.modifys = ''
this.$post(this.api.UpdateCode, { this.$post(this.api.UpdateCode, {
code: sourceCode, code: sourceCode,
codeId: this.codeId, codeId: this.codeId,
@ -339,7 +348,12 @@ export default {
let result = res.message.result let result = res.message.result
if(result.includes('File ')){ if(result.includes('File ')){
let modify = res.message.result let modify = res.message.result
this.modifys = modify if(isWhile){
this.modifys += modify
}else{
this.modifys = modify
}
this.after = modify.substring( this.after = modify.substring(
modify.indexOf("line") + 4, modify.indexOf("line") + 4,
modify.length modify.length
@ -373,6 +387,8 @@ export default {
isError: res.data.isError isError: res.data.isError
}) })
}else{ }else{
//
// 7
if(!res.message.isError){ if(!res.message.isError){
let result = '' let result = ''
try { try {

@ -1,6 +1,6 @@
import config from '@/config' import config from '@/config'
// let host = 'http://192.168.31.125:8081/python'//林 // let host = 'http://192.168.31.125:8081/python'//林
// let host = 'http://192.168.31.151:8081/python'//榕 // let host = 'http://192.168.31.216:8081/python'//榕
let host = `${config.host}python` let host = `${config.host}python`
export default { export default {

Loading…
Cancel
Save