practice.vue 8.1 KB

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