practice.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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 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 onStar = (item) =>
  91. new Promise((resolve) => {
  92. request(
  93. !item.is_favorite
  94. ? "api/question_bank/question_reception/topic/set_favorite"
  95. : "api/question_bank/question_reception/topic/cancel_favorite",
  96. {
  97. id: item.id,
  98. }
  99. ).then(() => {
  100. item.is_favorite = item.is_favorite ? 0 : 1;
  101. resolve(item.is_favorite);
  102. });
  103. });
  104. const lookReport = (d, s) => {
  105. data.value = d;
  106. showReport.value = true;
  107. const totalTime = Time.end();
  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. @nextPage="nextPage"
  136. @lookReport="lookReport"
  137. :onStar="onStar"
  138. :empty="!data.length"
  139. border
  140. v-if="!showReport && !showShare"
  141. />
  142. <Container
  143. bgColor="url('https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/7i6ROn34tZGe8QR4gaWDP1ZzyPYjqlvPgLLFRmIe.png')"
  144. bottomBorder
  145. v-else-if="!showShare && showReport"
  146. bottomBgColor="#fff"
  147. title="练习报告"
  148. >
  149. <view class="reslut">
  150. <div class="title-r">恭 喜 完 成 考 试</div>
  151. <view class="card">
  152. <view class="card-time">
  153. <view>{{ submitter.totalTime?.formatTime }}</view>
  154. <view>学习时长</view>
  155. </view>
  156. <view class="card-time">
  157. <view class="red">{{ correct.rate.toFixed(2) }}%</view>
  158. <view>正确率</view>
  159. </view>
  160. </view>
  161. <view class="template">
  162. <view class="header">
  163. <view>答题卡</view>
  164. <view class="right-error">
  165. <view class="right">答对({{ correct.right }})</view>
  166. <view class="error">答错({{ correct.error }})</view>
  167. </view>
  168. </view>
  169. <view class="group">
  170. <view
  171. class="item"
  172. :class="{
  173. right: it.isRight && it.showResult,
  174. error: !it.isRight && it.showResult && it.selectAns.length,
  175. }"
  176. v-for="(it, index) in data"
  177. :key="it.id"
  178. >{{ index + 1 }}</view
  179. >
  180. </view>
  181. </view>
  182. </view>
  183. <template #footer>
  184. <view class="footer">
  185. <view class="button plain" @click="showReport = false">答题解析</view>
  186. <view class="button" @click="showShare = true">炫耀一下</view>
  187. </view>
  188. </template>
  189. </Container>
  190. <ShareTemplate
  191. :onClose="() => (showShare = false)"
  192. :correct="correct"
  193. bg="https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/ix4wGk9h7Fb4c3d8hjkYjJP6VsPNbZgG3uDTUzxp.png"
  194. v-else
  195. />
  196. </template>
  197. <style lang="scss" scoped>
  198. @import "@/uni.scss";
  199. .template {
  200. padding: 15rpx;
  201. border-radius: 24rpx;
  202. background-color: #f8f9fb;
  203. }
  204. .red {
  205. color: #ff4444;
  206. }
  207. .title-r {
  208. display: flex;
  209. align-items: center;
  210. justify-content: center;
  211. font-weight: 500;
  212. font-size: 50rpx;
  213. color: #002fa7;
  214. }
  215. .card {
  216. display: flex;
  217. justify-content: center;
  218. align-items: center;
  219. gap: 63rpx;
  220. padding: 40rpx 50rpx;
  221. background-color: #f8f9fb;
  222. border-radius: 24rpx;
  223. &-time {
  224. font-family: PingFang SC, PingFang SC;
  225. font-weight: 500;
  226. font-size: 28rpx;
  227. color: #999999;
  228. display: flex;
  229. flex-direction: column;
  230. gap: 10rpx;
  231. align-items: center;
  232. }
  233. }
  234. .reslut {
  235. margin: 0 32rpx;
  236. padding: 24rpx;
  237. font-family: PingFang SC, PingFang SC;
  238. font-weight: 500;
  239. font-size: 28rpx;
  240. color: #333333;
  241. background: #fff;
  242. border-radius: 24rpx;
  243. display: flex;
  244. flex-direction: column;
  245. gap: 24rpx;
  246. .header {
  247. display: flex;
  248. justify-content: space-between;
  249. align-items: center;
  250. .right-error {
  251. display: flex;
  252. gap: 20rpx;
  253. font-weight: 400;
  254. font-size: 20rpx;
  255. color: #333333;
  256. @mixin type($color) {
  257. display: flex;
  258. align-items: center;
  259. gap: 10rpx;
  260. &::before {
  261. content: "";
  262. width: 16rpx;
  263. height: 16rpx;
  264. border-radius: 50%;
  265. display: block;
  266. background: $color;
  267. }
  268. }
  269. .right {
  270. @include type($success);
  271. }
  272. .error {
  273. @include type($error);
  274. }
  275. .not {
  276. @include type($default);
  277. }
  278. }
  279. }
  280. .group {
  281. display: grid;
  282. grid-template-columns: repeat(6, 1fr);
  283. gap: 20rpx;
  284. margin-top: 20rpx;
  285. .item {
  286. width: 72rpx;
  287. height: 72rpx;
  288. border-radius: 50%;
  289. display: flex;
  290. align-items: center;
  291. justify-content: center;
  292. background: $default;
  293. font-family: PingFang SC, PingFang SC;
  294. font-weight: 500;
  295. font-size: 28rpx;
  296. color: #ffffff;
  297. }
  298. .item.right {
  299. background: $success;
  300. }
  301. .item.error {
  302. background: $error;
  303. }
  304. }
  305. }
  306. .footer {
  307. display: flex;
  308. gap: 20rpx;
  309. align-items: center;
  310. padding-top: 20rpx;
  311. }
  312. </style>