考试5秒内只能提交一次

This commit is contained in:
zhangsir
2024-05-06 15:42:58 +08:00
parent efa84f6703
commit f3e9168e76

View File

@@ -92,8 +92,8 @@
if(this.examId){ if(this.examId){
this.loadExamInfo(); this.loadExamInfo();
} }
this.debouncedPresent = this.debounce(this.present, 500); this.debouncedPresent = this.throttle(this.present, 5000);
this.confirmStop = this.debounce(this.submitTest,500) this.confirmStop = this.throttle(this.submitTest,5000)
}, },
methods: { methods: {
changeTimer(){ changeTimer(){
@@ -352,14 +352,14 @@
} }
}) })
}, },
debounce(func, delay) { throttle(func, delay) {
let timerId; let lastExecTime = 0;
return function (...args) { return function (...args) {
if (timerId) clearTimeout(timerId); const now = Date.now();
timerId = setTimeout(() => { if (now - lastExecTime >= delay) {
func.apply(this, args); func.apply(this, args);
timerId = null; lastExecTime = now;
}, delay); }
}; };
}, },
present(){ present(){