|
|
@@ -12,7 +12,7 @@ const getNow = (): number => {
|
|
|
// #ifdef MP-WEIXIN
|
|
|
return Date.now();
|
|
|
// #endif
|
|
|
-
|
|
|
+
|
|
|
// #ifndef MP-WEIXIN
|
|
|
if (typeof performance !== 'undefined' && performance.now) {
|
|
|
return performance.now();
|
|
|
@@ -31,7 +31,7 @@ const requestAnimFrame = (() => {
|
|
|
return setTimeout(() => callback(Date.now()), 1000 / 60) as unknown as number;
|
|
|
};
|
|
|
// #endif
|
|
|
-
|
|
|
+
|
|
|
// #ifndef MP-WEIXIN
|
|
|
if (typeof requestAnimationFrame !== 'undefined') {
|
|
|
return requestAnimationFrame;
|
|
|
@@ -52,7 +52,7 @@ const cancelAnimFrame = (() => {
|
|
|
clearTimeout(id as unknown as NodeJS.Timeout);
|
|
|
};
|
|
|
// #endif
|
|
|
-
|
|
|
+
|
|
|
// #ifndef MP-WEIXIN
|
|
|
if (typeof cancelAnimationFrame !== 'undefined') {
|
|
|
return cancelAnimationFrame;
|
|
|
@@ -588,7 +588,9 @@ export const useExam = () => {
|
|
|
if (currentQuestion.value.activeSubIndex < currentQuestion.value.subQuestions.length - 1) {
|
|
|
currentQuestion.value.activeSubIndex++;
|
|
|
} else {
|
|
|
- currentIndex.value++;
|
|
|
+ const lastIndex = currentIndex.value + 1;
|
|
|
+ questionList.value[lastIndex].activeSubIndex = 0;
|
|
|
+ currentIndex.value = lastIndex;
|
|
|
}
|
|
|
}
|
|
|
// 上一题
|
|
|
@@ -600,7 +602,9 @@ export const useExam = () => {
|
|
|
if (currentQuestion.value.activeSubIndex > 0) {
|
|
|
currentQuestion.value.activeSubIndex--;
|
|
|
} else {
|
|
|
- currentIndex.value--;
|
|
|
+ const prevIndex = currentIndex.value - 1;
|
|
|
+ questionList.value[prevIndex].activeSubIndex = questionList.value[prevIndex].subQuestions.length - 1;
|
|
|
+ currentIndex.value = prevIndex;
|
|
|
}
|
|
|
} else {
|
|
|
if (currentIndex.value > 0) {
|
|
|
@@ -652,12 +656,12 @@ export const useExam = () => {
|
|
|
// 开始计时
|
|
|
const startTiming = () => {
|
|
|
startCount();
|
|
|
-
|
|
|
+
|
|
|
// 记录开始时间戳(毫秒)
|
|
|
if (practiceStartTime === 0) {
|
|
|
practiceStartTime = getNow();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 使用 requestAnimFrame 更新显示,更流畅且性能更好
|
|
|
// 兼容微信小程序环境
|
|
|
const updatePracticeDuration = () => {
|
|
|
@@ -669,20 +673,20 @@ export const useExam = () => {
|
|
|
animationFrameId = requestAnimFrame(updatePracticeDuration);
|
|
|
}
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
// 开始动画帧循环
|
|
|
animationFrameId = requestAnimFrame(updatePracticeDuration);
|
|
|
}
|
|
|
// 停止计时
|
|
|
const stopTiming = () => {
|
|
|
stopCount();
|
|
|
-
|
|
|
+
|
|
|
// 取消动画帧
|
|
|
if (animationFrameId !== null) {
|
|
|
cancelAnimFrame(animationFrameId);
|
|
|
animationFrameId = null;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 如果正在计时,累加经过的时间
|
|
|
if (practiceStartTime > 0) {
|
|
|
const elapsed = (getNow() - practiceStartTime) / 1000;
|
|
|
@@ -806,7 +810,7 @@ export const useExam = () => {
|
|
|
virtualIndex: 0,
|
|
|
duration: 0,
|
|
|
activeSubIndex: 0,
|
|
|
- hasSubQuestions: item.subQuestions?.length > 0,
|
|
|
+ hasSubQuestions: item.subQuestions && item.subQuestions.length > 0,
|
|
|
typeTitle: item.typeTitle
|
|
|
} as Study.Question
|
|
|
}
|