exam.vue 8.8 KB

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