竞赛及考核添加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`, fileupload: `${config.host}occupationlab/oss/manage/fileupload`,
getDetailById: 'occupationlab/occupationlab/assessment/getDetailById', getDetailById: 'occupationlab/occupationlab/assessment/getDetailById',
pageStuAssessment: 'occupationlab/occupationlab/assessment/pageStuAssessment', pageStuAssessment: 'occupationlab/occupationlab/assessment/pageStuAssessment',
queryUserInfoDetails: `users/users/userAccount/queryUserInfoDetails`,
modelClassList: `nakadai/nakadai/model/reference/modelClassList`, modelClassList: `nakadai/nakadai/model/reference/modelClassList`,
studentModelList: `nakadai/nakadai/model/student/studentModelList`, studentModelList: `nakadai/nakadai/model/student/studentModelList`,
referenceDemoList: `nakadai/nakadai/model/reference/demo/referenceDemoList`, referenceDemoList: `nakadai/nakadai/model/reference/demo/referenceDemoList`,

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

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