exam.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <script setup name="Exam">
  2. import TopicExam from "../../components/Topic/TopicExam.vue";
  3. import { ref, onMounted } from "vue";
  4. import { getRoute, router } 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
  162. class="button"
  163. @click="
  164. router.push({
  165. url: '/pages/real/shareExam',
  166. params: {
  167. correct,
  168. },
  169. })
  170. "
  171. >炫耀一下</view
  172. >
  173. </view>
  174. </template>
  175. </Container>
  176. </template>
  177. <style lang="scss" scoped>
  178. @import "@/uni.scss";
  179. .card {
  180. display: flex;
  181. justify-content: space-between;
  182. align-items: center;
  183. padding: 40rpx 50rpx;
  184. &-time {
  185. font-family: PingFang SC, PingFang SC;
  186. font-weight: 500;
  187. font-size: 28rpx;
  188. color: #999999;
  189. display: flex;
  190. flex-direction: column;
  191. gap: 10rpx;
  192. align-items: center;
  193. }
  194. }
  195. .reslut {
  196. margin: 0 30rpx;
  197. padding: 20rpx 50rpx;
  198. font-family: PingFang SC, PingFang SC;
  199. font-weight: 500;
  200. font-size: 28rpx;
  201. color: #333333;
  202. background: #fff;
  203. border-radius: 10rpx;
  204. .header {
  205. display: flex;
  206. justify-content: space-between;
  207. align-items: center;
  208. .right-error {
  209. display: flex;
  210. gap: 20rpx;
  211. font-weight: 400;
  212. font-size: 20rpx;
  213. color: #333333;
  214. @mixin type($color) {
  215. display: flex;
  216. align-items: center;
  217. gap: 10rpx;
  218. &::before {
  219. content: "";
  220. width: 16rpx;
  221. height: 16rpx;
  222. border-radius: 50%;
  223. display: block;
  224. background: $color;
  225. }
  226. }
  227. .right {
  228. @include type($success);
  229. }
  230. .error {
  231. @include type($error);
  232. }
  233. .not {
  234. @include type($default);
  235. }
  236. }
  237. }
  238. .group {
  239. display: grid;
  240. grid-template-columns: repeat(6, 1fr);
  241. gap: 20rpx;
  242. margin-top: 20rpx;
  243. .item {
  244. width: 72rpx;
  245. height: 72rpx;
  246. border-radius: 50%;
  247. display: flex;
  248. align-items: center;
  249. justify-content: center;
  250. background: $default;
  251. font-family: PingFang SC, PingFang SC;
  252. font-weight: 500;
  253. font-size: 28rpx;
  254. color: #ffffff;
  255. }
  256. .item.right {
  257. background: $success;
  258. }
  259. .item.error {
  260. background: $error;
  261. }
  262. }
  263. }
  264. .footer {
  265. display: flex;
  266. gap: 20rpx;
  267. align-items: center;
  268. padding-top: 20rpx;
  269. }
  270. </style>