|
|
@@ -1,11 +1,11 @@
|
|
|
<template>
|
|
|
- <view class="question-item">
|
|
|
+ <view class="question-item" :id="`qs_${question.id}`">
|
|
|
<view class="is-main-question">
|
|
|
<view v-if="question.typeId && !isSubQuestion" class="question-type">
|
|
|
{{ questionTypeDesc[question.typeId as EnumQuestionType] }}
|
|
|
</view>
|
|
|
<view class="question-content" :class="{ 'mt-30': isSubQuestion }">
|
|
|
- <uv-parse :content="getQuestionTitle"></uv-parse>
|
|
|
+ <uv-parse :content="getQuestionTitle()"></uv-parse>
|
|
|
</view>
|
|
|
<view class="question-options">
|
|
|
<view class="question-option" v-for="option in question.options"
|
|
|
@@ -25,8 +25,8 @@
|
|
|
</view>
|
|
|
</view>
|
|
|
<view v-if="question.subQuestions.length" class="is-sub-question">
|
|
|
- <question-item :question="subQuestion" v-for="subQuestion in question.subQuestions" :key="subQuestion.id"
|
|
|
- :is-sub-question="true" @update:question="emit('update:question', $event)" @select="handleSelectOption"
|
|
|
+ <question-item :question="subQuestion" v-for="(subQuestion, index) in question.subQuestions" :key="subQuestion.id"
|
|
|
+ :is-sub-question="true" :index="index" :total="question.subQuestions.length" @update:question="handleSubQuestionUpdate" @select="handleSelectOption"
|
|
|
@notKnow="handleSelectNotKnow" />
|
|
|
</view>
|
|
|
</view>
|
|
|
@@ -41,6 +41,8 @@ const { questionTypeDesc } = useExam();
|
|
|
const props = defineProps<{
|
|
|
question: Study.Question;
|
|
|
isSubQuestion?: boolean;
|
|
|
+ index?: number;
|
|
|
+ total?: number;
|
|
|
}>();
|
|
|
const nextQuestion = inject(NEXT_QUESTION);
|
|
|
const prevQuestion = inject(PREV_QUESTION);
|
|
|
@@ -50,13 +52,17 @@ const emit = defineEmits<{
|
|
|
(e: 'update:question', question: Study.Question): void;
|
|
|
(e: 'select', question: Study.Question): void;
|
|
|
(e: 'notKnow', question: Study.Question): void;
|
|
|
+ (e: 'scrollTo', selector: string): void;
|
|
|
}>();
|
|
|
-const getQuestionTitle = computed(() => {
|
|
|
+
|
|
|
+const getQuestionTitle = () => {
|
|
|
if (props.isSubQuestion) {
|
|
|
- return `[${questionTypeDesc[props.question.typeId as EnumQuestionType]}] ${props.question.title}`;
|
|
|
+ const prefix = questionTypeDesc[props.question.typeId as EnumQuestionType].slice(0, 2);
|
|
|
+ const qsOrder = props.total && props.total > 1 ? `${props.index! + 1}.` : '';
|
|
|
+ return `[${prefix}] ${qsOrder} ${props.question.title}`;
|
|
|
}
|
|
|
return props.question.title;
|
|
|
-});
|
|
|
+};
|
|
|
|
|
|
const handleNotKnow = () => {
|
|
|
// console.log('handleNotKnow')
|
|
|
@@ -66,10 +72,10 @@ const handleNotKnow = () => {
|
|
|
emit('update:question', props.question);
|
|
|
// emit('notKnow', props.question);
|
|
|
// nextQuestion?.();
|
|
|
- handleSelectNotKnow();
|
|
|
+ // handleSelectNotKnow();
|
|
|
+ emit('select', props.question);
|
|
|
}
|
|
|
const handleSelect = (option: Study.QuestionOption) => {
|
|
|
- // console.log('handleSelect', isDone.value)
|
|
|
if ([
|
|
|
EnumQuestionType.JUDGMENT,
|
|
|
EnumQuestionType.SINGLE_CHOICE,
|
|
|
@@ -96,21 +102,43 @@ const handleSelect = (option: Study.QuestionOption) => {
|
|
|
if (props.isSubQuestion) {
|
|
|
emit('select', props.question);
|
|
|
} else {
|
|
|
- handleSelectOption();
|
|
|
+ // 没有子题的,直接切换到下一题
|
|
|
+ changeQuestion();
|
|
|
}
|
|
|
}
|
|
|
+const handleSubQuestionUpdate = (question: Study.Question) => {
|
|
|
+ emit('update:question', question);
|
|
|
+ checkIsDone();
|
|
|
+}
|
|
|
const checkIsDone = () => {
|
|
|
if (props.question.subQuestions.length > 0) {
|
|
|
props.question.isDone = props.question.subQuestions.every(q => q.answers.length > 0 || q.isNotKnow);
|
|
|
+ } else {
|
|
|
+ props.question.isDone = props.question.answers.length > 0 || props.question.isNotKnow;
|
|
|
}
|
|
|
- props.question.isDone = props.question.answers.length > 0 || props.question.isNotKnow;
|
|
|
}
|
|
|
+// 子题选中方法
|
|
|
const handleSelectOption = () => {
|
|
|
- if (props.question.isDone) {
|
|
|
- nextQuestion?.();
|
|
|
- }
|
|
|
+ // changeQuestion();
|
|
|
+ findNotDoneSubQuestion();
|
|
|
}
|
|
|
const handleSelectNotKnow = () => {
|
|
|
+ // changeQuestion();
|
|
|
+ findNotDoneSubQuestion();
|
|
|
+}
|
|
|
+// 查找是否有子题没有做,有的话就自动滚动到目标处
|
|
|
+const findNotDoneSubQuestion = () => {
|
|
|
+ const notDoneSubQuestion = props.question.subQuestions.find(q => !q.isDone);
|
|
|
+ if (notDoneSubQuestion) {
|
|
|
+ const selector = `qs_${notDoneSubQuestion.id}`;
|
|
|
+ // 通知父组件滚动
|
|
|
+ emit('scrollTo', selector);
|
|
|
+ } else {
|
|
|
+ // 否则切换到下一题
|
|
|
+ changeQuestion();
|
|
|
+ }
|
|
|
+}
|
|
|
+const changeQuestion = () => {
|
|
|
if (props.question.isDone) {
|
|
|
nextQuestion?.();
|
|
|
}
|