practice.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <script setup name="Exam">
  2. import TopicPractice from "../../components/Topic/TopicPractice.vue";
  3. import { ref, onMounted } from "vue";
  4. import { getRoute, router } 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 user_exercise_paper_id = ref(0);
  38. const getList = async (params) => {
  39. if (pageParams.value.page * pageParams.value.limit >= total.value) return;
  40. const i = await request(
  41. "api/question_bank/question_reception/topic/get_user_exercise_paper"
  42. );
  43. if (!i.data) {
  44. const r = await request(
  45. "api/question_bank/question_reception/topic/set_user_new_exercise_paper",
  46. {
  47. chapter_id: getRoute().params.id,
  48. }
  49. );
  50. user_exercise_paper_id.value = r.data;
  51. } else {
  52. user_exercise_paper_id.value = i.data;
  53. }
  54. const res = await request(
  55. "api/question_bank/question_reception/topic/get_chapter_topic",
  56. {
  57. ...params,
  58. id: getRoute().params.id,
  59. user_exercise_paper_id: user_exercise_paper_id.value,
  60. }
  61. );
  62. total.value = res.data.total;
  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: [], // 选择的答案
  91. showResult: false, // 是否展示答案
  92. isRight: false, // 是否正确
  93. isImage: item.title.includes("<img"),
  94. ind,
  95. };
  96. })
  97. );
  98. pageParams.value.page++;
  99. };
  100. const nextPage = (e) => {
  101. if (pageParams.value.page * pageParams.value.limit - e.index - 1 !== 1)
  102. return;
  103. getList(pageParams.value);
  104. };
  105. const onStar = (item) =>
  106. new Promise((resolve) => {
  107. request(
  108. !item.is_favorite
  109. ? "api/question_bank/question_reception/topic/set_favorite"
  110. : "api/question_bank/question_reception/topic/cancel_favorite",
  111. {
  112. id: item.id,
  113. }
  114. ).then(() => {
  115. item.is_favorite = item.is_favorite ? 0 : 1;
  116. resolve(item.is_favorite);
  117. });
  118. });
  119. const lookReport = async (d, s) => {
  120. data.value = d;
  121. const totalTime = Time.end();
  122. await request(
  123. "api/question_bank/question_reception/topic/user_submit_exercise_paper",
  124. {
  125. user_exercise_paper_id: user_exercise_paper_id.value,
  126. chapter_id: getRoute().params.id,
  127. }
  128. );
  129. showReport.value = true;
  130. submitter.value = {
  131. ...s,
  132. totalTime,
  133. };
  134. const r = data.value.filter((item) => item.isRight).length;
  135. const n = data.value.filter((item) => !item.selectAns.length).length;
  136. correct.value = {
  137. rate: (r / total.value) * 100,
  138. right: r,
  139. error: total.value - r - n,
  140. not: n,
  141. total: total.value,
  142. };
  143. };
  144. onMounted(() => {
  145. Time.start();
  146. const params = getRoute().params;
  147. title.value = params.title;
  148. getList(pageParams.value);
  149. });
  150. </script>
  151. <template>
  152. <TopicPractice
  153. :title="title"
  154. :total="total"
  155. mode="practice"
  156. :topics="data"
  157. :user_exercise_paper_id="user_exercise_paper_id"
  158. @nextPage="nextPage"
  159. @lookReport="lookReport"
  160. :onStar="onStar"
  161. :empty="!data.length"
  162. border
  163. v-if="!showReport && !showShare"
  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>{{ submitter.totalTime?.formatTime }}</view>
  177. <view>学习时长</view>
  178. </view>
  179. <view class="card-time">
  180. <view class="red">{{ correct.rate.toFixed(2) }}%</view>
  181. <view>正确率</view>
  182. </view>
  183. </view>
  184. <view class="template">
  185. <view class="header">
  186. <view>答题卡</view>
  187. <view class="right-error">
  188. <view class="right">答对({{ correct.right }})</view>
  189. <view class="error">答错({{ correct.error }})</view>
  190. </view>
  191. </view>
  192. <view class="group">
  193. <view
  194. class="item"
  195. :class="{
  196. right: it.isRight && it.showResult,
  197. error: !it.isRight && it.showResult && it.selectAns.length,
  198. }"
  199. v-for="(it, index) in data"
  200. :key="it.id"
  201. >{{ index + 1 }}</view
  202. >
  203. </view>
  204. </view>
  205. </view>
  206. <template #footer>
  207. <view class="footer">
  208. <view class="button plain" @click="showReport = false">答题解析</view>
  209. <view class="button" @click="showShare = true">炫耀一下</view>
  210. </view>
  211. </template>
  212. </Container>
  213. <ShareTemplate
  214. :onClose="() => (showShare = false)"
  215. :correct="correct"
  216. bg="https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/ix4wGk9h7Fb4c3d8hjkYjJP6VsPNbZgG3uDTUzxp.png"
  217. v-else
  218. />
  219. </template>
  220. <style lang="scss" scoped>
  221. @import "@/uni.scss";
  222. .template {
  223. padding: 15rpx;
  224. border-radius: 24rpx;
  225. background-color: #f8f9fb;
  226. }
  227. .red {
  228. color: #ff4444;
  229. }
  230. .title-r {
  231. display: flex;
  232. align-items: center;
  233. justify-content: center;
  234. font-weight: 500;
  235. font-size: 50rpx;
  236. color: #002fa7;
  237. }
  238. .card {
  239. display: flex;
  240. justify-content: center;
  241. align-items: center;
  242. gap: 63rpx;
  243. padding: 40rpx 50rpx;
  244. background-color: #f8f9fb;
  245. border-radius: 24rpx;
  246. &-time {
  247. font-family: PingFang SC, PingFang SC;
  248. font-weight: 500;
  249. font-size: 28rpx;
  250. color: #999999;
  251. display: flex;
  252. flex-direction: column;
  253. gap: 10rpx;
  254. align-items: center;
  255. }
  256. }
  257. .reslut {
  258. margin: 0 32rpx;
  259. padding: 24rpx;
  260. font-family: PingFang SC, PingFang SC;
  261. font-weight: 500;
  262. font-size: 28rpx;
  263. color: #333333;
  264. background: #fff;
  265. border-radius: 24rpx;
  266. display: flex;
  267. flex-direction: column;
  268. gap: 24rpx;
  269. .header {
  270. display: flex;
  271. justify-content: space-between;
  272. align-items: center;
  273. .right-error {
  274. display: flex;
  275. gap: 20rpx;
  276. font-weight: 400;
  277. font-size: 20rpx;
  278. color: #333333;
  279. @mixin type($color) {
  280. display: flex;
  281. align-items: center;
  282. gap: 10rpx;
  283. &::before {
  284. content: "";
  285. width: 16rpx;
  286. height: 16rpx;
  287. border-radius: 50%;
  288. display: block;
  289. background: $color;
  290. }
  291. }
  292. .right {
  293. @include type($success);
  294. }
  295. .error {
  296. @include type($error);
  297. }
  298. .not {
  299. @include type($default);
  300. }
  301. }
  302. }
  303. .group {
  304. display: grid;
  305. grid-template-columns: repeat(6, 1fr);
  306. gap: 20rpx;
  307. margin-top: 20rpx;
  308. .item {
  309. width: 72rpx;
  310. height: 72rpx;
  311. border-radius: 50%;
  312. display: flex;
  313. align-items: center;
  314. justify-content: center;
  315. background: $default;
  316. font-family: PingFang SC, PingFang SC;
  317. font-weight: 500;
  318. font-size: 28rpx;
  319. color: #ffffff;
  320. }
  321. .item.right {
  322. background: $success;
  323. }
  324. .item.error {
  325. background: $error;
  326. }
  327. }
  328. }
  329. .footer {
  330. display: flex;
  331. gap: 20rpx;
  332. align-items: center;
  333. padding-top: 20rpx;
  334. }
  335. </style>