rightPractice.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <script setup name="Exam">
  2. import TopicPractice from "../../components/Topic/TopicPracticeEnd.vue";
  3. import { ref, onMounted } from "vue";
  4. import { getRoute, router } from "../../utils/router";
  5. import { request } from "../../utils/request";
  6. const TopicMapList = ["A", "B", "C", "D", "E"];
  7. const title = ref("");
  8. const total = ref(0);
  9. const data = ref([]);
  10. const user_exercise_paper_id = ref(0);
  11. const getList = async (params) => {
  12. const res = await request(
  13. "api/question_bank/question_reception/study_book/get_answer_topic_record",
  14. {
  15. chapter_id: params.catalogue_id,
  16. is_correct: Number(params.isRight),
  17. }
  18. );
  19. total.value = res.data.total;
  20. data.value.push(
  21. ...res.data.data.map((item, ind) => {
  22. const selectAns = Number(params.isRight) ? item.answer.split(",") : [];
  23. let questions = [];
  24. const ans = item.correct_answer.split(",");
  25. const ansList = [];
  26. for (let i = 0; i < item.question_count; i++) {
  27. const current = TopicMapList[i];
  28. if (ans.includes(current)) {
  29. ansList.push({
  30. label: current,
  31. value: i,
  32. });
  33. }
  34. const v =
  35. item[`select_${current.toLowerCase()}`].replace(/<br\s*\/?>/g, "") ||
  36. "";
  37. questions.push({
  38. label: v,
  39. value: current,
  40. checked: selectAns.includes(current),
  41. isRight: ans.includes(current),
  42. index: i,
  43. });
  44. }
  45. return {
  46. ...item,
  47. questions, // 题目
  48. ansList, // 正确答案
  49. selectAns: selectAns.map((i) => ({ value: i, label: i })), // 选择的答案
  50. showResult: !!Number(params.isRight), // 是否展示答案
  51. isRight: !!Number(params.isRight), // 是否正确
  52. isImage: item.title.includes("<img"),
  53. ind,
  54. };
  55. })
  56. );
  57. };
  58. const lookReport = () => {
  59. router.back();
  60. };
  61. const onStar = (item) =>
  62. new Promise((resolve) => {
  63. request(
  64. !item.is_favorite
  65. ? "api/question_bank/question_reception/topic/set_favorite"
  66. : "api/question_bank/question_reception/topic/cancel_favorite",
  67. {
  68. id: item.id,
  69. chapter_id: getRoute().params.id,
  70. user_exercise_paper_id: user_exercise_paper_id.value,
  71. }
  72. ).then(() => {
  73. item.is_favorite = item.is_favorite ? 0 : 1;
  74. resolve(item.is_favorite);
  75. });
  76. });
  77. onMounted(() => {
  78. const params = getRoute().params;
  79. title.value = params.title;
  80. getList(params);
  81. });
  82. </script>
  83. <template>
  84. <TopicPractice
  85. :title="title"
  86. :total="total"
  87. :topics="data"
  88. :user_exercise_paper_id="user_exercise_paper_id"
  89. :onStar="onStar"
  90. :empty="!data.length"
  91. @lookReport="lookReport"
  92. text="加载中···"
  93. border
  94. />
  95. </template>
  96. <style lang="scss" scoped>
  97. @import "@/uni.scss";
  98. .template {
  99. padding: 15rpx;
  100. border-radius: 24rpx;
  101. background-color: #f8f9fb;
  102. }
  103. .red {
  104. color: #ff4444;
  105. }
  106. .title-r {
  107. display: flex;
  108. align-items: center;
  109. justify-content: center;
  110. font-weight: 500;
  111. font-size: 50rpx;
  112. color: #002fa7;
  113. }
  114. .card {
  115. display: flex;
  116. justify-content: center;
  117. align-items: center;
  118. gap: 63rpx;
  119. padding: 40rpx 50rpx;
  120. background-color: #f8f9fb;
  121. border-radius: 24rpx;
  122. &-time {
  123. font-family: PingFang SC, PingFang SC;
  124. font-weight: 500;
  125. font-size: 28rpx;
  126. color: #999999;
  127. display: flex;
  128. flex-direction: column;
  129. gap: 10rpx;
  130. align-items: center;
  131. }
  132. }
  133. .reslut {
  134. margin: 0 32rpx;
  135. padding: 24rpx;
  136. font-family: PingFang SC, PingFang SC;
  137. font-weight: 500;
  138. font-size: 28rpx;
  139. color: #333333;
  140. background: #fff;
  141. border-radius: 24rpx;
  142. display: flex;
  143. flex-direction: column;
  144. gap: 24rpx;
  145. .header {
  146. display: flex;
  147. justify-content: space-between;
  148. align-items: center;
  149. .right-error {
  150. display: flex;
  151. gap: 20rpx;
  152. font-weight: 400;
  153. font-size: 20rpx;
  154. color: #333333;
  155. @mixin type($color) {
  156. display: flex;
  157. align-items: center;
  158. gap: 10rpx;
  159. &::before {
  160. content: "";
  161. width: 16rpx;
  162. height: 16rpx;
  163. border-radius: 50%;
  164. display: block;
  165. background: $color;
  166. }
  167. }
  168. .right {
  169. @include type($success);
  170. }
  171. .error {
  172. @include type($error);
  173. }
  174. .not {
  175. @include type($default);
  176. }
  177. }
  178. }
  179. .group {
  180. display: grid;
  181. grid-template-columns: repeat(6, 1fr);
  182. gap: 20rpx;
  183. margin-top: 20rpx;
  184. .item {
  185. width: 72rpx;
  186. height: 72rpx;
  187. border-radius: 50%;
  188. display: flex;
  189. align-items: center;
  190. justify-content: center;
  191. background: $default;
  192. font-family: PingFang SC, PingFang SC;
  193. font-weight: 500;
  194. font-size: 28rpx;
  195. color: #ffffff;
  196. }
  197. .item.right {
  198. background: $success;
  199. }
  200. .item.error {
  201. background: $error;
  202. }
  203. }
  204. }
  205. .footer {
  206. display: flex;
  207. gap: 20rpx;
  208. align-items: center;
  209. padding-top: 20rpx;
  210. }
  211. </style>