diff --git a/src/api/index.js b/src/api/index.js index c92574f..2ff46ae 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -8,9 +8,7 @@ export default { queryTestProject: 'occupationlab/occupationlab/projectManage/getProjectBySystemId', editExperimentalData: 'occupationlab/occupationlab/experimentalReport/editExperimentalData', queryBcJudgmentPointByBcId: 'judgment/judgment/bcJudgmentPoint/queryBcJudgmentPointByBcId', - saveCache: 'python/python/saveCache', - getLastCache: 'python/python/getLastCache', - delCache: 'python/python/delCache', + getLastCache: 'python/python/finalRunRecord', getTheMostRecentlyRunProject: 'python/python/getTheMostRecentlyRunProject', getDataProductBoughtByOurSchool: 'data/data/myDate/getDataProductBoughtByOurSchool', getPurchasedTableByCategory: `data/data/myDate/getPurchasedTableByCategory`, diff --git a/src/components/TestPanel.vue b/src/components/TestPanel.vue index 65af807..98a0040 100644 --- a/src/components/TestPanel.vue +++ b/src/components/TestPanel.vue @@ -320,10 +320,8 @@ import "codemirror/theme/base16-light.css"; import { mavonEditor } from 'mavon-editor' import 'mavon-editor/dist/css/index.css' import Stomp from 'stompjs' -export const IP = "x.108.x.33" // 自己的mq服务ip export const MQTT_USERNAME = 'huoran' // 连接用户名, todo: read from database export const MQTT_PASSWORD = 'huoran2024' // 连接密码, todo: read from database -export const VIRTUAL_HOST = '15674' // 侦听器端口 export default { data () { @@ -406,6 +404,7 @@ export default { client: '', accountId: '', runCodeType: '', + finishVscodeItem: 0, }; }, components: { @@ -441,12 +440,16 @@ export default { Cookie.remove('doneProjectId') // 获取项目列表 this.getList().then(() => { - let cache = localStorage.getItem('codeCache') // 获取本地缓存 - // 如果有缓存,再调接口取上次运行的代码 - if (cache) { - this.getCache(JSON.parse(cache)) + if (!this.isSubmit) { + let cache = localStorage.getItem('codeCache') // 获取本地缓存 + // 如果有缓存,再调接口取上次运行的代码 + if (cache) { + this.getCache(JSON.parse(cache)) + } else { + this.getCache() + } } else { - this.getCache() + this.closeLoad() } }).catch(res => { }) } @@ -619,6 +622,10 @@ export default { }, // 获取上次缓存记录 async getCache (cache) { + if (this.isSubmit) { + this.closeLoad() + return false + } const pId = cache ? cache.projectId : '' const projectId = Number(pId || this.projectId) const cid = this.courseId @@ -663,7 +670,7 @@ export default { cid // 课程id }).then(res => { this.closeLoad() - const result = res.runningResult + const result = res.runRecord // 如果有缓存代码 if (result) { hasCache = 1 @@ -722,16 +729,6 @@ export default { }).catch(() => { // 选择了不继续上次的实验,则清除本地缓存,并删除服务器里缓存的代码 localStorage.removeItem('codeCache') - // 删除该项目下所有判分规则的缓存代码 - points.map(e => { - e.code && this.$post(this.api.delCache, { - competitionId: this.competitionId, - assessmentId, - bcId: e.judgmentId, - projectId, - cid - }).then(res => { }).catch(() => { }) - }) }) }) } @@ -854,8 +851,12 @@ export default { } }, vscodeRunCode (data) { - // this.$parent.workbench[i].codeId = data.codeId - // this.$parent.workbench[i].retResult = 1 + console.log("🚀 ~ vscodeRunCode ~ data:", data, this.$parent.workbench) + const i = +data.sort + this.$parent.workbench[i].codeId = data.codeId + this.$parent.workbench[i].retResult = 1 + this.finishVscodeItem++ + this.finishVscodeItem === this.$parent.workbench.length && this.submit() }, emptyRunCode (data) { this.$parent.workbench[0].codeId = data.codeId @@ -877,7 +878,7 @@ export default { } else { if (!taskList.find(e => e.code || e.codeResult)) msg = '实验报告未填写,实验成绩为零,是否确认提交?' } - + this.finishVscodeItem = 0 this.$confirm(msg, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', @@ -887,9 +888,8 @@ export default { }).then(() => { // vscode类型的产品提交前需要自动运行每个判分点的代码以获取codeId if (isVscode) { - const promises = [] taskList.map(async (e, i) => { - (e.code || e.codeResult) && promises.push(new Promise(async (resolve, reject) => { + if (e.code || e.codeResult) { this.runCodeType = 'vscodeRunCode' await this.$post(this.api.runPythonCode, { code: e.code, @@ -901,11 +901,7 @@ export default { sort: i }) this.$parent.workbench[i].answer = e.codeResult - resolve() - })) - }) - Promise.all(promises).then(_ => { - this.submit() + } }) } else { // 如果全部都没运行直接点提交,则主动运行一个空代码。(不然会造成上次运行的结果,这次进来不运行直接提交的话,会无法取到运行结果) @@ -1220,7 +1216,8 @@ export default { // 消息队列获取 connect () { - let ws = new WebSocket(`ws://124.71.74.9:15674/ws`); + // let ws = new WebSocket(`ws://124.71.74.9:15674/ws`); + let ws = new WebSocket(`wss://python.occupationlab.com/ws`); this.client = Stomp.over(ws); //初始化连接 const headers = { @@ -1251,7 +1248,7 @@ export default { } else { newmain.$emit('runCode', data) } - this.runCodeType = '' + if (this.runCodeType !== 'vscodeRunCode') this.runCodeType = '' } else if (typeof data === 'string') { newmain.$emit('setPid', data) } diff --git a/src/components/codemirror.vue b/src/components/codemirror.vue index a72ccf0..caca07e 100644 --- a/src/components/codemirror.vue +++ b/src/components/codemirror.vue @@ -464,6 +464,7 @@ export default { this.isSubmit = isSubmit }) newmain.$on('runCode', data => { + this.pid = '' this.handleRunCode(data) }) newmain.$on('setPid', pid => { @@ -701,7 +702,7 @@ export default { if (data) { const photo = data.photoUrl const result = data.runResult || '' - this.$emit('cache') // 每次运行代码都要把代码传给后端做缓存 + // this.$emit('cache') // 每次运行代码都要把代码传给后端做缓存 if (this.loadIns) this.loadIns.close() this.picSrcList = [] this.$emit('update:photoUrl', '') @@ -743,6 +744,7 @@ export default { }, // 运行代码 runCode (isWhile) { // isWhile为true表示代码里有while循环,右边的运行结果需要拼接展示,而不是直接覆盖 + this.pid = '' if (!this.isSubmit) { let code = this.codeVal if (!code) { diff --git a/src/views/Home.vue b/src/views/Home.vue index d08af0d..8c8e40f 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -170,21 +170,7 @@ export default { judgmentIdList: this.workbench.map(e => e.judgmentId) } // 如果有输入代码,则要入库,否则,只保存到本地 - if (list.some(e => e.code)) { - list.map(e => { - if (e.code) { - let data = { - competitionId: this.competitionId, - assessmentId: this.assessmentId, - code: e.code, - bcId: e.judgmentId, - cid: this.courseId, - projectId: this.projectId - } - this.$post(this.api.saveCache, data).then(res => { }).catch(e => { }) - } - }) - } else { + if (!list.some(e => e.code)) { cache.empty = true // 没有输入代码的,加个标识,回到页面的时候不需要调接口了,只需要恢复项目和判分点即可 } localStorage.setItem('codeCache', JSON.stringify(cache)) // 在本地缓存里保存项目id和判分点id,下次进来通过这两个id去查找缓存代码。之所以不在前端缓存代码是预防更换了浏览器或电脑后依然可以找回缓存代码,只不过更换了客户端后本地缓存就消失了,这种情况就做一个向下处理,就切换项目的时候去恢复代码