diff --git a/src/components/TestPanel.vue b/src/components/TestPanel.vue index 02962ad..0f62c3f 100644 --- a/src/components/TestPanel.vue +++ b/src/components/TestPanel.vue @@ -214,10 +214,6 @@ import "codemirror/theme/base16-light.css"; import { mavonEditor } from 'mavon-editor' import 'mavon-editor/dist/css/index.css' import Stomp from 'stompjs' -// export const MQTT_USERNAME = 'huoran' // 连接用户名, todo: read from database -// export const MQTT_PASSWORD = 'huoran2024' // 连接密码, todo: read from database -export const MQTT_USERNAME = 'huorantest' // 连接用户名, todo: read from database -export const MQTT_PASSWORD = 'huorantest2024' // 连接密码, todo: read from database export default { data () { @@ -331,18 +327,27 @@ export default { if (this.assessmentId) { // 考核(考核才会从外面带进来assessmentId,练习是默认显示第一个项目,竞赛会带进来competitionId) this.getAssList() } else { // 练习 - if (Cookie.get('doneProjectId')) { + if (Cookie.get('doneProjectId')) { // 已经做完了实验,则直接恢复项目id this.projectId = +Cookie.get('doneProjectId') + } else { + // 没有初次加载的标识,说明不是第一次进来,而是当前页面刷新后进来这个方法,这时候则查最近一次跑的项目是哪个 + if (Cookie.get('admin-loaded')) { + const { data } = await this.$get(`${this.api.getTheMostRecentlyRunProject}`, { + cid: this.courseId + }) + if (data.length) this.projectId = data[0].projectId + } else { + Cookie.set('admin-loaded', 1) // 初次加载的标识 + } } Cookie.remove('doneProjectId') // 获取项目列表 - this.getList().then(() => { - if (!this.isSubmit) { - this.getCache() - } else { - this.closeLoad() - } - }).catch(res => { }) + await this.getList() + if (!this.isSubmit) { + this.getCache() + } else { + this.closeLoad() + } } this.competitionId && this.getCompetitionStatus() // 查询竞赛信息 this.getUserDetail() @@ -585,8 +590,8 @@ export default { competitionId: this.competitionId, assessmentId: assessmentId ? Number(assessmentId) : '', bcId: e.judgmentId, - projectId, // 项目id,同上 - cid // 课程id + projectId, + cid }) }) }) @@ -694,6 +699,17 @@ export default { this.startCount() this.clearReport() this.entryTime = await this.getNow() + + // 清除代码缓存 + this.points.map(async (e) => { + await this.$post(this.api.deleteTheLastUncommittedRecord, { + competitionId: this.competitionId, + assessmentId: this.assessmentId, + bcId: e.judgmentId, + projectId: this.projectId, + cid: this.courseId, + }) + }) }, //重新开始 async reloadConfirm () { @@ -715,14 +731,14 @@ export default { }, // 页面加载完后重置编辑框大小 ready (i) { - if (this.$refs['codemirror' + i]) { - const code = this.$refs['codemirror' + i].codemirror - if (code) { - code.on('beforeChange', (istance, change) => { - change.origin === 'paste' && change.cancel() - }) - } - } + // if (this.$refs['codemirror' + i]) { + // const code = this.$refs['codemirror' + i].codemirror + // if (code) { + // code.on('beforeChange', (istance, change) => { + // change.origin === 'paste' && change.cancel() + // }) + // } + // } }, vscodeRunCode (data) { const i = +data.sort @@ -1092,15 +1108,15 @@ export default { // 消息队列获取 connect () { - let ws = new WebSocket(`ws://139.159.153.48:15674/ws`); + let ws = new WebSocket(this.$config.isTest ? `ws://139.159.153.48:15674/ws` : `wss://python.occupationlab.com/ws`); // let ws = new WebSocket(`wss://python.occupationlab.com/ws`); this.client = Stomp.over(ws); this.client.heartbeat.outgoing = 0 this.client.heartbeat.incoming = 0 //初始化连接 const headers = { - login: MQTT_USERNAME, - passcode: MQTT_PASSWORD + login: this.$config.isTest ? 'huorantest' : 'huoran', + passcode: this.$config.isTest ? 'huorantest2024' : 'huoran2024' }; //进行连接 this.client.connect(headers.login, headers.passcode, this.onConnected, this.onFailed, 'pyhost'); diff --git a/src/views/Home.vue b/src/views/Home.vue index 09995ed..6f390a6 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -95,31 +95,6 @@ export default { testPanel }, mounted () { - // 保证同一个浏览器只有一个当前系统能打开 - const opened = +localStorage.getItem('opened') - if (opened) { - localStorage.setItem('opened', opened + 1) - this.notAllowed = 1 - this.$alert('我们注意到您当前已尝试打开多个实验页面。为保证实验的公平性和诚信,系统仅允许单个实验页面处于活跃状态。', '提示', { - confirmButtonText: '退出当前页面', - showClose: false, - callback: action => { - this.back() - } - }) - } else { - localStorage.setItem('opened', 1) - } - - // 页面离开后当前活跃的标识处理 - window.addEventListener('unload', function () { - const opened = +localStorage.getItem('opened') - if (opened) { - localStorage.setItem('opened', opened - 1) - } else { - localStorage.removeItem('opened') - } - }) document.onkeydown = function (event) { var e = event || window.event || arguments.callee.caller.arguments[0];