dayPractice.vue 7.8 KB

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