exam.vue 8.1 KB

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