exam.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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:00",
  26. totalTime: 0,
  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
  124. bgColor="url('https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/7i6ROn34tZGe8QR4gaWDP1ZzyPYjqlvPgLLFRmIe.png')"
  125. bottomBorder
  126. v-else
  127. bottomBgColor="#fff"
  128. title="练习报告"
  129. >
  130. <view class="reslut">
  131. <div class="title-r">恭 喜 完 成 本 课</div>
  132. <view class="card">
  133. <view class="card-time">
  134. <view>{{ submitter.totalTime?.formatTime }}</view>
  135. <view>学习时长</view>
  136. </view>
  137. <view class="card-time">
  138. <view class="red">{{ correct.rate.toFixed(2) }}%</view>
  139. <view>正确率</view>
  140. </view>
  141. <view class="card-time">
  142. <view class="red">{{ correct.right }}</view>
  143. <view>获得分数</view>
  144. </view>
  145. </view>
  146. <view class="template">
  147. <view class="header">
  148. <view>答题卡</view>
  149. <view class="right-error">
  150. <view class="right">答对({{ correct.right }})</view>
  151. <view class="error">答错({{ correct.error }})</view>
  152. <view class="not">未作({{ correct.not }})</view>
  153. </view>
  154. </view>
  155. <view class="group">
  156. <view
  157. class="item"
  158. :class="{
  159. right: it.isRight && it.showResult,
  160. error: !it.isRight && it.showResult && it.selectAns.length,
  161. }"
  162. v-for="(it, index) in data"
  163. :key="it.id"
  164. >{{ index + 1 }}</view
  165. >
  166. </view>
  167. </view>
  168. </view>
  169. <template #footer>
  170. <view class="footer">
  171. <view class="button plain" @click="showReport = false">答题解析</view>
  172. <view
  173. class="button"
  174. @click="
  175. router.push({
  176. url: '/pages/real/sharePractice',
  177. params: {
  178. correct,
  179. },
  180. })
  181. "
  182. >炫耀一下</view
  183. >
  184. </view>
  185. </template>
  186. </Container>
  187. </template>
  188. <style lang="scss" scoped>
  189. @import "@/uni.scss";
  190. .template {
  191. padding: 15rpx;
  192. border-radius: 24rpx;
  193. background-color: #f8f9fb;
  194. }
  195. .red {
  196. color: #ff4444;
  197. }
  198. .title-r {
  199. display: flex;
  200. align-items: center;
  201. justify-content: center;
  202. font-weight: 500;
  203. font-size: 50rpx;
  204. color: #002FA7;
  205. }
  206. .card {
  207. display: flex;
  208. justify-content: space-between;
  209. align-items: center;
  210. padding: 40rpx 50rpx;
  211. background-color: #f8f9fb;
  212. border-radius: 24rpx;
  213. &-time {
  214. font-family: PingFang SC, PingFang SC;
  215. font-weight: 500;
  216. font-size: 28rpx;
  217. color: #999999;
  218. display: flex;
  219. flex-direction: column;
  220. gap: 10rpx;
  221. align-items: center;
  222. }
  223. }
  224. .reslut {
  225. margin: 0 32rpx;
  226. padding: 24rpx;
  227. font-family: PingFang SC, PingFang SC;
  228. font-weight: 500;
  229. font-size: 28rpx;
  230. color: #333333;
  231. background: #fff;
  232. border-radius: 24rpx;
  233. display: flex;
  234. flex-direction: column;
  235. gap: 24rpx;
  236. .header {
  237. display: flex;
  238. justify-content: space-between;
  239. align-items: center;
  240. .right-error {
  241. display: flex;
  242. gap: 20rpx;
  243. font-weight: 400;
  244. font-size: 20rpx;
  245. color: #333333;
  246. @mixin type($color) {
  247. display: flex;
  248. align-items: center;
  249. gap: 10rpx;
  250. &::before {
  251. content: "";
  252. width: 16rpx;
  253. height: 16rpx;
  254. border-radius: 50%;
  255. display: block;
  256. background: $color;
  257. }
  258. }
  259. .right {
  260. @include type($success);
  261. }
  262. .error {
  263. @include type($error);
  264. }
  265. .not {
  266. @include type($default);
  267. }
  268. }
  269. }
  270. .group {
  271. display: grid;
  272. grid-template-columns: repeat(6, 1fr);
  273. gap: 20rpx;
  274. margin-top: 20rpx;
  275. .item {
  276. width: 72rpx;
  277. height: 72rpx;
  278. border-radius: 50%;
  279. display: flex;
  280. align-items: center;
  281. justify-content: center;
  282. background: $default;
  283. font-family: PingFang SC, PingFang SC;
  284. font-weight: 500;
  285. font-size: 28rpx;
  286. color: #ffffff;
  287. }
  288. .item.right {
  289. background: $success;
  290. }
  291. .item.error {
  292. background: $error;
  293. }
  294. }
  295. }
  296. .footer {
  297. display: flex;
  298. gap: 20rpx;
  299. align-items: center;
  300. padding-top: 20rpx;
  301. }
  302. </style>