exam.vue 8.6 KB

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