exam.vue 8.7 KB

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