exam.vue 6.2 KB

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