wrong-book.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <ie-page :safe-area-inset-bottom="false">
  3. <z-paging ref="paging" v-model="list" :auto="false" :safe-area-inset-bottom="true" :hide-no-more-by-limit="10"
  4. @query="handleQuery">
  5. <template #top>
  6. <ie-navbar title="错题本" />
  7. <uv-tabs :current="current" keyName="subjectName" :list="tabs" @change="handleTabChange" />
  8. <uv-line margin="0" />
  9. <date-time-picker v-model:start-date="startDate" v-model:end-date="endDate" @change="handleChange" />
  10. </template>
  11. <view v-for="item in list" :key="item.id">
  12. <question-book-item :data="item" :show-answer="true" @correct="handleCorrect"
  13. @toggleCollect="handleToggleCollect" @delete="handleDelete" />
  14. </view>
  15. </z-paging>
  16. <question-correct-popup ref="questionCorrectPopupRef" />
  17. </ie-page>
  18. </template>
  19. <script lang="ts" setup>
  20. import type { Study } from '@/types';
  21. import QuestionBookItem from '@/pagesStudy/components/question-book-item.vue';
  22. import QuestionCorrectPopup from '@/pagesStudy/pages/exam-start/components/question-correct-popup.vue';
  23. import DateTimePicker from '@/pagesStudy/pages/wrong-book/components/datetime-picker.vue';
  24. import { decodeHtmlEntities } from '@/composables/useExam';
  25. import { getStudentSubject, getWrongBookList } from '@/api/modules/study';
  26. import useQuestionBook from '@/composables/useQuestionBook';
  27. const list = ref<Study.FavoriteQuestionVO[]>([]);
  28. const paging = ref<ZPagingInstance>();
  29. const questionCorrectPopupRef = ref();
  30. const current = ref(0);
  31. const tabs = ref<Study.StudentSubject[]>([]);
  32. const startDate = ref('');
  33. const endDate = ref('');
  34. const { isOptionCorrect, isOptionSelected, cancelCollect, collect, deleteWrongQuestion } = useQuestionBook();
  35. const transfomeToQuestionBookVO = (list: Study.WrongBookQuestion[]): Study.FavoriteQuestionVO[] => {
  36. 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'];
  37. return list.map(item => {
  38. const originalOptions = [...item.options].filter(Boolean) as string[];
  39. const options: Study.QuestionOption[] = originalOptions.map((option, index) => {
  40. const cleanedOption = option.replace(/[A-Z]\./g, '').replace(/\s/g, ' ');
  41. return {
  42. name: decodeHtmlEntities(cleanedOption),
  43. no: orders[index],
  44. id: index,
  45. isAnswer: false,
  46. isCorrect: false,
  47. isSelected: false,
  48. isIncorrect: false,
  49. isMissed: false
  50. }
  51. });
  52. return {
  53. id: item.questionId,
  54. title: item.title,
  55. options: options,
  56. answers: item.answers,
  57. answer: decodeHtmlEntities(item.answer1 || ''),
  58. qtype: item.type,
  59. typeId: item.typeId,
  60. parse: decodeHtmlEntities(item.parse || ''),
  61. knowledge: decodeHtmlEntities(item.knowledge || ''),
  62. collect: item.collect || false
  63. }
  64. })
  65. }
  66. const handleQuery = (page: number, size: number) => {
  67. const queryParams: Study.WrongBookQuestionRequestDTO = {
  68. pageNum: page,
  69. pageSize: size,
  70. subjectId: tabs.value[current.value].subjectId,
  71. start: startDate.value,
  72. end: endDate.value
  73. }
  74. getWrongBookList(queryParams).then(res => {
  75. const data = transfomeToQuestionBookVO(res.rows);
  76. data.forEach(qs => {
  77. qs.options.forEach(option => {
  78. option.isCorrect = isOptionCorrect(qs, option);
  79. option.isSelected = isOptionSelected(qs, option);
  80. option.isMissed = !option.isSelected && option.isCorrect;
  81. option.isIncorrect = !option.isCorrect && option.isSelected;
  82. });
  83. });
  84. paging.value?.completeByTotal(data, res.total);
  85. });
  86. };
  87. const handleCorrect = (question: Study.FavoriteQuestionVO) => {
  88. questionCorrectPopupRef.value.open(question.id);
  89. }
  90. const handleToggleCollect = (question: Study.FavoriteQuestionVO) => {
  91. if (question.collect) {
  92. cancelCollect(question.id).then(res => {
  93. if (res) {
  94. paging.value?.refresh();
  95. }
  96. });
  97. } else {
  98. collect(question.id).then(res => {
  99. if (res) {
  100. paging.value?.refresh();
  101. }
  102. });
  103. }
  104. }
  105. const handleDelete = (question: Study.FavoriteQuestionVO) => {
  106. deleteWrongQuestion(question.id).then(res => {
  107. if (res) {
  108. paging.value?.reload();
  109. }
  110. });
  111. }
  112. const handleTabChange = (e: any) => {
  113. current.value = e.index;
  114. paging.value?.reload();
  115. }
  116. const handleChange = (e: any) => {
  117. paging.value?.reload();
  118. }
  119. const loadData = () => {
  120. getStudentSubject().then(res => {
  121. tabs.value = res.data;
  122. setTimeout(() => {
  123. paging.value?.reload();
  124. }, 0);
  125. });
  126. }
  127. onMounted(() => {
  128. loadData();
  129. });
  130. </script>
  131. <style lang="scss"></style>