|
@@ -16,7 +16,6 @@ export default {
|
|
|
},
|
|
|
async mounted() {
|
|
|
this.heartbeatErrorNum = 0;
|
|
|
- this.first = true;
|
|
|
this.getRemainTimeFromServer();
|
|
|
this.intervalA = setInterval(() => {
|
|
|
this.getRemainTimeFromServer();
|
|
@@ -33,15 +32,18 @@ export default {
|
|
|
methods: {
|
|
|
...mapMutations(["setShouldSubmitPaper"]),
|
|
|
async getRemainTimeFromServer() {
|
|
|
- try {
|
|
|
- const res = await this.$http.get(
|
|
|
- "/api/ecs_oe_student/examControl/examHeartbeat"
|
|
|
- );
|
|
|
- this.remainTime = res.data;
|
|
|
+ const res = await this.$http.get(
|
|
|
+ "/api/ecs_oe_student/examControl/examHeartbeat"
|
|
|
+ );
|
|
|
+ if (/\d+/.test(res.data)) {
|
|
|
+ if (this.remainTime === null) {
|
|
|
+ // 仅当剩余考试时间没有被初始化才使用服务器时间。否则使用本机时间。
|
|
|
+ this.remainTime = res.data;
|
|
|
+ }
|
|
|
this.heartbeatErrorNum = 0;
|
|
|
- } catch (e) {
|
|
|
+ } else {
|
|
|
this.heartbeatErrorNum++;
|
|
|
- if (this.heartbeatErrorNum === 5) {
|
|
|
+ if (this.heartbeatErrorNum === 10) {
|
|
|
// 心跳异常5次则退出考试
|
|
|
this.$Modal.error({
|
|
|
title: "网络连接异常",
|
|
@@ -52,7 +54,7 @@ export default {
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
- this.getRemainTimeFromServer();
|
|
|
+ setTimeout(() => this.getRemainTimeFromServer(), 10 * 1000);
|
|
|
}
|
|
|
}
|
|
|
},
|