exam.vue 7.5 KB

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