exam.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. import ShareTemplate from "../../components/ShareTemplate/ShareTemplateExam.vue";
  9. const Time = useTimeStore();
  10. const TopicMapList = ["A", "B", "C", "D", "E"];
  11. const title = ref("");
  12. const total = ref(100000);
  13. const correct = ref({
  14. rate: 0, // 正确率
  15. error: 0, // 错误数
  16. right: 0, // 正确数
  17. not: 0, // 未答题
  18. total: 0, // 总题数
  19. });
  20. const showReport = ref(false);
  21. const showShare = ref(false);
  22. const submitter = ref({
  23. closeText: "直接退出",
  24. context: "您本次答题还未提交, 确定要退出答题吗?",
  25. isEndQuestion: false,
  26. text: "提交查看",
  27. totalTime: {
  28. formatTime: "00:00",
  29. totalTime: 0,
  30. },
  31. });
  32. const pageParams = ref({
  33. page: 1,
  34. limit: 999,
  35. });
  36. const data = ref([]);
  37. const real_topic_id = ref(0);
  38. const getList = async (params = {}) => {
  39. if (pageParams.value.page * pageParams.value.limit >= total.value) return;
  40. const t = await request(
  41. "api/question_bank/question_reception/real_topic/set_user_new_paper",
  42. {
  43. catalogue_id: getRoute().params.id,
  44. }
  45. );
  46. real_topic_id.value = t.data;
  47. const res = await request(
  48. "api/question_bank/question_reception/real_topic/get_real_topic",
  49. {
  50. ...params,
  51. catalogue_id: getRoute().params.id,
  52. real_topic_id: real_topic_id.value,
  53. }
  54. );
  55. total.value = res.data.total;
  56. data.value.push(
  57. ...res.data.data.map((item, ind) => {
  58. let questions = [];
  59. const ans = item.correct_answer.split(",");
  60. const ansList = [];
  61. for (let i = 0; i < item.question_count; i++) {
  62. const current = TopicMapList[i];
  63. if (ans.includes(current)) {
  64. ansList.push({
  65. label: current,
  66. value: i,
  67. });
  68. }
  69. const v =
  70. item[`select_${current.toLowerCase()}`].replace(/<br\s*\/?>/g, "") ||
  71. "";
  72. questions.push({
  73. label: v,
  74. value: current,
  75. checked: false,
  76. index: i,
  77. });
  78. }
  79. return {
  80. ...item,
  81. questions, // 题目
  82. ansList, // 正确答案
  83. selectAns: [], // 选择的答案
  84. showResult: false, // 是否展示答案
  85. isRight: false, // 是否正确
  86. isImage: item.title.includes("<img"),
  87. ind,
  88. };
  89. })
  90. );
  91. pageParams.value.page++;
  92. };
  93. const nextPage = (e) => {
  94. if (pageParams.value.page * pageParams.value.limit - e.index - 1 !== 1)
  95. return;
  96. getList(pageParams.value);
  97. };
  98. const lookReport = async (d, s) => {
  99. data.value = d;
  100. const totalTime = Time.end();
  101. // 提交试卷
  102. await request(
  103. "api/question_bank/question_reception/real_topic/user_submit_real_paper",
  104. {
  105. user_real_paper_id: real_topic_id.value,
  106. catalogue_id: getRoute().params.id,
  107. use_time: totalTime.totalTime,
  108. use_time_str: totalTime.formatTime,
  109. }
  110. );
  111. showReport.value = true;
  112. submitter.value = {
  113. ...s,
  114. totalTime,
  115. };
  116. const r = data.value.filter((item) => item.isRight).length;
  117. const n = data.value.filter((item) => !item.selectAns.length).length;
  118. correct.value = {
  119. rate: (r / total.value) * 100,
  120. right: r,
  121. error: total.value - r - n,
  122. not: n,
  123. total: total.value,
  124. };
  125. };
  126. onMounted(async () => {
  127. const params = getRoute().params;
  128. title.value = params.title;
  129. await getList(pageParams.value);
  130. Time.start();
  131. });
  132. </script>
  133. <template>
  134. <TopicExam
  135. :title="title"
  136. :total="total"
  137. mode="practice"
  138. :topics="data"
  139. @nextPage="nextPage"
  140. @lookReport="lookReport"
  141. :real_topic_id="real_topic_id"
  142. :empty="!data.length"
  143. border
  144. v-if="!showReport && !showShare"
  145. />
  146. <Container
  147. bgColor="url('https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/7i6ROn34tZGe8QR4gaWDP1ZzyPYjqlvPgLLFRmIe.png')"
  148. bottomBorder
  149. v-else-if="!showShare && showReport"
  150. bottomBgColor="#fff"
  151. title="练习报告"
  152. >
  153. <view class="reslut">
  154. <div class="title-r">恭 喜 完 成 本 课</div>
  155. <view class="card">
  156. <view class="card-time">
  157. <view>{{ submitter.totalTime?.formatTime }}</view>
  158. <view>学习时长</view>
  159. </view>
  160. <view class="card-time">
  161. <view class="red">{{ correct.rate.toFixed(2) }}%</view>
  162. <view>正确率</view>
  163. </view>
  164. <view class="card-time">
  165. <view class="red">{{ correct.right }}</view>
  166. <view>获得分数</view>
  167. </view>
  168. </view>
  169. <view class="template">
  170. <view class="header">
  171. <view>答题卡</view>
  172. <view class="right-error">
  173. <view class="right">答对({{ correct.right }})</view>
  174. <view class="error">答错({{ correct.error }})</view>
  175. <view class="not">未作({{ correct.not }})</view>
  176. </view>
  177. </view>
  178. <view class="group">
  179. <view
  180. class="item"
  181. :class="{
  182. right: it.isRight && it.showResult,
  183. error: !it.isRight && it.showResult && it.selectAns.length,
  184. }"
  185. v-for="(it, index) in data"
  186. :key="it.id"
  187. >{{ index + 1 }}</view
  188. >
  189. </view>
  190. </view>
  191. </view>
  192. <template #footer>
  193. <view class="footer">
  194. <view class="button plain" @click="showReport = false">答题解析</view>
  195. <view class="button" @click="showShare = true">炫耀一下</view>
  196. </view>
  197. </template>
  198. </Container>
  199. <ShareTemplate
  200. :onClose="() => (showShare = false)"
  201. :correct="correct"
  202. bg="https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/BxBKVS1eV1xaSylWq3i2UjE5VmiJfrfVT7Cc98m3.png"
  203. v-else
  204. />
  205. </template>
  206. <style lang="scss" scoped>
  207. @import "@/uni.scss";
  208. .template {
  209. padding: 15rpx;
  210. border-radius: 24rpx;
  211. background-color: #f8f9fb;
  212. }
  213. .red {
  214. color: #ff4444;
  215. }
  216. .title-r {
  217. display: flex;
  218. align-items: center;
  219. justify-content: center;
  220. font-weight: 500;
  221. font-size: 50rpx;
  222. color: #002fa7;
  223. }
  224. .card {
  225. display: flex;
  226. justify-content: space-between;
  227. align-items: center;
  228. padding: 40rpx 50rpx;
  229. background-color: #f8f9fb;
  230. border-radius: 24rpx;
  231. &-time {
  232. font-family: PingFang SC, PingFang SC;
  233. font-weight: 500;
  234. font-size: 28rpx;
  235. color: #999999;
  236. display: flex;
  237. flex-direction: column;
  238. gap: 10rpx;
  239. align-items: center;
  240. }
  241. }
  242. .reslut {
  243. margin: 0 32rpx;
  244. padding: 24rpx;
  245. font-family: PingFang SC, PingFang SC;
  246. font-weight: 500;
  247. font-size: 28rpx;
  248. color: #333333;
  249. background: #fff;
  250. border-radius: 24rpx;
  251. display: flex;
  252. flex-direction: column;
  253. gap: 24rpx;
  254. .header {
  255. display: flex;
  256. justify-content: space-between;
  257. align-items: center;
  258. .right-error {
  259. display: flex;
  260. gap: 20rpx;
  261. font-weight: 400;
  262. font-size: 20rpx;
  263. color: #333333;
  264. @mixin type($color) {
  265. display: flex;
  266. align-items: center;
  267. gap: 10rpx;
  268. &::before {
  269. content: "";
  270. width: 16rpx;
  271. height: 16rpx;
  272. border-radius: 50%;
  273. display: block;
  274. background: $color;
  275. }
  276. }
  277. .right {
  278. @include type($success);
  279. }
  280. .error {
  281. @include type($error);
  282. }
  283. .not {
  284. @include type($default);
  285. }
  286. }
  287. }
  288. .group {
  289. display: grid;
  290. grid-template-columns: repeat(6, 1fr);
  291. gap: 20rpx;
  292. margin-top: 20rpx;
  293. .item {
  294. width: 72rpx;
  295. height: 72rpx;
  296. border-radius: 50%;
  297. display: flex;
  298. align-items: center;
  299. justify-content: center;
  300. background: $default;
  301. font-family: PingFang SC, PingFang SC;
  302. font-weight: 500;
  303. font-size: 28rpx;
  304. color: #ffffff;
  305. }
  306. .item.right {
  307. background: $success;
  308. }
  309. .item.error {
  310. background: $error;
  311. }
  312. }
  313. }
  314. .footer {
  315. display: flex;
  316. gap: 20rpx;
  317. align-items: center;
  318. padding-top: 20rpx;
  319. }
  320. </style>