实验缓存

ui
jialong.yu 3 years ago
parent cba2750588
commit 352be7ca95
  1. 250
      src/components/TestPanel.vue
  2. 233
      src/components/codemirror.vue
  3. 19
      src/utils/api.js
  4. 78
      src/views/Home.vue

@ -6,7 +6,7 @@
<div class="flex" style="width: 28%"> <div class="flex" style="width: 28%">
<p>实训项目</p> <p>实训项目</p>
<el-select <el-select
v-model="value1" v-model="projectId"
placeholder="请选择" placeholder="请选择"
class="select" class="select"
:disabled="projectPermissions != 0" :disabled="projectPermissions != 0"
@ -14,7 +14,7 @@
style="flex: 1" style="flex: 1"
> >
<el-option <el-option
v-for="item in value" v-for="item in projectList"
:key="item.projectId" :key="item.projectId"
:label="item.projectName" :label="item.projectName"
:value="item.projectId" :value="item.projectId"
@ -44,7 +44,7 @@
v-show="projectPermissions == 0" v-show="projectPermissions == 0"
@click="reload" @click="reload"
>重新开始</el-button> >重新开始</el-button>
<el-button style="margin-right:7px" @click="Submit()" :disabled="isSubmit">提交</el-button> <el-button style="margin-right:7px" @click="Submit" :disabled="isSubmit">提交</el-button>
</div> </div>
</div> </div>
</el-header> </el-header>
@ -96,7 +96,7 @@
</div> </div>
</el-aside> </el-aside>
<el-main> <el-main>
<el-tabs v-model="activeName" type="card"> <el-tabs v-model="pannelTab" type="card">
<el-tab-pane label="案例" name="first"> <el-tab-pane label="案例" name="first">
<div class="break-all" v-html="experimentDescription"></div> <div class="break-all" v-html="experimentDescription"></div>
</el-tab-pane> </el-tab-pane>
@ -105,13 +105,13 @@
<el-collapse-item v-for="(loop, index) in points" :key="index"> <el-collapse-item v-for="(loop, index) in points" :key="index">
<template slot="title"> <template slot="title">
<i class="el-icon-s-ticket"></i> <i class="el-icon-s-ticket"></i>
<span style="font-size:16px">{{loop.experimentalRequirements}}</span>
</template>
<div class="break-all" v-html="loop.experimentalRequirements"></div> <div class="break-all" v-html="loop.experimentalRequirements"></div>
</template>
<div class="break-all" v-html="loop.expserimentalRequirements"></div>
</el-collapse-item> </el-collapse-item>
</el-collapse> </el-collapse>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="实验提示" name="fifth" v-if="isstartexperimentSuggests"> <el-tab-pane label="实验提示" name="fifth" v-if="hintOpen">
<div class="break-all" v-html="experimentHint"></div> <div class="break-all" v-html="experimentHint"></div>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
@ -139,15 +139,23 @@ import util from '@/util'
export default { export default {
data() { data() {
return { return {
userId: util.getCookie("userId"),
studentId: util.getCookie("studentId"),
courseId: util.getCookie("courseId"),
projectId: util.getCookie("projectId"),
assessmentId: util.getCookie("assessmentId"),
projectPermissions: 0, // (0 1 2)
isSubmit: false,
entryTime: util.formatDate('yyyy-MM-dd hh:mm:ss'),
startTime: util.getCookie("startTime") ? new Date(util.getCookie("startTime")).getTime() : '',
stopTime: util.getCookie("stopTime") ? new Date(util.getCookie("stopTime")).getTime() : '',
test: [], test: [],
ishow: true, ishow: true,
grade: "00", grade: "00",
exampleData: "", exampleData: "",
codeid: "", codeid: "",
codeIds: [],
judgmentPointsIds: [],
text: "", text: "",
isStart: false, isStart: false, //
globalTimer: null, //setInterval globalTimer: null, //setInterval
millisecond: 0, millisecond: 0,
countVal: this.defaultVal, // countVal: this.defaultVal, //
@ -156,10 +164,9 @@ export default {
seconds: 0, seconds: 0,
minutes: 0, minutes: 0,
hour: 0, hour: 0,
createTime: "", // createTime: '', //
actEndTime: "", // actEndTime: '', //
value1: "", // projectList: [],
value: [],
experimentTarget: "", // experimentTarget: "", //
experimentDescription: "", // experimentDescription: "", //
experimentHint: "", // experimentHint: "", //
@ -167,21 +174,9 @@ export default {
points: [], points: [],
activeNames: [], activeNames: [],
tableData: [], tableData: [],
activeName: "first", pannelTab: "first",
studentId: "", isSelected: false, // true
courseId: "", hintOpen: 1 //
projectId: "",
assessmentId: "",
projectPermissions: 0, //(0 1 2)
isSubmit: false,
entryTime: util.formatDate('yyyy-MM-dd hh:mm:ss'),
startTime: '',
stopTime: '',
isSelected: false,
userId: '',
workbenchCus: this.workbench,
isRecovery: false,
isstartexperimentSuggests: 1
}; };
}, },
watch: { watch: {
@ -240,51 +235,23 @@ export default {
} }
}, },
mounted() { mounted() {
this.assessmentId = util.getCookie("assessmentId"); this.projectPermissions = this.projectId ? 1 : 0 // /
this.userId = util.getCookie("userId"); if(this.projectId){ // projectId)
this.studentId = util.getCookie("studentId"); this.getProDetail()
this.projectId = util.getCookie("projectId"); }else{ //
this.courseId = util.getCookie("courseId"); //
this.startTime = util.getCookie("startTime") ? new Date(util.getCookie("startTime")).getTime() : '' this.getList().then(() => {
this.stopTime = util.getCookie("stopTime") ? new Date(util.getCookie("stopTime")).getTime() : '' let cache = localStorage.getItem('codeCache')
if(cache){
this.projectPermissions = this.projectId ? 1 : 0 cache = JSON.parse(cache)
if(this.projectId){ this.getCache(cache.projectId, cache.judgmentId)
this.getQueryProject();
}else{
console.log(33)
this.getProjects();
let codeCache = localStorage.getItem('codeCache')
if(codeCache){
codeCache = JSON.parse(codeCache)
// if(codeCache.systemId && codeCache.systemId == this.$config.systemId){
// this.$confirm('', '', {
// confirmButtonText: '',
// cancelButtonText: '',
// type: 'success'
// }).then(() => {
// this.value1 = codeCache.projectId
// this.workbenchCus = codeCache.workbench
// this.isRecovery = true
// this.selectProject()
// let codeIds = []
// codeCache.workbench.map(n => codeIds.push(n.code.codeId))
// codeIds = codeIds.filter(n => n)
// this.codeIds = codeIds
// this.$emit('recoveryCode',codeCache.workbench1)
// }).catch(() => {
// localStorage.removeItem('codeCache')
// })
// }
} }
}).catch(res => {})
} }
this.assessmentId && this.projectId && this.checkVer()
this.codeId && this.codeIds.push(this.codeId)
// //
newmain.$on("codeid", val => { newmain.$on("codeid", val => {
this.codeid = val; this.codeid = val;
let codeId = this.codeid; let codeId = this.codeid;
this.codeIds.push(codeId);
}); });
// tableData // tableData
newmain.$on("updateJud", item => { newmain.$on("updateJud", item => {
@ -296,32 +263,44 @@ export default {
}); });
}, },
methods: { methods: {
checkVer() { //
let data = { getCache(projectId, judgmentId) {
userId: this.userId, this.$post(this.api.getLastCache, {
id: this.assessmentId bcId: judgmentId ? judgmentId : this.judgmentId,
} cid: this.courseId,
this.$get(this.api.qualifications,data).then(res => { projectId: projectId ? projectId : this.projectId
if(res.message == 'false'){ }).then(res => {
this.isSubmit = true; const code = res.getLastCache
newmain.$emit("isSubmit", this.isSubmit); if (code) {
this.$confirm('是否要继续上次的实验?', '提示', {
confirmButtonText: '是',
cancelButtonText: '否',
type: 'success'
}).then(() => {
localStorage.removeItem('codeCache')
this.projectId = projectId
this.judgmentId = judgmentId
this.points[0].code = code
this.$emit("tell", this.projectId, this.projectPermissions, this.points)
// this.$emit('recoveryCode', cache.curTab)
}).catch(() => {
localStorage.removeItem('codeCache')
})
} }
}); }).catch(res => {})
}, },
// //
reload() { reload() {
this.$post(this.api.DeleteCodes, this.codeIds).then(res => { this.$post(this.api.DeleteCodes).then(res => {
this.getClearTime() this.getClearTime()
this.grade = '00' this.grade = '00'
localStorage.removeItem('codeCache') localStorage.removeItem('codeCache')
this.codeIds = []
this.isSubmit = false this.isSubmit = false
newmain.$emit("isSubmit", this.isSubmit) newmain.$emit("isSubmit", this.isSubmit)
let workbench = this.workbench let workbench = this.workbench
workbench.map(n => { workbench.map(n => {
n.code = { n.code = {
code: '', code: ''
codeId: ''
} }
}) })
this.$emit('recoveryCode',workbench) this.$emit('recoveryCode',workbench)
@ -334,29 +313,24 @@ export default {
this.startCountFn() this.startCountFn()
}); });
}, },
//
Submit() { Submit() {
if(!this.codeIds.length) return this.$message.error('请先完成实验') // if(!this.codeIds.length) return this.$message.error('')
this.$confirm("此操作将视为结束考试, 是否继续?", "提示", { this.$confirm("此操作将视为结束考试, 是否继续?", "提示", {
confirmButtonText: "确定", confirmButtonText: "确定",
cancelButtonText: "取消", cancelButtonText: "取消",
type: "warning", type: "warning",
center: true center: true
}) }).then(() => {
.then(() => {
this.actEndTime = new Date().getTime(); this.actEndTime = new Date().getTime();
this.getClearTime(); this.getClearTime();
// //
this.$post(this.api.Submit, { this.$post(this.api.Submit, {
// projectPermissions: 0,
createTime: this.startTime, createTime: this.startTime,
endTime: this.stopTime, endTime: this.stopTime,
projectId: this.projectId, projectId: this.projectId,
projectPermissions: this.projectPermissions, projectPermissions: this.projectPermissions,
// assessmentId: 1,
assessmentId: this.assessmentId ? this.assessmentId : '', assessmentId: this.assessmentId ? this.assessmentId : '',
codeIds: this.codeIds,
judgmentPointsIds: this.judgmentPointsIds,
// studentId: 54,
studentId: this.studentId, studentId: this.studentId,
record: { record: {
courseId: 1, courseId: 1,
@ -394,20 +368,17 @@ export default {
}); });
}) })
.catch(err => {}); .catch(err => {});
}) }).catch(() => {
.catch(() => {
this.$message({ this.$message({
type: "info", type: "info",
message: "已取消提交" message: "已取消提交"
}); });
}); });
}, },
// //
timeFormat(param) { timeFormat(param) {
return param < 10 ? "0" + param : param; return param < 10 ? "0" + param : param;
}, },
// //
step() { step() {
$(".m_step").toggleClass("n_step"); $(".m_step").toggleClass("n_step");
@ -428,45 +399,26 @@ export default {
// this.text = '' // this.text = ''
// } // }
}, },
//
handleData(project,type){ getProDetail() {
if(!this.isSelected){ const projectId = this.projectId
this.value = project; return new Promise((resolve, reject) => {
this.value1 = project[0].projectId;
}
this.projectId = type == 2 ? project[0].projectId : this.projectId
if(type == 2) this.getQueryProject(0,1)
this.projectPermissions = type == 1 ? project[0].projectPermissions : this.projectPermissions
this.experimentTarget = project[0].experimentTarget;
this.experimentDescription = project[0].experimentDescription;
this.experimentHint = project[0].experimentHint;
this.actEndTime = project[0].endTime;
this.isRecovery = false
},
getQueryProject(projectId,type) {
//++++
this.$get(this.api.QueryProject, { this.$get(this.api.QueryProject, {
projectId: projectId ? projectId : this.projectId projectId
}).then(res => {
const points = res.projectJudgmentVos
const project = res.projectManage
points.map(e => {
e.code = ''
}) })
.then(res => { this.points = points
if(!type){ this.judgmentId = points[0].judgmentId
this.handleData(res.projectManage,1) this.experimentTarget = project.experimentTarget
this.projectId = res.projectManage[0].projectId this.experimentDescription = project.experimentDescription
} this.experimentHint = project.experimentHint
// debugger // this.actEndTime = project[0].endTime
this.points = res.projectJudgmentVos; this.hintOpen = !res.projectManage.hintOpen // 01
this.$emit("tell", this.value1, this.projectPermissions, this.points); this.$emit("tell", projectId, this.projectPermissions, this.points)
// -
if (this.points.length) {
this.$parent.workbench1 = '0';
}
this.tableData = res.message.projectJudgmentVos;
let arr1 = this.tableData;
let result1 = arr1.map(e => e.judgmentPointsId);
this.judgmentPointsIds = this.judgmentPointsIds.concat(result1)
this.isstartexperimentSuggests = !res.message.project[0].isstartexperimentSuggests //01
if (this.projectPermissions == "1") { if (this.projectPermissions == "1") {
this.text = "剩余"; this.text = "剩余";
var interval = setInterval(() => { var interval = setInterval(() => {
@ -511,25 +463,41 @@ export default {
this.startCountFn(); this.startCountFn();
} }
} }
resolve()
}).catch(err => {
reject()
})
}) })
.catch(err => {});
}, },
getProjects(){ //
getList(){
let data = { let data = {
systemId: 1, systemId: 1,
cId: this.courseId, cId: this.courseId, // id
permissions: this.projectPermissions permissions: this.projectPermissions
} }
return new Promise((resolve, reject) => {
this.$get(`${this.api.queryTestProject}`,data).then(res => { this.$get(`${this.api.queryTestProject}`,data).then(res => {
this.handleData(res.projects,2) const list = res.projects
}).catch(res => {}); this.projectList = list
this.projectId = list ? list[0].projectId : 0
this.getProDetail().then(() => {
resolve()
}).catch(res => {
reject()
})
}).catch(res => {
reject()
})
})
}, },
//
selectProject(){ selectProject(){
this.isSelected = true this.isSelected = true
this.assessmentId = '' this.assessmentId = ''
this.judgmentPointsIds = [] // -
this.codeIds = [] this.$parent.workbench1 = '0'
this.getQueryProject(this.value1) this.getProDetail()
this.isSubmit = false this.isSubmit = false
this.countVal = 0 this.countVal = 0
this.grade = 0 this.grade = 0
@ -552,9 +520,9 @@ export default {
this.minutes = minutes; this.minutes = minutes;
this.seconds = seconds; this.seconds = seconds;
}, },
//
startCountFn() { startCountFn() {
if (!this.isStart) { if (!this.isStart) { //
this.countVal = this.countVal ? this.countVal : 0; this.countVal = this.countVal ? this.countVal : 0;
let timer = setInterval(() => { let timer = setInterval(() => {
this.counterFn(this.countVal++); this.counterFn(this.countVal++);

@ -2,24 +2,22 @@
<div style="display:flex;"> <div style="display:flex;">
<div class="left"> <div class="left">
<codemirror <codemirror
v-model="exampleData" v-model="codeVal"
:value="codeid"
:options="cmOption" :options="cmOption"
class="code-mirror" class="code-mirror"
@ready="onCmReady3" @ready="ready"
ref="myCmGenerate" ref="myCmGenerate"
></codemirror> ></codemirror>
<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="AnswerTips()" @click="runCode"
:disabled="isAnswerTips" :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>
</div> </div>
<div class="code-right answer"> <div class="code-right answer">
<p class="text-wrapper" v-html="modifys"></p> <p class="text-wrapper" v-html="runResult"></p>
<!-- <p class="text-wrapper">{{modifys}}</p> -->
<div class="pic-wrap" v-if="picSrc"> <div class="pic-wrap" v-if="picSrc">
<div style="margin-bottom: 5px;text-align: center"> <div style="margin-bottom: 5px;text-align: center">
<img class="pic" :src="picSrc" alt=""> <img class="pic" :src="picSrc" alt="">
@ -27,17 +25,14 @@
<el-button class="download-btn" type="primary" size="mini" @click="$refs.picLink.click()">下载图片</el-button> <el-button class="download-btn" type="primary" size="mini" @click="$refs.picLink.click()">下载图片</el-button>
<a ref="picLink" style="display: none;" download="运行结果.png" :href="picSrc">下载图片</a> <a ref="picLink" style="display: none;" download="运行结果.png" :href="picSrc">下载图片</a>
</div> </div>
<div class="code_yes" v-show="this.isError == 0"> <div class="code_yes" v-show="this.isError">
<img src="../assets/img/yes.png" alt />运行成功 <img src="../assets/img/yes.png" alt />运行成功
</div> </div>
<div class="code_error" v-show="this.isError == 1"> <div class="code_error" v-show="this.isError === 0">
<img src="../assets/img/error.png" alt /> <img src="../assets/img/error.png" alt />
{{num}}行出现错误 {{errLine}}行出现错误
<!-- <el-button <el-button class="tips-btn" @click="getTips" v-show="showTips">提示</el-button>
style="color:rgba(255,49,49,1);background:rgba(255,255,255,1);margin-left:80px" <el-dialog title="答案提示" center :visible.sync="tipsVisible">
>求助</el-button>-->
<el-button class="tips-btn" @click="getQueryAnswer()" v-show="ShowAssessmentId">提示</el-button>
<el-dialog title="答案提示" center :visible.sync="error">
<el-tabs> <el-tabs>
<el-tab-pane label="参考答案"> <el-tab-pane label="参考答案">
<div class="answer-wrap" v-html="answer"></div> <div class="answer-wrap" v-html="answer"></div>
@ -90,37 +85,27 @@ import "codemirror/addon/fold/xml-fold.js";
// //
import "codemirror/theme/monokai.css"; import "codemirror/theme/monokai.css";
import "codemirror/theme/base16-light.css"; import "codemirror/theme/base16-light.css";
import * as $ from "jquery";
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'
const CANCEL_TOKEN = axios.CancelToken const CANCEL_TOKEN = axios.CancelToken // input
export default { export default {
props: ["workbench1", "code", "codeid", "projectId"], props: ["workbench1", "code", "projectId"],
data() { data() {
return { return {
courseId: util.getCookie("courseId"), assessmentId: util.getCookie("assessmentId"), // id
datas: [], courseId: util.getCookie("courseId"), // id
ShowAssessmentId: false, showTips: false, //
answer: "", answer: '', //
exampleData: this.code, codeVal: this.code,
codeId: this.codeid, runResult: '', //
codes: [], isError: false, //
submit: "", errLine: '', //
modifys: "", // isSubmit: false, //
isError: 2, runEnable: false, //
timer: "", tipsVisible: false, //
after: "", picSrc: '', // url
num: "", loadIns: null, // loading
userId: '',
studentId: "",
isSubmit: "", //
isAnswerTips: false,
error: false,
picVisible: false,
picSrc: '',
loadIns: null,
submiting: false,
cmOption: { cmOption: {
scrollbarStyle: "native", scrollbarStyle: "native",
tabSize: 2, // tab tabSize: 2, // tab
@ -149,41 +134,34 @@ export default {
theme: "monokai", // theme: "monokai", //
extraKeys: { Ctrl: "autocomplete" } // keyMap extraKeys: { Ctrl: "autocomplete" } // keyMap
}, },
inputTextReg: /^((?!#).*?(,|\(|\[|\{|\s)+)?input(?!\w)\(['|"]([\s\S]+?)['|"]\)/m,// input() inputTextReg: /^((?!#).*?(,|\(|\[|\{|\s)+)?input(?!\w)\(['|"]([\s\S]+?)['|"]\)/m, // input()
requestList: [], requestList: [], // inputaxios
sourceCode: '', sourceCode: '', // inputexit
requestTimer: null, requestTimer: null //
assessmentId: util.getCookie("assessmentId"),
}; };
}, },
components: { components: {
codemirror codemirror
}, },
watch: { watch: {
list() { codeVal(val) {
this.timer(); this.$emit("update:code", val)
},
exampleData(val) {
this.$emit("update:code", val);
},
codeId(val) {
this.$emit("update:codeid", val);
} }
}, },
mounted() { mounted() {
if (!this.assessmentId) { if (!this.assessmentId) this.showTips = true
this.ShowAssessmentId = true;
}
// //
newmain.$on("isSubmit", isSubmit => { newmain.$on("isSubmit", isSubmit => {
this.isSubmit = isSubmit; this.isSubmit = isSubmit
}); })
}, },
methods: { methods: {
onCmReady3() { //
ready() {
this.$refs.myCmGenerate.codemirror.setSize("auto", "calc(100vh - 149px)"); this.$refs.myCmGenerate.codemirror.setSize("auto", "calc(100vh - 149px)");
}, },
//
downloadFile(fileName,url) { downloadFile(fileName,url) {
var x = new XMLHttpRequest() var x = new XMLHttpRequest()
x.open("GET", url, true) x.open("GET", url, true)
@ -203,11 +181,11 @@ export default {
// input // input
confirmInput(msg){ confirmInput(msg){
let receiveResult = msg.replace('validing:','') let receiveResult = msg.replace('validing:','')
this.modifys += receiveResult this.runResult += receiveResult
this.$prompt(receiveResult, "提示", { this.$prompt(receiveResult, "提示", {
confirmButtonText: "确定" confirmButtonText: "确定"
}).then(({ value }) => { }).then(({ value }) => {
this.modifys += `${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,'')}')`,val => {
return `'${value}'` return `'${value}'`
@ -222,8 +200,8 @@ export default {
this.requestList.map(n => n('interrupt')) this.requestList.map(n => n('interrupt'))
},1000) },1000)
axios.post(this.api.UpdateCode,{ axios.post(this.api.runPythonCode,{
code: this.exampleData, code: this.codeVal,
bcId: this.workbench1, bcId: this.workbench1,
cid: this.courseId, cid: this.courseId,
projectId: this.projectId projectId: this.projectId
@ -236,19 +214,15 @@ 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 this.runResult = modify
this.after = modify.substring( this.errLine = parseInt(modify.substring(modify.indexOf("line") + 4, modify.length))
modify.indexOf("line") + 4,
modify.length
);
this.num = parseInt(this.after)
this.isError = res.message.isError this.isError = res.message.isError
}else if(result.includes('validing:')){ }else if(result.includes('validing:')){
this.isError = 0 this.isError = 0
this.confirmInput(result) this.confirmInput(result)
}else if(!res.message.isError){ }else if(!res.message.isError){
this.isError = 0 this.isError = 0
this.modifys += result this.runResult += result
newmain.$emit("updateJud",{ newmain.$emit("updateJud",{
id: res.data.judgmentPointsId, id: res.data.judgmentPointsId,
isError: res.data.isError isError: res.data.isError
@ -256,31 +230,30 @@ export default {
} }
}).catch(e => { }).catch(e => {
if(e && e.message == 'interrupt'){ if(e && e.message == 'interrupt'){
this.AnswerTips(true) this.runCode(true)
this.requestList = [] this.requestList = []
} }
}) })
}).catch(err => {}) }).catch(err => {})
}, },
AnswerTips(isWhile) {// isWhiletruewhile runCode(isWhile) { // isWhiletruewhile
if (this.isSubmit == "") { if (!this.isSubmit) {
this.submit = 1; if (!this.codeVal) {
if (this.codeid == "") {
this.$message({ this.$message({
message: "警告哦,内容为空不可运行", message: "警告哦,内容为空不可运行",
type: "warning" type: "warning"
}); })
} else { } else {
let inputTextReg = this.inputTextReg let inputTextReg = this.inputTextReg
let inputFuncReg = /input\(['|"]/g let inputFuncReg = /input\(['|"]/g
// input // input
if (inputTextReg.test(this.exampleData)) { if (inputTextReg.test(this.codeVal)) {
let sourceCode = this.exampleData let sourceCode = this.codeVal
sourceCode = sourceCode.replace(inputTextReg,val => { sourceCode = sourceCode.replace(inputTextReg,val => {
return val.replace(/\\n/g,"") return val.replace(/\\n/g,"")
}) })
this.exampleData = sourceCode this.codeVal = sourceCode
// inputexit"validing:"便 // inputexit"validing:"便
sourceCode = sourceCode.replace(inputFuncReg,val => { sourceCode = sourceCode.replace(inputFuncReg,val => {
@ -288,9 +261,9 @@ export default {
}) })
this.sourceCode = sourceCode this.sourceCode = sourceCode
if(!isWhile) this.modifys = '' if(!isWhile) this.runResult = ''
this.$post(this.api.UpdateCode, { this.$post(this.api.runPythonCode, {
code: this.exampleData, code: this.codeVal,
bcId: this.workbench1, bcId: this.workbench1,
cid: this.courseId, cid: this.courseId,
projectId: this.projectId projectId: this.projectId
@ -299,16 +272,12 @@ export default {
if(result.includes('File ')){ if(result.includes('File ')){
let modify = res.message.result let modify = res.message.result
if(isWhile){ if(isWhile){
this.modifys += modify this.runResult += modify
}else{ }else{
this.modifys = modify this.runResult = modify
} }
this.after = modify.substring( this.errLine = parseInt(modify.substring(modify.indexOf("line") + 4, modify.length))
modify.indexOf("line") + 4,
modify.length
);
this.num = parseInt(this.after)
this.isError = res.message.isError this.isError = res.message.isError
}else if(result.includes('validing:')){ }else if(result.includes('validing:')){
this.isError = 0 this.isError = 0
@ -319,93 +288,65 @@ export default {
this.loadIns = Loading.service({ this.loadIns = Loading.service({
background: 'transparent' background: 'transparent'
}) })
//() // Python
this.$post(this.api.UpdateCode, { this.$post(this.api.runPythonCode, {
code: this.exampleData, code: this.codeVal,
bcId: this.workbench1, bcId: this.workbench1,
cid: this.courseId, cid: this.courseId,
projectId: this.projectId projectId: this.projectId
}) }).then(res => {
.then(res => { const data = res.code
const photo = data.photoUrl
const result = data.runResult
this.loadIns.close() this.loadIns.close()
this.picSrc = '' this.picSrc = ''
if(typeof res.message == 'string'){ if(photo){
this.isError = res.message.isError; this.isError = 0
this.modifys = '' this.runResult = ''
this.picSrc = `${res.message}?id=${new Date().getTime()}` this.picSrc = `${photo}?id=${new Date().getTime()}`
newmain.$emit("updateJud",{
id: res.data.judgmentPointsId,
isError: res.data.isError
})
}else{ }else{
// //
// 7 // 7
if(!res.message.isError){ if(0){
let result = ''
try {
result = eval(res.message.result)
} catch (error) {}
if(result instanceof Array && result.length && (result[0].includes('.jpg') || result[0].includes('.png') || result[0].includes('.gif'))){ if(result instanceof Array && result.length && (result[0].includes('.jpg') || result[0].includes('.png') || result[0].includes('.gif'))){
result.map((n,i) => { result.map((n,i) => {
this.downloadFile(`${i+1}.jpg`,n) this.downloadFile(`${i+1}.jpg`,n)
}) })
this.isError = 0 this.isError = 0
this.modifys = '下载完成' this.runResult = '下载完成'
}else{ }else{
this.isError = res.message.isError; this.isError = 0
newmain.$emit("updateJud",{ this.runResult = data.runResult
id: res.data.judgmentPointsId, this.errLine = parseInt(result.substring(modify.indexOf("line") + 4, modify.length))
isError: res.data.isError
})
var modify = res.message.result;
this.modifys = modify;
this.after = modify.substring(
modify.indexOf("line") + 4,
modify.length
);
this.num = parseInt(this.after);
} }
}else{ } else {
this.isError = res.message.isError; this.isError = data.retResult
newmain.$emit("updateJud",{ this.runResult = result
id: res.data.judgmentPointsId, this.errLine = parseInt(result.substring(result.indexOf("line") + 4, result.length))
isError: res.data.isError
})
var modify = res.message.result;
this.modifys = modify;
this.after = modify.substring(
modify.indexOf("line") + 4,
modify.length
);
this.num = parseInt(this.after);
} }
} }
}) }).catch(res => {
.catch(res => {
res.status == 500 && this.$message.error('检测到代码里有非法代码,请检查是否有调用系统命令。') res.status == 500 && this.$message.error('检测到代码里有非法代码,请检查是否有调用系统命令。')
this.loadIns.close() this.loadIns.close()
}); })
clearTimeout(this.timer);
} }
} }
} else { } else {
this.isAnswerTips = true; this.runEnable = true
this.$message({ this.$message({
message: "警告哦,已提交不可再运行", message: "警告哦,已提交不可再运行",
type: "warning" type: "warning"
}); })
} }
}, },
getQueryAnswer() { getTips() {
this.error = true; this.tipsVisible = true
// //
this.$get(this.api.QueryAnswer, { this.$get(this.api.QueryAnswer, {
judgmentPointsId: this.workbench1 judgmentPointsId: this.workbench1
}) }).then(res => {
.then(res => { this.answer = res.message
this.answer = res.message; }).catch(err => {})
})
.catch(err => {});
} }
} }
}; };

@ -2,15 +2,12 @@ import config from '@/config'
let host = `${config.host}` let host = `${config.host}`
export default { export default {
QueryProject: `${host}occupationlab/projectManage/getProjectDetail`, //项目选择下拉框+项目信息+判分点信息展示 QueryProject: `${host}occupationlab/projectManage/getProjectDetail`,
ProjectId: `${host}/python/projectId`, //判分点下拉框信息展示 Submit: `${host}/python/submit`,
Submit: `${host}/python/submit`, //提交代码与判分点进行判断 runPythonCode: `${host}python/python/runPythonCode`,
UpdateCode: `${host}python/python/runPythonCode`, //实时更新编辑器代码(修改代码) QueryAnswer: `${host}/python/queryAnswer`,
QueryAnswer: `${host}/python/queryAnswer`, //提示答案 DeleteCodes: `${host}/python/deleteCodes`,
DeleteCodes: `${host}/python/deleteCodes`, //重新开始 queryTestProject: `${host}occupationlab/projectManage/getProjectBySystemId`,
QueryAllProject: `${host}/python/queryAllProject`, //项目选择下拉框 saveCache: `${host}python/python/saveCache`,
ChangeCode: `${host}/python/changeCode`, //input交互 getLastCache: `${host}python/python/getLastCache`
queryTestProject: `${host}occupationlab/projectManage/getProjectBySystemId`, //input交互
qualifications: `${host}/python/qualifications`, //input交互
saveCache: `${host}python/python/saveCache` //中途退出实验并保存实验数据(虚拟仿真实验)
} }

@ -11,11 +11,11 @@
<div class="flex center"> <div class="flex center">
<p v-if="$config.isHh" style="font-size: 18px">{{$config.title}}</p> <p v-if="$config.isHh" style="font-size: 18px">{{$config.title}}</p>
<p>编程语言</p> <p>编程语言</p>
<el-input placeholder="请输入内容" v-model="value" :disabled="true"></el-input> <el-input placeholder="请输入内容" v-model="language" :disabled="true"></el-input>
</div> </div>
<div class="tab"> <div class="tab">
<el-tabs v-model="workbench1" type="card"> <el-tabs v-model="curTab" type="card">
<el-tab-pane <el-tab-pane
v-for="item in workbench" v-for="item in workbench"
:key="item.judgmentId" :key="item.judgmentId"
@ -57,29 +57,12 @@ import util from '@/util'
export default { export default {
data() { data() {
return { return {
courseId: util.getCookie("courseId"), courseId: util.getCookie("courseId"), // id
// projectPermissions: 0, // (0 1 2)
isShow: false,
projectPermissions: 0, //(0 1 2)
ops: {
vuescroll: {},
scrollPanel: {},
rail: {
keepShow: true
},
bar: {
hoverStyle: true,
onlyShowBarOnScroll: false, //
background: "red", //
opacity: 0.5, //
"overflow-x": "hidden"
}
},
judgmentPointsId: "",
codeId: 0, codeId: 0,
value: "Python", language: "Python", //
workbench1: "", // curTab: "", //
workbench: [], workbench: [], //
editableTabs: [], editableTabs: [],
tabIndex: 2, tabIndex: 2,
name: "", name: "",
@ -98,35 +81,42 @@ export default {
codemirror, codemirror,
testPanel testPanel
}, },
beforeDestroy(){
this.leavePage()
},
mounted() { mounted() {
this.autoLogout() this.autoLogout()
if (window.history && window.history.pushState) { window.onbeforeunload = () => {
// this.leavePage()
history.pushState(null, null, document.URL);
window.addEventListener("popstate", this.goBack, false);
} }
}, },
destroyed() {
window.removeEventListener("popstate", this.goBack, false);
},
methods: { methods: {
//
leavePage(){ leavePage(){
if(!this.$refs.mainindex.isSubmit && !this.assessmentId && this.workbench.length){ const list = this.workbench
if(!this.$refs.mainindex.isSubmit && !this.assessmentId && list.length){
if(list.some(e => e.code)){
const cache = {
projectId: this.projectId,
judgmentId: list[this.curTab].judgmentId
}
localStorage.setItem('codeCache', JSON.stringify(cache))
list.map(e => {
if (e.code) {
let data = { let data = {
code: '', code: e.code,
bcId: this.workbench1, bcId: e.judgmentId,
cid: this.courseId, cid: this.courseId,
projectId: this.projectId projectId: this.projectId
} }
this.$post(this.api.saveCache,data).then(res => {}).catch(e => {}) this.$post(this.api.saveCache,data).then(res => {}).catch(e => {})
} }
})
}
}
}, },
// 退
autoLogout(){ autoLogout(){
let lastTime = new Date().getTime() let lastTime = new Date().getTime()
let logout = false let logout = false
//
document.onmousedown = () => { document.onmousedown = () => {
lastTime = new Date().getTime() lastTime = new Date().getTime()
} }
@ -138,23 +128,19 @@ export default {
} }
},1000) },1000)
}, },
goBack() {
this.leavePage()
history.back()
},
getDataFromChild(data) { getDataFromChild(data) {
sessionStorage.setItem("timer", parseInt(data)); sessionStorage.setItem("timer", parseInt(data));
}, },
recoveryCode(workbench){ recoveryCode(workbench){
this.workbench = workbench this.workbench = workbench
this.codeKey++ this.codeKey++
this.workbench1 = '0' this.curTab = '0'
}, },
reload(){ reload(){
this.$refs.mainindex.reload() this.$refs.mainindex.reload()
}, },
// 退
back() { back() {
this.leavePage()
if(this.projectPermissions){ if(this.projectPermissions){
// //
if (this.$config.isBeta) { // if (this.$config.isBeta) { //
@ -173,9 +159,11 @@ export default {
// //
getQueryIndex(value1, projectPermissions,workBench) { getQueryIndex(value1, projectPermissions,workBench) {
// //
this.projectId = value1; console.log(5555,workBench)
this.projectPermissions = projectPermissions; this.projectId = value1
this.projectPermissions = projectPermissions
this.workbench = workBench this.workbench = workBench
this.codeKey++
}, },
} }
}; };

Loading…
Cancel
Save