|
@@ -2,12 +2,16 @@ import { computed, onMounted, reactive, ref, watch, onBeforeUnmount } from "vue"
|
|
|
import { openApi } from "@/api/open/type";
|
|
|
import moment from 'moment';
|
|
|
import audio from "@/utils/audio";
|
|
|
+import { useStore } from "vuex";
|
|
|
export const useDriverExam = (requestFn: Promise<openApi.selectFreeQuestionInfoRes>, config = {
|
|
|
- watch: true,
|
|
|
- countDown: true
|
|
|
+ autoNext: false,
|
|
|
+ autoRead: false,
|
|
|
+ countDown: true,
|
|
|
+ autoAnswer: true
|
|
|
}) => {
|
|
|
+ const store = useStore()
|
|
|
let timerId = 0
|
|
|
- let examMillSeconds = 45 * 60 * 1000
|
|
|
+ let examTimeMillSeconds = config.countDown ? 45 * 60 * 1000 : 0
|
|
|
const falseNum = ref(0)
|
|
|
const trueNum = ref(0)
|
|
|
const list = ref<openApi.selectFreeQuestionInfoRes["rows"]>([{
|
|
@@ -529,12 +533,12 @@ export const useDriverExam = (requestFn: Promise<openApi.selectFreeQuestionInfoR
|
|
|
return listIndex.value + 1
|
|
|
})
|
|
|
const countDown = ref('00:45:00')
|
|
|
- const setPageNumToListIndex = (page:string|number)=>{
|
|
|
+ const setPageNumToListIndex = (page: string | number) => {
|
|
|
page = Number(page)
|
|
|
- listIndex.value = page-1
|
|
|
-
|
|
|
+ listIndex.value = page - 1
|
|
|
+
|
|
|
}
|
|
|
- const playIssueAudio = ()=>{
|
|
|
+ const playIssueAudio = () => {
|
|
|
audio.playAudio(list.value[listIndex.value].issuemp3)
|
|
|
}
|
|
|
const getProblemTypeName = (type: number) => {
|
|
@@ -592,10 +596,10 @@ export const useDriverExam = (requestFn: Promise<openApi.selectFreeQuestionInfoR
|
|
|
} else {
|
|
|
list.value[listIndex.value].userAnswer = answer;
|
|
|
}
|
|
|
- //判断对错
|
|
|
+ //判断对错,以及是否自动下一题
|
|
|
if (
|
|
|
list.value[listIndex.value].questionType !== 3 &&
|
|
|
-
|
|
|
+
|
|
|
list.value[listIndex.value].userAnswer.length
|
|
|
) {
|
|
|
const userAnswer = list.value[listIndex.value].userAnswer as string;
|
|
@@ -604,6 +608,13 @@ export const useDriverExam = (requestFn: Promise<openApi.selectFreeQuestionInfoR
|
|
|
list.value[listIndex.value].isComplete = true;
|
|
|
list.value[listIndex.value].isError = false;
|
|
|
trueNum.value++;
|
|
|
+ //自动跳转下一题
|
|
|
+ if (store.state.sysConfig.autoNext) {
|
|
|
+ window.setTimeout(() => {
|
|
|
+ nextProblem()
|
|
|
+ }, 1500)
|
|
|
+
|
|
|
+ }
|
|
|
} else {
|
|
|
list.value[listIndex.value].isComplete = true;
|
|
|
list.value[listIndex.value].isError = true;
|
|
@@ -611,7 +622,7 @@ export const useDriverExam = (requestFn: Promise<openApi.selectFreeQuestionInfoR
|
|
|
}
|
|
|
} else if (
|
|
|
list.value[listIndex.value].questionType == 3 &&
|
|
|
-
|
|
|
+
|
|
|
list.value[listIndex.value].userAnswer.length
|
|
|
) {
|
|
|
const userAnswer = Object.assign([], list.value[listIndex.value].userAnswer) as string[];
|
|
@@ -622,6 +633,13 @@ export const useDriverExam = (requestFn: Promise<openApi.selectFreeQuestionInfoR
|
|
|
list.value[listIndex.value].isComplete = true;
|
|
|
list.value[listIndex.value].isError = false;
|
|
|
trueNum.value++;
|
|
|
+ //自动跳转下一题
|
|
|
+ if (store.state.sysConfig.autoNext) {
|
|
|
+ window.setTimeout(() => {
|
|
|
+ nextProblem()
|
|
|
+ }, 1500)
|
|
|
+
|
|
|
+ }
|
|
|
} else {
|
|
|
list.value[listIndex.value].isComplete = true;
|
|
|
list.value[listIndex.value].isError = true;
|
|
@@ -634,6 +652,7 @@ export const useDriverExam = (requestFn: Promise<openApi.selectFreeQuestionInfoR
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
};
|
|
|
const switchIndexByJudge = (index: number) => {
|
|
|
let name = "";
|
|
@@ -683,8 +702,9 @@ export const useDriverExam = (requestFn: Promise<openApi.selectFreeQuestionInfoR
|
|
|
}
|
|
|
return select;
|
|
|
};
|
|
|
- if (config.watch) {
|
|
|
- watch(listIndex, (newVal, oldVal) => {
|
|
|
+
|
|
|
+ watch(listIndex, (newVal, oldVal) => {
|
|
|
+ if (config.autoAnswer) {
|
|
|
//判断对错
|
|
|
if (
|
|
|
list.value[oldVal].questionType !== 3 &&
|
|
@@ -739,9 +759,12 @@ export const useDriverExam = (requestFn: Promise<openApi.selectFreeQuestionInfoR
|
|
|
) {
|
|
|
alert("正确答案:" + list.value[oldVal].answer);
|
|
|
}
|
|
|
- //提示
|
|
|
- });
|
|
|
- }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //提示
|
|
|
+ });
|
|
|
+
|
|
|
const getCorrectRate = () => {
|
|
|
if (trueNum.value + falseNum.value) {
|
|
|
Math.round((trueNum.value) / (trueNum.value + falseNum.value) * 100) / 100
|
|
@@ -767,11 +790,14 @@ export const useDriverExam = (requestFn: Promise<openApi.selectFreeQuestionInfoR
|
|
|
list.value = res.rows;
|
|
|
})
|
|
|
timerId = window.setInterval(() => {
|
|
|
- examMillSeconds = examMillSeconds - 1000
|
|
|
- countDown.value = moment(examMillSeconds).format('00:mm:ss')
|
|
|
- if (examMillSeconds === 0) {
|
|
|
+ if (examTimeMillSeconds === 0) {
|
|
|
+ console.log('已经清除')
|
|
|
window.clearInterval(timerId)
|
|
|
+ return
|
|
|
}
|
|
|
+ examTimeMillSeconds = examTimeMillSeconds - 1000
|
|
|
+ countDown.value = moment(examTimeMillSeconds).format('00:mm:ss')
|
|
|
+
|
|
|
}, 1000)
|
|
|
|
|
|
|