exam.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <script setup name="Exam">
  2. import TopicExam from "../../components/Topic/TopicExam.vue";
  3. import { ref, onMounted } from "vue";
  4. import { getRoute } from "../../utils/router";
  5. import { request } from "../../utils/request";
  6. import { useTimeStore } from "@/store/time";
  7. import Container from "../../components/Container/Container.vue";
  8. const Time = useTimeStore();
  9. const TopicMapList = ["A", "B", "C", "D", "E"];
  10. const title = ref("");
  11. const total = ref(100000);
  12. const correct = ref({
  13. rate: 0, // 正确率
  14. error: 0, // 错误数
  15. right: 0, // 正确数
  16. not: 0, // 未答题
  17. });
  18. const showReport = ref(false);
  19. const submitter = ref({
  20. closeText: "直接退出",
  21. context: "您本次答题还未提交, 确定要退出答题吗?",
  22. isEndQuestion: false,
  23. text: "提交查看",
  24. totalTime: {
  25. formatTime: "00:03",
  26. totalTime: 2892,
  27. },
  28. });
  29. const pageParams = ref({
  30. page: 1,
  31. limit: 999,
  32. });
  33. const data = ref([]);
  34. const getList = async (params) => {
  35. if (pageParams.value.page * pageParams.value.limit >= total.value) return;
  36. const res = await request(
  37. "api/question_bank/question_reception/topic/get_chapter_topic",
  38. {
  39. ...params,
  40. id: getRoute().params.id,
  41. }
  42. );
  43. total.value = res.data.total;
  44. data.value.push(
  45. ...res.data.data.map((item) => {
  46. let questions = [];
  47. const ans = item.correct_answer.split(",");
  48. const ansList = [];
  49. for (let i = 0; i < item.question_count; i++) {
  50. const current = TopicMapList[i];
  51. if (ans.includes(current)) {
  52. ansList.push({
  53. label: current,
  54. value: i,
  55. });
  56. }
  57. const v =
  58. item[`select_${current.toLowerCase()}`].replace(/<br\s*\/?>/g, "") ||
  59. "";
  60. questions.push({
  61. label: v,
  62. value: current,
  63. checked: false,
  64. index: i,
  65. });
  66. }
  67. return {
  68. ...item,
  69. questions, // 题目
  70. ansList, // 正确答案
  71. selectAns: [], // 选择的答案
  72. showResult: false, // 是否展示答案
  73. isRight: false, // 是否正确
  74. isImage: item.title.includes("<img"),
  75. };
  76. })
  77. );
  78. pageParams.value.page++;
  79. };
  80. const nextPage = (e) => {
  81. if (pageParams.value.page * pageParams.value.limit - e.index - 1 !== 1)
  82. return;
  83. getList(pageParams.value);
  84. };
  85. const lookReport = (d, s) => {
  86. data.value = d;
  87. showReport.value = true;
  88. const totalTime = Time.end();
  89. submitter.value = {
  90. ...s,
  91. totalTime,
  92. };
  93. const r = data.value.filter((item) => item.isRight).length;
  94. const n = data.value.filter((item) => !item.showResult).length;
  95. correct.value = {
  96. rate: (r / total.value) * 100,
  97. right: r,
  98. error: total.value - r - n,
  99. not: n,
  100. };
  101. };
  102. onMounted(() => {
  103. Time.start();
  104. const params = getRoute().params;
  105. title.value = params.title;
  106. getList(pageParams.value);
  107. });
  108. </script>
  109. <template>
  110. <TopicExam
  111. :title="title"
  112. :total="total"
  113. mode="practice"
  114. :topics="data"
  115. @nextPage="nextPage"
  116. @lookReport="lookReport"
  117. border
  118. v-if="!showReport"
  119. />
  120. <Container v-else title="练习报告">
  121. <uni-card>
  122. <view class="card">
  123. <view class="card-time">
  124. <view>{{ submitter.totalTime?.formatTime }}</view>
  125. <view>学习时长</view>
  126. </view>
  127. <view class="card-time">
  128. <view>{{ correct.rate.toFixed(2) }}%</view>
  129. <view>正确率</view>
  130. </view>
  131. </view>
  132. </uni-card>
  133. <view class="reslut">
  134. <view class="header">
  135. <view>答题卡</view>
  136. <view class="right-error">
  137. <view class="right">答对({{ correct.right }})</view>
  138. <view class="error">答错({{ correct.error }})</view>
  139. <view class="not">未作({{ correct.not }})</view>
  140. </view>
  141. </view>
  142. <view class="group">
  143. <view
  144. class="item"
  145. :class="{
  146. right: it.isRight && it.showResult,
  147. error: !it.isRight && it.showResult,
  148. }"
  149. v-for="(it, index) in data"
  150. :key="it.id"
  151. >{{ index + 1 }}</view
  152. >
  153. </view>
  154. </view>
  155. <template #footer>
  156. <view class="footer">
  157. <view class="button plain">答题解析</view>
  158. <view class="button">炫耀一下</view>
  159. </view>
  160. </template>
  161. </Container>
  162. </template>
  163. <style lang="scss" scoped>
  164. @import "@/uni.scss";
  165. .card {
  166. display: flex;
  167. justify-content: space-between;
  168. align-items: center;
  169. padding: 40rpx 50rpx;
  170. &-time {
  171. font-family: PingFang SC, PingFang SC;
  172. font-weight: 500;
  173. font-size: 28rpx;
  174. color: #999999;
  175. display: flex;
  176. flex-direction: column;
  177. gap: 10rpx;
  178. align-items: center;
  179. }
  180. }
  181. .reslut {
  182. margin: 0 30rpx;
  183. padding: 20rpx 50rpx;
  184. font-family: PingFang SC, PingFang SC;
  185. font-weight: 500;
  186. font-size: 28rpx;
  187. color: #333333;
  188. background: #fff;
  189. border-radius: 10rpx;
  190. .header {
  191. display: flex;
  192. justify-content: space-between;
  193. align-items: center;
  194. .right-error {
  195. display: flex;
  196. gap: 20rpx;
  197. font-weight: 400;
  198. font-size: 20rpx;
  199. color: #333333;
  200. @mixin type($color) {
  201. display: flex;
  202. align-items: center;
  203. gap: 10rpx;
  204. &::before {
  205. content: "";
  206. width: 16rpx;
  207. height: 16rpx;
  208. border-radius: 50%;
  209. display: block;
  210. background: $color;
  211. }
  212. }
  213. .right {
  214. @include type($success);
  215. }
  216. .error {
  217. @include type($error);
  218. }
  219. .not {
  220. @include type($default);
  221. }
  222. }
  223. }
  224. .group {
  225. display: grid;
  226. grid-template-columns: repeat(6, 1fr);
  227. gap: 20rpx;
  228. margin-top: 20rpx;
  229. .item {
  230. width: 72rpx;
  231. height: 72rpx;
  232. border-radius: 50%;
  233. display: flex;
  234. align-items: center;
  235. justify-content: center;
  236. background: $default;
  237. font-family: PingFang SC, PingFang SC;
  238. font-weight: 500;
  239. font-size: 28rpx;
  240. color: #ffffff;
  241. }
  242. .item.right {
  243. background: $success;
  244. }
  245. .item.error {
  246. background: $error;
  247. }
  248. }
  249. }
  250. .footer {
  251. display: flex;
  252. gap: 20rpx;
  253. align-items: center;
  254. padding-top: 20rpx;
  255. }
  256. </style>