竞赛及考核添加websocket,去掉定时器

openf12
yujialong 1 year ago
parent b4c6e94cf5
commit 9e3f20314f
  1. 1
      src/api/index.js
  2. 120
      src/components/TestPanel.vue
  3. 2
      src/config/index.js

@ -20,6 +20,7 @@ export default {
fileupload: `${config.host}occupationlab/oss/manage/fileupload`,
getDetailById: 'occupationlab/occupationlab/assessment/getDetailById',
pageStuAssessment: 'occupationlab/occupationlab/assessment/pageStuAssessment',
queryUserInfoDetails: `users/users/userAccount/queryUserInfoDetails`,
modelClassList: `nakadai/nakadai/model/reference/modelClassList`,
studentModelList: `nakadai/nakadai/model/student/studentModelList`,
referenceDemoList: `nakadai/nakadai/model/reference/demo/referenceDemoList`,

@ -325,7 +325,7 @@ export default {
token: Cookie.get('admin-token'),
systemId: Cookie.get('admin-systemId') || 1,
classId: Cookie.get('admin-classId'),
className: Cookie.get('admin-className') ? decodeURI(Cookie.get('admin-className')) : '',
className: Cookie.get('admin-className') ? Cookie.get('admin-className') : '',
courseId: Cookie.get('admin-courseId'),
projectId: Cookie.get('admin-projectId') ? Number(Cookie.get('admin-projectId')) : '',
assessmentId: Cookie.get('admin-assessmentId'),
@ -363,7 +363,6 @@ export default {
taskList: [], //
pannelTab: 'first', //
isSelected: false, // true
statusTimer: null, //
reportId: '',
cmOption: {
@ -395,7 +394,8 @@ export default {
reportPoints: [],
reportVisible: false,
tableHeight: 0,
dragIds: ['panelHeader', 'aside', 'main', 'infoContainer']
dragIds: ['panelHeader', 'aside', 'main', 'infoContainer'],
submiting: false
};
},
components: {
@ -427,13 +427,9 @@ export default {
this.getCache()
}
}).catch(res => { })
if (this.competitionId) {
clearInterval(this.statusTimer)
this.statusTimer = setInterval(_ => {
this.getCompetitionStatus()
}, 1000)
}
}
this.competitionId && this.getCompetitionStatus() //
this.getUserDetail()
// this.drag()
this.tableHeight = window.innerHeight - 360
},
@ -564,9 +560,7 @@ export default {
this.getCache()
}).catch(res => { })
//
this.statusTimer = setInterval(_ => {
this.getAssStatus()
}, 1000)
this.getAssStatus()
}
}).catch(res => { })
},
@ -599,7 +593,7 @@ export default {
this.closeLoad()
localStorage.removeItem('codeCache')
} else {
if (Cookie.get('admin-projectId') && !this.competitionId) {
if (Cookie.get('admin-projectId') && this.projectPermissions == 0) {
Cookie.remove('admin-projectId')
}
let newJudgmentId = '' //
@ -672,7 +666,7 @@ export default {
})
}
},
//
//
getAssStatus () {
//
this.isSubmit || this.$get(this.api.getDetailById, {
@ -681,7 +675,6 @@ export default {
const done = res.data ? res.data.status === 2 : false // (0 1 2)
//
if (done) {
clearInterval(this.statusTimer)
this.$alert('考核时间已到,系统已自动交卷', '提示', {
confirmButtonText: '确定'
})
@ -689,7 +682,7 @@ export default {
}
}).catch(res => { })
},
//
//
getCompetitionStatus () {
//
this.isSubmit || this.$post(`${this.api.getCompetition}?competitionId=${this.competitionId}`).then(({ competition }) => {
@ -700,13 +693,13 @@ export default {
const now = Date.now()
//
if (now >= new Date(stage.endTime)) {
clearInterval(this.statusTimer)
this.$alert('竞赛时间已到,系统已自动交卷', '提示', {
confirmButtonText: '确定'
})
this.submit()
} else { //
this.counter((endTime - now) / 1000)
} else { //
this.countVal = (endTime - Date.now()) / 1000
this.startCount()
}
}
}).catch(res => { })
@ -776,7 +769,6 @@ export default {
ready () {
for (let i = 0; i < this.points.length; i++) {
const code = this.$refs['codemirror' + i][0].codemirror
console.log('ready', code)
// code && code.setSize('auto', 'calc(100vh - 150px)')
code && code.setSize('auto', '300px')
@ -784,6 +776,8 @@ export default {
},
//
confirmSubmit () {
if (this.submiting) return false
this.submiting = true
const isVscode = this.$parent.language // vscode
const { taskList } = this
const pointList = this.$parent.workbench
@ -842,7 +836,9 @@ export default {
this.submit()
}
}
}).catch(() => { })
}).catch(() => {
this.submiting = false
})
},
//
submit () {
@ -891,7 +887,6 @@ export default {
this.$post(this.api.submit, data).then(({ retInfo, reportId }) => {
localStorage.removeItem('codeCache')
this.setSubmit(true)
clearInterval(this.statusTimer)
this.reportVisible = false
let list = retInfo
let { taskList } = this
@ -912,14 +907,17 @@ export default {
this.$store.commit('setReportId', reportId)
this.$store.commit('setTaskList', taskList)
this.editReport(reportId)
this.submiting = false
//
this.competitionId && this.resultsDetails == 0 && this.$alert(`提交成功${this.resultAnnouncementTime != 0 ? ',成绩将在' + this.resultAnnouncementTime + '小时后发布,请去参赛信息模块查看' : ''}`, '提示', {
confirmButtonText: '确定',
callback: action => {
this.$parent.back()
}
})
}).catch(err => { })
// this.competitionId && this.resultsDetails == 0 && this.$alert(`${this.resultAnnouncementTime != 0 ? '' + this.resultAnnouncementTime + '' : ''}`, '', {
// confirmButtonText: '',
// callback: action => {
// this.$parent.back()
// }
// })
}).catch(err => {
this.submiting = false
})
},
//
editReport (reportId) {
@ -981,8 +979,24 @@ export default {
this.minutes = '00'
this.hour = '00'
},
//
//
counter (counterTime) {
if (counterTime <= 0) {
if (this.projectPermissions) { // /
clearInterval(this.counterTimer)
this.$alert(`${this.projectPermissions == 2 ? '竞赛' : '考核'}时间已到,系统已自动交卷`, '提示', {
confirmButtonText: '确定'
})
this.submit()
} else {
this.handleCounter(counterTime)
}
} else {
this.handleCounter(counterTime)
}
},
//
handleCounter (counterTime) {
let leave1 = counterTime % (24 * 3600) //
let leave2 = leave1 % 3600 //
let leave3 = leave2 % 60 //
@ -1065,7 +1079,51 @@ export default {
}
}
document.querySelector('#toggle').onmousedown = this.pannelVisible ? this.togglePannel : drag1
}
},
// websocket
// socket
open () {
console.log("socket连接成功");
},
// socket
error () {
console.log("连接错误");
},
//
getMessage (msg) {
console.log("==websocket接收数据==");
console.log(JSON.parse(msg.data));
const { content } = JSON.parse(msg.data)
// 1234-id
if (content == 1) {
this.getCompetitionStatus()
} else if (content === '3-' + this.assessmentId) { // 3-id
this.getAssStatus()
}
},
// socket
close () {
console.log("socket已经关闭");
},
// socket
initSocket ({ id, account }) {
// socket
this.socket = new WebSocket(`${this.$config.isTest ? 'ws' : 'wss'}://${this.$config.isDev ? '192.168.31.51:9100' : location.host}/nakadai/websocket/${id}/${account}`)
// this.socket = new WebSocket(`ws://121.37.12.51:9100/nakadai/websocket/${id}/${account}`)
// socket
this.socket.onopen = this.open;
// socket
this.socket.onerror = this.error;
// socket
this.socket.onmessage = this.getMessage;
},
//
getUserDetail () {
this.$get(this.api.queryUserInfoDetails).then(res => {
this.initSocket(res.result.userAccount)
}).catch(res => { })
},
}
};
</script>

@ -66,5 +66,5 @@ export default {
/**
* @description 长时间未操作自动退出登录时间
*/
autoLogoutTime: 3600000
autoLogoutTime: 1000 * 60 * 60
}
Loading…
Cancel
Save