|
@@ -143,7 +143,9 @@ export default {
|
|
|
multipleChoice: "DuoXuan", // 多选题
|
|
|
gapFilling: "TianKong" // 填空题
|
|
|
}, // 试题类型
|
|
|
- endTimeSeconds: null, // 考试开始时间的信息
|
|
|
+ examEndTimeSeconds: null, // 考试结束时的毫秒秒数
|
|
|
+ examBeforeHalfEndTimeSeconds: null, // 开始考试一半时间的毫秒秒数
|
|
|
+ startTimeSeconds: 0, // 当前开始考试的毫秒秒数时长
|
|
|
timeDiff: "00:00:00", // 距离考试结束的时间
|
|
|
interval: null, // 计时器
|
|
|
examQuestionList: [], // 试题列表
|
|
@@ -151,6 +153,7 @@ export default {
|
|
|
answerValue: [], // 当前试题的所答
|
|
|
inputValue: [], // 填空题时输入框的值
|
|
|
isInited: false, // 是否已初始化完毕
|
|
|
+ isOverHalfTime: false, // 是否已超过1/3的考试时间
|
|
|
answerTime: {
|
|
|
startTime: 0,
|
|
|
endTime: 0
|
|
@@ -158,9 +161,19 @@ export default {
|
|
|
};
|
|
|
},
|
|
|
mounted() {
|
|
|
+ // window.onbeforeunload = function() {
|
|
|
+ // return "正在考试,无法退出";
|
|
|
+ // };
|
|
|
+ // history.pushState(null, null, document.URL);
|
|
|
+ // window.addEventListener("popstate", function() {
|
|
|
+ // Toast("正在考试中,无法退出");
|
|
|
+ // history.pushState(null, null, document.URL);
|
|
|
+ // });
|
|
|
+
|
|
|
this.initDataFun(); // 初始化数据信息
|
|
|
},
|
|
|
beforeDestroy() {
|
|
|
+ console.log("in");
|
|
|
if (this.interval) {
|
|
|
clearInterval(this.interval); // 销毁前清空计时器
|
|
|
}
|
|
@@ -180,6 +193,10 @@ export default {
|
|
|
message: "试题信息有误,请重新进入当前页面",
|
|
|
theme: "round-button"
|
|
|
}).then(() => {
|
|
|
+ // window.removeEventListener("popstate", function() {
|
|
|
+ // Toast("正在考试中,无法退出");
|
|
|
+ // history.pushState(null, null, document.URL);
|
|
|
+ // });
|
|
|
this.$router.back();
|
|
|
});
|
|
|
return;
|
|
@@ -265,11 +282,11 @@ export default {
|
|
|
curTime = new Date(addMinute);
|
|
|
// 在当前时间curTime变量上加上秒
|
|
|
let addSeconds = new Date(
|
|
|
- curTime.setSeconds(curTime.getSeconds() + tarTime.seconds)
|
|
|
+ curTime.setSeconds(curTime.getSeconds() + tarTime.seconds + 1)
|
|
|
);
|
|
|
curTime = new Date(addSeconds);
|
|
|
- this.answerTime.endTime = curTime; // 赋值结束时间
|
|
|
- this.endTimeSeconds = curTime.getTime(); // 赋值结束时间的秒数
|
|
|
+ this.answerTime.endTime = curTime; // 赋值结束时间-标准时间格式
|
|
|
+ this.examEndTimeSeconds = curTime.getTime(); // 赋值结束时间的毫秒秒数
|
|
|
},
|
|
|
// 方法:分别获取时 分 秒
|
|
|
getTimeHoursMinuteSecondsTogetherFun(e) {
|
|
@@ -299,17 +316,39 @@ export default {
|
|
|
// 设置:倒计时定时器
|
|
|
setIntervalFun() {
|
|
|
let _self = this;
|
|
|
+ let isStart = false;
|
|
|
// 获取距离目标时间的毫秒时间戳
|
|
|
this.interval = setInterval(() => {
|
|
|
let curTime = Date.now(); // 获取当前时间的毫秒时间戳
|
|
|
- let diffTime = this.endTimeSeconds - curTime; // 计算出当前时间距离目标时间的时间差
|
|
|
+ if (!isStart) {
|
|
|
+ this.examBeforeHalfEndTimeSeconds = this.examEndTimeSeconds - curTime; // 获取当前开始考试的时间的毫秒秒数
|
|
|
+ console.log(
|
|
|
+ "examBeforeHalfEndTimeSeconds:",
|
|
|
+ this.examBeforeHalfEndTimeSeconds
|
|
|
+ );
|
|
|
+ isStart = true;
|
|
|
+ }
|
|
|
+ let diffTime = this.examEndTimeSeconds - curTime; // 计算出当前时间距离目标时间的时间差
|
|
|
// 判断倒计时是否完成,成立则清除定时器,关闭函数执行
|
|
|
if (diffTime <= 0) {
|
|
|
+ Dialog.close(); // 关闭弹框提示框
|
|
|
clearInterval(_self.interval);
|
|
|
_self.timeDiff = "00:00:00";
|
|
|
this.examsEndFun(true); // 自动交卷
|
|
|
return;
|
|
|
}
|
|
|
+ this.startTimeSeconds = this.startTimeSeconds + 1000; // 新增开始进行了考试的时长
|
|
|
+ console.log(this.startTimeSeconds);
|
|
|
+ if (
|
|
|
+ this.examBeforeHalfEndTimeSeconds / 2 > diffTime &&
|
|
|
+ !this.isOverHalfTime
|
|
|
+ ) {
|
|
|
+ console.log("超过一半考试时间了");
|
|
|
+ // this.$nextTick(() => {
|
|
|
+ // this.$refs.uploadUserInput.click(); // 调用拍照工具
|
|
|
+ // });
|
|
|
+ this.isOverHalfTime = true;
|
|
|
+ }
|
|
|
let hours = Math.floor(diffTime / (1000 * 60 * 60));
|
|
|
let minutes = Math.floor(
|
|
|
(diffTime - hours * 60 * 60 * 1000) / (1000 * 60)
|
|
@@ -427,12 +466,6 @@ export default {
|
|
|
this.examQuestionList[nextIndex],
|
|
|
nextIndex
|
|
|
);
|
|
|
- if (nextIndex + 1 > 3) {
|
|
|
- let isPrimeVal = this.isPrime(nextIndex + 1);
|
|
|
- if (isPrimeVal) {
|
|
|
- this.$refs.uploadUserInput.click(); // 调用拍照工具
|
|
|
- }
|
|
|
- }
|
|
|
},
|
|
|
// 操作:确定
|
|
|
handleSureFun() {
|
|
@@ -441,30 +474,10 @@ export default {
|
|
|
}
|
|
|
this.examQuestionList[this.answerIndex].userAnswer = this.answerValue;
|
|
|
this.handleNextFun();
|
|
|
- },
|
|
|
- // 方法:判断一个数是否为质数
|
|
|
- isPrime(num) {
|
|
|
- // 不是数字或者数字小于2
|
|
|
- if (typeof num !== "number" || !Number.isInteger(num)) {
|
|
|
- // Number.isInterget 判断是否为整数
|
|
|
- return false;
|
|
|
- }
|
|
|
- // 2是质数
|
|
|
- if (num === 2) {
|
|
|
- return true;
|
|
|
- } else if (num % 2 === 0) {
|
|
|
- // 排除偶数
|
|
|
- return false;
|
|
|
- }
|
|
|
- // 依次判断是否能被奇数整除,最大循环为数值的开方
|
|
|
- var squareRoot = Math.sqrt(num);
|
|
|
- // 因为2已经验证过,所以从3开始;且已经排除偶数,所以每次加2
|
|
|
- for (var i = 3; i <= squareRoot; i += 2) {
|
|
|
- if (num % i === 0) {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // 若超过了了考试时间的1/3,则需要调用拍照
|
|
|
+ if (this.isOverHalfTime) {
|
|
|
+ this.$refs.uploadUserInput.click(); // 调用拍照工具
|
|
|
}
|
|
|
- return true;
|
|
|
},
|
|
|
// 操作:交卷 isAuto:true(时间到了的自动交卷) false(手动交卷)
|
|
|
handleSubmitFun() {
|
|
@@ -489,6 +502,10 @@ export default {
|
|
|
if (isAuto) {
|
|
|
Dialog({ message: "考试时间已到,该考试已结束,并自动交卷" });
|
|
|
}
|
|
|
+ // window.removeEventListener("popstate", function() {
|
|
|
+ // Toast("正在考试中,无法退出");
|
|
|
+ // history.pushState(null, null, document.URL);
|
|
|
+ // });
|
|
|
this.$store.commit("toggleLoading", true);
|
|
|
let grades = this.getUserExamAllPointsFun(); // 方法:计算成绩
|
|
|
let answers = this.getUserExamAllAnswersFun(); // 方法:获取当前用户所有题目作答的答案
|