|
@@ -1,4 +1,12 @@
|
|
-import { ref, watch, onBeforeMount, Ref, computed, nextTick } from "vue";
|
|
|
|
|
|
+import {
|
|
|
|
+ ref,
|
|
|
|
+ watch,
|
|
|
|
+ onBeforeMount,
|
|
|
|
+ Ref,
|
|
|
|
+ computed,
|
|
|
|
+ nextTick,
|
|
|
|
+ ComputedRef,
|
|
|
|
+} from "vue";
|
|
import * as API from "@/api";
|
|
import * as API from "@/api";
|
|
import { Howl, Howler } from "howler";
|
|
import { Howl, Howler } from "howler";
|
|
import { useRoute } from "vue-router";
|
|
import { useRoute } from "vue-router";
|
|
@@ -39,7 +47,7 @@ export function useTopicMode() {
|
|
}
|
|
}
|
|
|
|
|
|
//语音设置
|
|
//语音设置
|
|
-export function useAudioSet(currentAnswerIndex: Ref<number>) {
|
|
|
|
|
|
+export function useAudioSet(currentSubject: ComputedRef<any>) {
|
|
const aotuPlayFlag = ref(false);
|
|
const aotuPlayFlag = ref(false);
|
|
|
|
|
|
let sound: Howl;
|
|
let sound: Howl;
|
|
@@ -68,9 +76,28 @@ export function useAudioSet(currentAnswerIndex: Ref<number>) {
|
|
};
|
|
};
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 自动读题
|
|
|
|
|
|
+ * 读题
|
|
*/
|
|
*/
|
|
- const issueAudioPlay = () => {};
|
|
|
|
|
|
+ const subjectAudioPlay = (
|
|
|
|
+ type: "读题" | "读官方解释" | "读技巧解释" | "读题+答案"
|
|
|
|
+ ) => {
|
|
|
|
+ switch (type) {
|
|
|
|
+ case "读题":
|
|
|
|
+ audioPlay(currentSubject.value.issuemp3);
|
|
|
|
+ break;
|
|
|
|
+ case "读官方解释":
|
|
|
|
+ audioPlay(currentSubject.value.explainjsmp3);
|
|
|
|
+ break;
|
|
|
|
+ case "读技巧解释":
|
|
|
|
+ audioPlay(currentSubject.value.explainMp3);
|
|
|
|
+ break;
|
|
|
|
+ case "读题+答案":
|
|
|
|
+ audioPlay([currentSubject.value.issuemp3, currentSubject.value.answermp3]);
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
|
|
/**
|
|
/**
|
|
* 停止播放
|
|
* 停止播放
|
|
@@ -82,22 +109,18 @@ export function useAudioSet(currentAnswerIndex: Ref<number>) {
|
|
//音频模块end
|
|
//音频模块end
|
|
const aotuPlaySet = () => {
|
|
const aotuPlaySet = () => {
|
|
aotuPlayFlag.value = !aotuPlayFlag.value;
|
|
aotuPlayFlag.value = !aotuPlayFlag.value;
|
|
- if (aotuPlayFlag.value) issueAudioPlay();
|
|
|
|
- if (!aotuPlayFlag.value) audioPause();
|
|
|
|
|
|
+ aotuPlayFlag.value ? subjectAudioPlay("读题") : audioPause();
|
|
};
|
|
};
|
|
|
|
|
|
- onBeforeMount(() => {
|
|
|
|
- watch(currentAnswerIndex, () => {
|
|
|
|
- if (aotuPlayFlag.value) issueAudioPlay(); //自动读题
|
|
|
|
- });
|
|
|
|
|
|
+ //自动读题
|
|
|
|
+ watch(currentSubject, () => {
|
|
|
|
+ if (aotuPlayFlag.value) subjectAudioPlay("读题"); //自动读题
|
|
});
|
|
});
|
|
|
|
|
|
return {
|
|
return {
|
|
aotuPlayFlag,
|
|
aotuPlayFlag,
|
|
- issueAudioPlay,
|
|
|
|
- audioPause,
|
|
|
|
aotuPlaySet,
|
|
aotuPlaySet,
|
|
- audioPlay,
|
|
|
|
|
|
+ subjectAudioPlay
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
@@ -105,12 +128,13 @@ const useSubjectList = () => {
|
|
const subjectList = ref<any[]>([]); //题目列表
|
|
const subjectList = ref<any[]>([]); //题目列表
|
|
const subjectTotal = ref(0); //题目总数
|
|
const subjectTotal = ref(0); //题目总数
|
|
const pageNum = ref(1); //当前请求页码
|
|
const pageNum = ref(1); //当前请求页码
|
|
|
|
+ const pageSize = ref(100); //当前请求每页数据
|
|
const query = useRoute().query; //路由query参数
|
|
const query = useRoute().query; //路由query参数
|
|
onBeforeMount(async () => {
|
|
onBeforeMount(async () => {
|
|
const res = await API.getTopicList({
|
|
const res = await API.getTopicList({
|
|
...query,
|
|
...query,
|
|
pageNum: pageNum.value,
|
|
pageNum: pageNum.value,
|
|
- pageSize: 10,
|
|
|
|
|
|
+ pageSize: pageSize.value,
|
|
});
|
|
});
|
|
subjectList.value = res.list;
|
|
subjectList.value = res.list;
|
|
subjectTotal.value = res.total;
|
|
subjectTotal.value = res.total;
|
|
@@ -122,7 +146,7 @@ const useSubjectList = () => {
|
|
const res = await API.getTopicList({
|
|
const res = await API.getTopicList({
|
|
...query,
|
|
...query,
|
|
pageNum: pageNum.value,
|
|
pageNum: pageNum.value,
|
|
- pageSize: 10,
|
|
|
|
|
|
+ pageSize: pageSize.value,
|
|
});
|
|
});
|
|
subjectList.value = subjectList.value.concat(res.list);
|
|
subjectList.value = subjectList.value.concat(res.list);
|
|
};
|
|
};
|
|
@@ -140,62 +164,17 @@ const useSubjectList = () => {
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
|
|
-export const useSubjectShowLogic = () => {
|
|
|
|
|
|
+const useSubjectCheck = (
|
|
|
|
+ currentSubject: ComputedRef<any>,
|
|
|
|
+ nextSubject: () => Promise<void>
|
|
|
|
+) => {
|
|
const trueNum = ref(0); //正确数量
|
|
const trueNum = ref(0); //正确数量
|
|
const falseNum = ref(0); //错误数量
|
|
const falseNum = ref(0); //错误数量
|
|
const isJumpNext = ref(false); //答对跳转下一题
|
|
const isJumpNext = ref(false); //答对跳转下一题
|
|
- const {
|
|
|
|
- subjectList,
|
|
|
|
- subjectTotal,
|
|
|
|
- loadNewSubject,
|
|
|
|
- currentSubject,
|
|
|
|
- currentSubjectIndex,
|
|
|
|
- } = useSubjectList(); //获取题目列表
|
|
|
|
|
|
|
|
- const nextBtnState = ref(true); //下一题数据请求锁
|
|
|
|
- /**
|
|
|
|
- * 展示下一题
|
|
|
|
- */
|
|
|
|
- const nextSubject = async () => {
|
|
|
|
- if (currentSubjectIndex.value < subjectList.value.length - 1) {
|
|
|
|
- currentSubjectIndex.value++;
|
|
|
|
- } else {
|
|
|
|
- if (nextBtnState.value) {
|
|
|
|
- //禁用下一题按钮
|
|
|
|
- nextBtnState.value = false;
|
|
|
|
- //题目数量不足加载数据
|
|
|
|
- await loadNewSubject();
|
|
|
|
- //启用按钮
|
|
|
|
- nextBtnState.value = true;
|
|
|
|
- nextSubject()
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- /**
|
|
|
|
- * 展示上一题
|
|
|
|
- */
|
|
|
|
- const lastSubject = () => {
|
|
|
|
- if (currentSubjectIndex.value > 0) {
|
|
|
|
- currentSubjectIndex.value--;
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
/**
|
|
/**
|
|
- * 题目类型判断
|
|
|
|
- * @param type
|
|
|
|
- * @returns
|
|
|
|
|
|
+ * 选择答案后进行校验
|
|
*/
|
|
*/
|
|
- const topicType = (type: Number) => {
|
|
|
|
- switch (type) {
|
|
|
|
- case 0:
|
|
|
|
- return "判断题";
|
|
|
|
- case 1:
|
|
|
|
- return "单选题";
|
|
|
|
- case 2:
|
|
|
|
- return "多选题";
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- //选择答案后
|
|
|
|
const userAnswerChange = () => {
|
|
const userAnswerChange = () => {
|
|
currentSubject.value.optsBack = currentSubject.value.opts.map(
|
|
currentSubject.value.optsBack = currentSubject.value.opts.map(
|
|
(val: String) => {
|
|
(val: String) => {
|
|
@@ -230,6 +209,56 @@ export const useSubjectShowLogic = () => {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ return {
|
|
|
|
+ trueNum,
|
|
|
|
+ falseNum,
|
|
|
|
+ isJumpNext,
|
|
|
|
+ userAnswerChange,
|
|
|
|
+ };
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+export const useSubjectShowLogic = () => {
|
|
|
|
+ const {
|
|
|
|
+ subjectList,
|
|
|
|
+ subjectTotal,
|
|
|
|
+ loadNewSubject,
|
|
|
|
+ currentSubject,
|
|
|
|
+ currentSubjectIndex,
|
|
|
|
+ } = useSubjectList(); //获取题目列表
|
|
|
|
+
|
|
|
|
+ const nextBtnState = ref(true); //下一题数据请求锁
|
|
|
|
+ /**
|
|
|
|
+ * 展示下一题
|
|
|
|
+ */
|
|
|
|
+ const nextSubject = async () => {
|
|
|
|
+ if (currentSubjectIndex.value < subjectList.value.length - 1) {
|
|
|
|
+ currentSubjectIndex.value++;
|
|
|
|
+ } else {
|
|
|
|
+ if (nextBtnState.value) {
|
|
|
|
+ //禁用下一题按钮
|
|
|
|
+ nextBtnState.value = false;
|
|
|
|
+ //题目数量不足加载数据
|
|
|
|
+ await loadNewSubject();
|
|
|
|
+ //启用按钮
|
|
|
|
+ nextBtnState.value = true;
|
|
|
|
+ nextSubject();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ /**
|
|
|
|
+ * 展示上一题
|
|
|
|
+ */
|
|
|
|
+ const lastSubject = () => {
|
|
|
|
+ if (currentSubjectIndex.value > 0) {
|
|
|
|
+ currentSubjectIndex.value--;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const { trueNum, falseNum, isJumpNext, userAnswerChange } = useSubjectCheck(
|
|
|
|
+ currentSubject,
|
|
|
|
+ nextSubject
|
|
|
|
+ );
|
|
|
|
+
|
|
return {
|
|
return {
|
|
currentSubject,
|
|
currentSubject,
|
|
currentSubjectIndex,
|
|
currentSubjectIndex,
|
|
@@ -240,6 +269,5 @@ export const useSubjectShowLogic = () => {
|
|
falseNum,
|
|
falseNum,
|
|
isJumpNext,
|
|
isJumpNext,
|
|
userAnswerChange,
|
|
userAnswerChange,
|
|
- topicType,
|
|
|
|
};
|
|
};
|
|
};
|
|
};
|