add comment

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

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

@ -1,6 +1,6 @@
import config from '@/config'
// 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`
export default {

Loading…
Cancel
Save