|
@@ -4,6 +4,8 @@
|
|
|
|
|
|
<script>
|
|
<script>
|
|
import moment from "moment";
|
|
import moment from "moment";
|
|
|
|
+import { createNamespacedHelpers } from "vuex";
|
|
|
|
+const { mapMutations } = createNamespacedHelpers("examingHomeModule");
|
|
|
|
|
|
export default {
|
|
export default {
|
|
name: "RemainTime",
|
|
name: "RemainTime",
|
|
@@ -13,13 +15,46 @@ export default {
|
|
};
|
|
};
|
|
},
|
|
},
|
|
async mounted() {
|
|
async mounted() {
|
|
- // const res = await this.$http.get("/api/ecs_oe_student/examControl/examHeartbeat");
|
|
|
|
- // this.remainTime = res.data.leftTime;
|
|
|
|
|
|
+ this.getRemainTimeFromServer();
|
|
|
|
+ this.first = true;
|
|
|
|
+ this.remainTime += 60 * 1000; //补偿心跳
|
|
|
|
+ this.intervalA = setInterval(() => {
|
|
|
|
+ if (this.first) {
|
|
|
|
+ // 跳过第一次
|
|
|
|
+ this.first = false;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ this.getRemainTimeFromServer();
|
|
|
|
+ }, 60 * 1000);
|
|
|
|
+ this.intervalB = setInterval(
|
|
|
|
+ () => (this.remainTime = this.remainTime - 1000),
|
|
|
|
+ 1000
|
|
|
|
+ );
|
|
|
|
+ },
|
|
|
|
+ beforeDestroy() {
|
|
|
|
+ clearInterval(this.intervalA);
|
|
|
|
+ clearInterval(this.intervalB);
|
|
|
|
+ },
|
|
|
|
+ methods: {
|
|
|
|
+ ...mapMutations(["shouldSumbitPaper"]),
|
|
|
|
+ async getRemainTimeFromServer() {
|
|
|
|
+ const res = await this.$http.get(
|
|
|
|
+ "/api/ecs_oe_student/examControl/examHeartbeat"
|
|
|
|
+ );
|
|
|
|
+ this.remainTime = res.data;
|
|
|
|
+ }
|
|
},
|
|
},
|
|
computed: {
|
|
computed: {
|
|
remainTimeFormatted: function() {
|
|
remainTimeFormatted: function() {
|
|
return moment.utc(this.remainTime).format("HH:mm:ss");
|
|
return moment.utc(this.remainTime).format("HH:mm:ss");
|
|
}
|
|
}
|
|
|
|
+ },
|
|
|
|
+ watch: {
|
|
|
|
+ remainTime(val, oldVal) {
|
|
|
|
+ if (oldVal && val === 0) {
|
|
|
|
+ this.shouldSumbitPaper();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
};
|
|
};
|
|
</script>
|
|
</script>
|