favorite.vue 4.6 KB

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