From 798b02e176de142c5adc8377d0dcc6070691559e Mon Sep 17 00:00:00 2001 From: yujialong <479214531@qq.com> Date: Fri, 29 Mar 2024 18:32:22 +0800 Subject: [PATCH] fix --- src/components/TestPanel.vue | 10 +++++++++- src/components/codemirror.vue | 29 ++++++++++++++++------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/components/TestPanel.vue b/src/components/TestPanel.vue index 8dc9129..dcf3336 100644 --- a/src/components/TestPanel.vue +++ b/src/components/TestPanel.vue @@ -675,6 +675,7 @@ export default { if (result) { hasCache = 1 if (newJudgmentId === '') newJudgmentId = i + e.finalCode = result.code e.code = result.code e.codeId = result.id e.answer = result.runResult @@ -704,6 +705,7 @@ export default { this.points.map(e => { const item = points.find(n => n.judgmentId === e.judgmentId) if (item) { + item.finalCode && this.$set(e, 'finalCode', item.finalCode) item.code && this.$set(e, 'code', item.code) item.codeId && this.$set(e, 'codeId', item.codeId) item.answer && this.$set(e, 'answer', item.answer) @@ -717,6 +719,7 @@ export default { } else { this.points.map(e => { const item = points.find(n => n.judgmentId === e.judgmentId) + item.finalCode && this.$set(e, 'finalCode', item.finalCode) item.code && this.$set(e, 'code', item.code) item.codeId && this.$set(e, 'codeId', item.codeId) item.answer && this.$set(e, 'answer', item.answer) @@ -892,6 +895,8 @@ export default { if (e.code || e.codeResult) { this.runCodeType = 'vscodeRunCode' await this.$post(this.api.runPythonCode, { + assessmentId: this.assessmentId, + competitionId: this.competitionId, code: e.code, bcId: e.judgmentId, cid: this.courseId, @@ -908,6 +913,8 @@ export default { if (!pointList.find(e => e.codeId)) { this.runCodeType = 'emptyRunCode' this.$post(this.api.runPythonCode, { + assessmentId: this.assessmentId, + competitionId: this.competitionId, code: '', bcId: pointList[0].judgmentId, cid: this.courseId, @@ -1263,8 +1270,9 @@ export default { // 心跳检测 heartbeatDetection () { setInterval(async () => { + this.client.send('ping') await this.$get(this.api.heartbeatDetection) - }, 58 * 1000) + }, 56 * 1000) }, // 获取用户详情 getUserDetail () { diff --git a/src/components/codemirror.vue b/src/components/codemirror.vue index 80869de..cc31c44 100644 --- a/src/components/codemirror.vue +++ b/src/components/codemirror.vue @@ -329,8 +329,8 @@ export default { data () { return { token: Cookie.get('admin-token'), - assessmentId: Cookie.get('admin-assessmentId'), // 考核id - competitionId: Cookie.get('admin-competitionId'), + assessmentId: Cookie.get('admin-assessmentId') || '', // 考核id + competitionId: Cookie.get('admin-competitionId') || '', fromManager: Cookie.get('admin-fromManager'), // 是否是从教师端进入 courseId: Cookie.get('admin-courseId'), // 课程id mallId: Cookie.get('admin-mallId'), @@ -435,6 +435,7 @@ export default { pid: '', cancelRunTimer: null, runCodeConfirm: null, + isStopRunCode: 0, }; }, components: { @@ -586,24 +587,16 @@ export default { newmain.$emit('changeRunStatus', '') this.runCodeType = fn clearTimeout(this.cancelRunTimer) - // this.cancelRunTimer = setTimeout(() => { - // this.runCodeConfirm = this.$confirm('当前代码已运行超过5秒钟,是否终止运行?', '提示', { - // type: 'warning', - // closeOnClickModal: false, - // showClose: false - // }).then(async () => { - // if (this.pid) await this.$post(`${this.api.endRunningProcess}?pid=${this.pid}`) - // if (this.loadIns) this.loadIns.close() - // }).catch(() => { }) - // }, 5000) }, // 终止运行 async stopRunCode () { + this.isStopRunCode = 1 if (this.pid) await this.$post(`${this.api.endRunningProcess}?pid=${this.pid}`) this.pid = '' if (this.loadIns) this.loadIns.close() }, inputRunCode (data) { + if (this.isStopRunCode) return false const result = data.runResult if (result.includes('File ')) { this.runResult = result @@ -647,8 +640,11 @@ export default { this.requestList.map(n => n('interrupt')) }, 1000) + this.isStopRunCode = 0 this.handleRunCodeCb('inputRunCode') axios.post(config.host + this.api.runPythonCode, { + assessmentId: this.assessmentId, + competitionId: this.competitionId, code: this.sourceCode, bcId: this.judgmentId, cid: this.courseId, @@ -681,6 +677,7 @@ export default { if (this.runCodeType && this[this.runCodeType]) this[this.runCodeType](data) }, runCodeCb1 (res) { + if (this.isStopRunCode) return false const result = data.runResult if (result.includes('File ')) { if (isWhile) { @@ -699,7 +696,7 @@ export default { this.$emit('update:retResult', data.retResult) // 更新返回结果 }, runCodeCb2 (data) { - if (data.sort != this.index) return false + if (this.isStopRunCode || data.sort != this.index) return false // 正常返回结果 if (data) { const photo = data.photoUrl @@ -774,8 +771,11 @@ export default { this.sourceCode = code if (!isWhile) this.runResult = '' + this.isStopRunCode = 0 this.handleRunCodeCb('runCodeCb1') this.$post(this.api.runPythonCode, { + assessmentId: this.assessmentId, + competitionId: this.competitionId, code, bcId, cid, @@ -799,8 +799,11 @@ export default { }) // 把代码传给后端,在后端运行Python代码 + this.isStopRunCode = 0 this.handleRunCodeCb('runCodeCb2') this.$post(this.api.runPythonCode, { + assessmentId: this.assessmentId, + competitionId: this.competitionId, code, bcId, cid,