|
@@ -65,14 +65,9 @@ export const useExam = () => {
|
|
|
const subQuestionIndex = ref<number>(0);
|
|
const subQuestionIndex = ref<number>(0);
|
|
|
// 包含状态的问题列表
|
|
// 包含状态的问题列表
|
|
|
const stateQuestionList = computed(() => {
|
|
const stateQuestionList = computed(() => {
|
|
|
- function parseQuestion(qs: Study.Question, parentIndex: number) {
|
|
|
|
|
|
|
+ function parseQuestion(qs: Study.Question) {
|
|
|
if (qs.subQuestions && qs.subQuestions.length > 0) {
|
|
if (qs.subQuestions && qs.subQuestions.length > 0) {
|
|
|
qs.subQuestions.forEach((item, index) => {
|
|
qs.subQuestions.forEach((item, index) => {
|
|
|
- // item.isSubQuestion = true;
|
|
|
|
|
- // item.parentId = qs.id;
|
|
|
|
|
- // item.parentTypeId = qs.typeId;
|
|
|
|
|
- // item.subIndex = index;
|
|
|
|
|
- // item.parentIndex = parentIndex;
|
|
|
|
|
item.isDone = isDone(item);
|
|
item.isDone = isDone(item);
|
|
|
});
|
|
});
|
|
|
} else {
|
|
} else {
|
|
@@ -85,13 +80,21 @@ export const useExam = () => {
|
|
|
}
|
|
}
|
|
|
console.log('重新计算')
|
|
console.log('重新计算')
|
|
|
return questionList.value.map((item, index) => {
|
|
return questionList.value.map((item, index) => {
|
|
|
- return parseQuestion(item, index)
|
|
|
|
|
|
|
+ return parseQuestion(item)
|
|
|
// return {
|
|
// return {
|
|
|
// ...item,
|
|
// ...item,
|
|
|
// // isDone: isDone(item)
|
|
// // isDone: isDone(item)
|
|
|
// };
|
|
// };
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
+ const flatQuestionList = computed(() => {
|
|
|
|
|
+ return questionList.value.flatMap(item => {
|
|
|
|
|
+ if (item.subQuestions && item.subQuestions.length > 0) {
|
|
|
|
|
+ return item.subQuestions.flat();
|
|
|
|
|
+ }
|
|
|
|
|
+ return item;
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
const groupedQuestionList = computed(() => {
|
|
const groupedQuestionList = computed(() => {
|
|
|
// 状态:已做、未做、是否不会、是否标记,整体按照题型分组
|
|
// 状态:已做、未做、是否不会、是否标记,整体按照题型分组
|
|
|
const state = questionTypeOrder.map(type => {
|
|
const state = questionTypeOrder.map(type => {
|
|
@@ -103,41 +106,30 @@ export const useExam = () => {
|
|
|
}[]
|
|
}[]
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- let offset = 0;
|
|
|
|
|
- function addQuestion(qs: Study.Question, index: number) {
|
|
|
|
|
- if (qs.subQuestions && qs.subQuestions.length > 0) {
|
|
|
|
|
- qs.subQuestions.forEach((subQs, subIndex) => {
|
|
|
|
|
- offset++;
|
|
|
|
|
- addQuestion(subQs, index + subIndex);
|
|
|
|
|
|
|
+ const arr: Study.Question[] = [];
|
|
|
|
|
+ flatQuestionList.value.forEach((qs, index) => {
|
|
|
|
|
+ let group;
|
|
|
|
|
+ if (qs.isSubQuestion) {
|
|
|
|
|
+ group = state.find(item => item.type === qs.parentTypeId);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ group = state.find(item => item.type === qs.typeId);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (group) {
|
|
|
|
|
+ group.list.push({
|
|
|
|
|
+ question: qs,
|
|
|
|
|
+ index
|
|
|
});
|
|
});
|
|
|
} else {
|
|
} else {
|
|
|
- let group;
|
|
|
|
|
- if (qs.isSubQuestion) {
|
|
|
|
|
- group = state.find(item => item.type === qs.parentTypeId);
|
|
|
|
|
- } else {
|
|
|
|
|
- group = state.find(item => item.type === qs.typeId);
|
|
|
|
|
- }
|
|
|
|
|
- if (group) {
|
|
|
|
|
- group.list.push({
|
|
|
|
|
|
|
+ state.push({
|
|
|
|
|
+ type: qs.typeId,
|
|
|
|
|
+ list: [{
|
|
|
question: qs,
|
|
question: qs,
|
|
|
index
|
|
index
|
|
|
- });
|
|
|
|
|
- } else {
|
|
|
|
|
- state.push({
|
|
|
|
|
- type: qs.typeId,
|
|
|
|
|
- list: [{
|
|
|
|
|
- question: qs,
|
|
|
|
|
- index
|
|
|
|
|
- }]
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }]
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- console.log(stateQuestionList.value.length)
|
|
|
|
|
- for (let i = 0; i <= stateQuestionList.value.length - 1; i++) {
|
|
|
|
|
- const qs = stateQuestionList.value[i];
|
|
|
|
|
- addQuestion(qs, i + offset);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ console.log('group data', arr)
|
|
|
return state;
|
|
return state;
|
|
|
});
|
|
});
|
|
|
const isAllDone = computed(() => {
|
|
const isAllDone = computed(() => {
|
|
@@ -301,11 +293,43 @@ export const useExam = () => {
|
|
|
examDuration.value = duration;
|
|
examDuration.value = duration;
|
|
|
practiceDuration.value = duration;
|
|
practiceDuration.value = duration;
|
|
|
}
|
|
}
|
|
|
|
|
+ const processArray = (arr: Study.Question[]) => {
|
|
|
|
|
+ let offset = 0;
|
|
|
|
|
+ return arr.map((item: Study.Question, index: number) => {
|
|
|
|
|
+ const result = {
|
|
|
|
|
+ ...item,
|
|
|
|
|
+ index: index
|
|
|
|
|
+ };
|
|
|
|
|
+ // 如果有子节点,处理子节点并计算subIndex
|
|
|
|
|
+ if (item.subQuestions && Array.isArray(item.subQuestions) && item.subQuestions.length > 0) {
|
|
|
|
|
+ // 为当前节点设置offset
|
|
|
|
|
+ result.offset = offset;
|
|
|
|
|
+ result.subQuestions = item.subQuestions.map((child, childIndex) => ({
|
|
|
|
|
+ ...child,
|
|
|
|
|
+ subIndex: childIndex,
|
|
|
|
|
+ isSubQuestion: true,
|
|
|
|
|
+ parentId: item.id,
|
|
|
|
|
+ parentTypeId: item.typeId,
|
|
|
|
|
+ parentIndex: index,
|
|
|
|
|
+ index: index,
|
|
|
|
|
+ virtualIndex: index + result.offset + childIndex
|
|
|
|
|
+ }));
|
|
|
|
|
+ // 更新offset,累加当前节点的子节点数量
|
|
|
|
|
+ offset += (item.subQuestions.length - 1);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 如果没有子节点,设置offset为当前累计值
|
|
|
|
|
+ result.offset = offset;
|
|
|
|
|
+ result.isSubQuestion = false;
|
|
|
|
|
+ result.virtualIndex = result.index + offset;
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
const setQuestionList = (list: Study.ExamineeQuestion[]) => {
|
|
const setQuestionList = (list: Study.ExamineeQuestion[]) => {
|
|
|
const orders = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
|
|
const orders = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
|
|
|
// 数据预处理
|
|
// 数据预处理
|
|
|
// 1、给每个项目补充额外字段
|
|
// 1、给每个项目补充额外字段
|
|
|
- const transerQuestion = (item: Study.ExamineeQuestion): Study.Question => {
|
|
|
|
|
|
|
+ const transerQuestion = (item: Study.ExamineeQuestion, index: number): Study.Question => {
|
|
|
return {
|
|
return {
|
|
|
...item,
|
|
...item,
|
|
|
// 处理没有题型的大题,统一作为阅读题
|
|
// 处理没有题型的大题,统一作为阅读题
|
|
@@ -321,28 +345,14 @@ export const useExam = () => {
|
|
|
} as Study.QuestionOption
|
|
} as Study.QuestionOption
|
|
|
}) || [],
|
|
}) || [],
|
|
|
isDone: false,
|
|
isDone: false,
|
|
|
- isCorrect: isQuestionCorrect(item)
|
|
|
|
|
|
|
+ isCorrect: isQuestionCorrect(item),
|
|
|
|
|
+ offset: 0,
|
|
|
|
|
+ index: index,
|
|
|
|
|
+ virtualIndex: 0
|
|
|
} as Study.Question
|
|
} as Study.Question
|
|
|
}
|
|
}
|
|
|
- const parseQuestion = (qs: Study.Question, parentIndex: number) => {
|
|
|
|
|
- if (qs.subQuestions && qs.subQuestions.length > 0) {
|
|
|
|
|
- qs.subQuestions.forEach((item, index) => {
|
|
|
|
|
- item.isSubQuestion = true;
|
|
|
|
|
- item.parentId = qs.id;
|
|
|
|
|
- item.parentTypeId = qs.typeId;
|
|
|
|
|
- item.subIndex = index;
|
|
|
|
|
- item.parentIndex = parentIndex;
|
|
|
|
|
- // item.isDone = isDone(item);
|
|
|
|
|
- });
|
|
|
|
|
- } else {
|
|
|
|
|
- qs.isSubQuestion = false;
|
|
|
|
|
- // qs.isDone = isDone(qs);
|
|
|
|
|
- }
|
|
|
|
|
- return qs;
|
|
|
|
|
- }
|
|
|
|
|
- const arr: Study.Question[] = list.map((item, index) => {
|
|
|
|
|
- return parseQuestion(transerQuestion(item), index);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ console.log(list.map((item, index) => transerQuestion(item, index)), 777)
|
|
|
|
|
+ const arr: Study.Question[] = processArray(list.map((item, index) => transerQuestion(item, index)));
|
|
|
questionList.value = arr;
|
|
questionList.value = arr;
|
|
|
}
|
|
}
|
|
|
const reset = () => {
|
|
const reset = () => {
|
|
@@ -370,6 +380,7 @@ export const useExam = () => {
|
|
|
interval = null;
|
|
interval = null;
|
|
|
}
|
|
}
|
|
|
const setSubQuestionIndex = (index: number) => {
|
|
const setSubQuestionIndex = (index: number) => {
|
|
|
|
|
+ console.log(index, 1000)
|
|
|
subQuestionIndex.value = index;
|
|
subQuestionIndex.value = index;
|
|
|
}
|
|
}
|
|
|
watch(() => currentIndex.value, (val) => {
|
|
watch(() => currentIndex.value, (val) => {
|
|
@@ -378,7 +389,13 @@ export const useExam = () => {
|
|
|
immediate: false
|
|
immediate: false
|
|
|
});
|
|
});
|
|
|
watch([() => currentIndex.value, () => subQuestionIndex.value], (val) => {
|
|
watch([() => currentIndex.value, () => subQuestionIndex.value], (val) => {
|
|
|
- virtualCurrentIndex.value = val[0] + val[1];
|
|
|
|
|
|
|
+ const qs = questionList.value[val[0]];
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ console.log(qs, val[1], 999)
|
|
|
|
|
+ console.log(11111, flatQuestionList.value[virtualCurrentIndex.value])
|
|
|
|
|
+ }, 500);
|
|
|
|
|
+ virtualCurrentIndex.value = qs.index + qs.offset + val[1];
|
|
|
|
|
+
|
|
|
}, {
|
|
}, {
|
|
|
immediate: false
|
|
immediate: false
|
|
|
});
|
|
});
|
|
@@ -386,6 +403,7 @@ export const useExam = () => {
|
|
|
questionList,
|
|
questionList,
|
|
|
groupedQuestionList,
|
|
groupedQuestionList,
|
|
|
stateQuestionList,
|
|
stateQuestionList,
|
|
|
|
|
+ flatQuestionList,
|
|
|
favoriteList,
|
|
favoriteList,
|
|
|
notKnowList,
|
|
notKnowList,
|
|
|
markList,
|
|
markList,
|