Nav apraksta

result.vue 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <script lang="ts" setup>
  2. import { onMounted, ref } from 'vue';
  3. import { useRoute } from 'vue-router';
  4. // // @ts-ignore
  5. // import { useVbenModal } from '@vben/common-ui';
  6. // @ts-ignore
  7. import { Page, useVbenModal } from '@vben/common-ui';
  8. import { CircleCheckFilled, CircleCloseFilled } from '@element-plus/icons-vue';
  9. // @ts-ignore
  10. import { getAnswerResult } from '#/api/exam/exam/answer';
  11. // @ts-ignore
  12. import { examPaperDetail } from '#/api/exam/exam/exam';
  13. // @ts-ignore
  14. import { getParticipantById } from '#/api/exam/exam/participant';
  15. import knowledgemain from '#/components/knowledgemain/index.vue';
  16. const route = useRoute();
  17. const examId = Number(route.params.id || 0);
  18. const pid = Number(route.query.pid || 0);
  19. const participantInfo = ref<any>({});
  20. // 考试信息
  21. const examInfo = ref<any>({});
  22. // 答题信息
  23. const answerInfo = ref<any>([]);
  24. onMounted(() => {
  25. getParticipantById(pid).then((res: any) => {
  26. participantInfo.value = res || {};
  27. });
  28. });
  29. // 计算用时
  30. const calculateExamTime = () => {
  31. if (!participantInfo.value.startTime || !participantInfo.value.submitTime) {
  32. return '-';
  33. }
  34. const startTime = new Date(participantInfo.value.startTime).getTime();
  35. const submitTime = new Date(participantInfo.value.submitTime).getTime();
  36. const duration = (submitTime - startTime) / 60_000; // 转换为分钟
  37. return `${duration.toFixed(2)} 分钟`;
  38. };
  39. // 数据处理工具函数
  40. // 解析JSON字符串,处理异常
  41. const parseJson = (str: string) => {
  42. if (!str) return [];
  43. try {
  44. return JSON.parse(str);
  45. } catch (error) {
  46. console.error('解析JSON失败:', error);
  47. return [];
  48. }
  49. };
  50. const knowledgeRef: any = ref(null);
  51. const selectedCategoryInfo = ref<any>({});
  52. const [quoteModal, quoteModalApi] = useVbenModal({
  53. title: '引用试题',
  54. showCancelBtn: false,
  55. class: 'quote-modal',
  56. onConfirm: () => {
  57. const result = knowledgeRef.value.confirmSelection();
  58. if (result) {
  59. // formData.value = result;
  60. // console.log(result);
  61. selectedCategoryInfo.value = result;
  62. quoteModalApi.close();
  63. }
  64. },
  65. });
  66. // 根据paperQuestionId获取答题信息
  67. const getAnswerByPaperQuestionId = (paperQuestionId: number) => {
  68. return (
  69. answerInfo.value.find(
  70. (item: any) => item.paperQuestionId === paperQuestionId,
  71. ) || {}
  72. );
  73. };
  74. // 获取题目类型中文名称
  75. const getQuestionTypeName = (type: string) => {
  76. const typeMap: any = {
  77. single_choice: '单选题',
  78. multiple_choice: '多选题',
  79. judgment: '判断题',
  80. fill_blank: '填空题',
  81. essay: '简答题',
  82. };
  83. return typeMap[type] || type;
  84. };
  85. // 按大题索引分组题目
  86. const getQuestionsByBigIndex = () => {
  87. if (!examInfo.value?.paper?.questions) return [];
  88. const grouped: any = {};
  89. examInfo.value.paper.questions.forEach((question: any) => {
  90. if (!grouped[question.bigQuestionIndex]) {
  91. grouped[question.bigQuestionIndex] = [];
  92. }
  93. grouped[question.bigQuestionIndex].push(question);
  94. });
  95. // 转换为数组并按索引排序
  96. return Object.keys(grouped)
  97. .sort((a, b) => Number(a) - Number(b))
  98. .map((key) => grouped[key]);
  99. };
  100. const handleQuote = (str: string) => {
  101. selectedCategoryInfo.value = JSON.parse(str || '{}');
  102. quoteModalApi.open();
  103. };
  104. const init = async () => {
  105. // 并发请求接口获取数据
  106. const [examInfoRes, participantRes, answerRes] = await Promise.all([
  107. examPaperDetail(examId),
  108. getParticipantById(pid),
  109. getAnswerResult(examId),
  110. ]);
  111. examInfo.value = examInfoRes || {};
  112. if (examInfo.value?.paper?.bigQuestionNames) {
  113. examInfo.value.paper.bigQuestionNames = JSON.parse(
  114. examInfo.value.paper.bigQuestionNames,
  115. );
  116. }
  117. participantInfo.value = participantRes || {};
  118. answerInfo.value = answerRes || {};
  119. };
  120. onMounted(async () => {
  121. await init();
  122. });
  123. </script>
  124. <template>
  125. <Page title="已出分">
  126. <div class="startexamin_box">
  127. <div class="left w-full rounded-md bg-white p-4">
  128. <div
  129. class="exam_info_left"
  130. v-for="(bigQuestion, bigIndex) in examInfo?.paper?.bigQuestionNames"
  131. :key="bigIndex"
  132. >
  133. <div class="exam_info_left_title">
  134. {{ bigQuestion.name }}(本题分值{{ bigQuestion.score }}分)
  135. </div>
  136. <!-- 动态生成小题 -->
  137. <div
  138. class="exam_info_left_content"
  139. v-for="(question, questionIndex) in getQuestionsByBigIndex()[
  140. +bigIndex
  141. ] || []"
  142. :key="question.id"
  143. >
  144. <div class="exam_info_left_content_title">
  145. {{ +questionIndex + 1 }}.
  146. <span v-html="question.info.questionContent"></span>({{
  147. getQuestionTypeName(question.questionType)
  148. }},{{ question.smallQuestionScore }}分)
  149. </div>
  150. <!-- 选项题(单选、多选、判断) -->
  151. <div
  152. class="exam_info_left_content_option"
  153. v-if="
  154. ['single_choice', 'multiple_choice', 'judgment'].includes(
  155. question.questionType,
  156. )
  157. "
  158. >
  159. <div
  160. class="exam_info_left_content_option_item"
  161. v-for="(option, optionIndex) in parseJson(
  162. question.info.options,
  163. )"
  164. :key="optionIndex"
  165. :style="{
  166. color:
  167. getAnswerByPaperQuestionId(question.id).userAnswer &&
  168. parseJson(
  169. getAnswerByPaperQuestionId(question.id).userAnswer,
  170. ).includes(optionIndex)
  171. ? getAnswerByPaperQuestionId(question.id).isCorrect === 1
  172. ? '#38b865'
  173. : '#eb5e12'
  174. : '#31373d',
  175. }"
  176. >
  177. <span>
  178. {{ String.fromCharCode(65 + +optionIndex) }}.
  179. <span v-html="option"></span>
  180. </span>
  181. <!-- 显示正确/错误图标 -->
  182. <el-icon
  183. v-if="
  184. getAnswerByPaperQuestionId(question.id).userAnswer &&
  185. parseJson(
  186. getAnswerByPaperQuestionId(question.id).userAnswer,
  187. ).includes(optionIndex)
  188. "
  189. >
  190. <CircleCheckFilled
  191. v-if="
  192. getAnswerByPaperQuestionId(question.id).isCorrect === 1
  193. "
  194. />
  195. <CircleCloseFilled v-else />
  196. </el-icon>
  197. </div>
  198. </div>
  199. <!-- 填空题 -->
  200. <div
  201. class="exam_info_left_content_option"
  202. v-else-if="question.questionType === 'fill_blank'"
  203. >
  204. <div class="exam_info_left_content_option_item">
  205. <span>用户答案:</span>
  206. <span
  207. :style="{
  208. color:
  209. getAnswerByPaperQuestionId(question.id).isCorrect === 1
  210. ? '#38b865'
  211. : '#eb5e12',
  212. marginLeft: '10px',
  213. }"
  214. >
  215. <span
  216. v-html="
  217. parseJson(
  218. getAnswerByPaperQuestionId(question.id).userAnswer ||
  219. '[]',
  220. ).join('、')
  221. "
  222. ></span>
  223. </span>
  224. </div>
  225. </div>
  226. <!-- 简答题 -->
  227. <div
  228. class="exam_info_left_content_option"
  229. v-else-if="question.questionType === 'essay'"
  230. >
  231. <div class="exam_info_left_content_option_item">
  232. <span>用户答案:</span>
  233. </div>
  234. <div
  235. class="exam_info_left_content_option_item"
  236. :style="{
  237. color:
  238. getAnswerByPaperQuestionId(question.id).isCorrect === 1
  239. ? '#38b865'
  240. : '#eb5e12',
  241. marginLeft: '20px',
  242. marginTop: '10px',
  243. }"
  244. >
  245. <span
  246. v-html="
  247. getAnswerByPaperQuestionId(question.id).userAnswer ||
  248. '未作答'
  249. "
  250. ></span>
  251. </div>
  252. </div>
  253. <!-- 答案解析 -->
  254. <div class="exam_info_left_content_answer">
  255. <!-- 正确答案(简答题不显示) -->
  256. <div
  257. class="exam_info_left_content_answer_title"
  258. v-if="question.questionType !== 'essay'"
  259. >
  260. 正确答案:
  261. <span
  262. v-if="
  263. ['single_choice', 'multiple_choice', 'judgment'].includes(
  264. question.questionType,
  265. )
  266. "
  267. >
  268. <span
  269. v-html="
  270. parseJson(question.info.correctAnswer || '[]')
  271. .map((idx: number) => String.fromCharCode(65 + idx))
  272. .join(',')
  273. "
  274. ></span>
  275. </span>
  276. <span v-else-if="question.questionType === 'fill_blank'">
  277. <span
  278. v-html="
  279. parseJson(question.info.correctAnswer || '[]').join('、')
  280. "
  281. ></span>
  282. </span>
  283. <span v-else>
  284. <span v-html="question.info.correctAnswer || '无'"></span>
  285. </span>
  286. </div>
  287. <div class="exam_info_left_content_answer_desc">
  288. 答案解析:
  289. <ElLink
  290. v-if="question.info.analysisReference"
  291. type="primary"
  292. @click="handleQuote(question.info.analysisReference)"
  293. >
  294. 查看引用解析
  295. </ElLink>
  296. <div class="exam_info_left_content_answer_content">
  297. <span
  298. v-html="question.info.answerAnalysis || '暂无解析'"
  299. ></span>
  300. </div>
  301. </div>
  302. <div class="exam_info_left_content_answer_title">
  303. 得分:
  304. <span
  305. :style="{
  306. color:
  307. getAnswerByPaperQuestionId(question.id).isCorrect === 1
  308. ? '#38b865'
  309. : '#eb5e12',
  310. }"
  311. >
  312. {{ getAnswerByPaperQuestionId(question.id).userScore || 0 }} /
  313. {{ question.smallQuestionScore }}
  314. </span>
  315. </div>
  316. </div>
  317. </div>
  318. </div>
  319. </div>
  320. <div class="rigth">
  321. <div class="exam_info_right_top">
  322. <div class="exam_info_right_top_title">{{ examInfo.examName }}</div>
  323. <div class="exam_info_right_top_content">
  324. <div>考试姓名:{{ participantInfo.userName || '未知' }}</div>
  325. <div>试卷总分:{{ examInfo.totalScore }}分</div>
  326. <div>及格分数:{{ examInfo.passScore }}分</div>
  327. <div v-if="participantInfo.reviewStatus === 'unreviewed'">
  328. 考生得分:未出分
  329. </div>
  330. <div v-else>考生得分:{{ participantInfo.score || 0 }}分</div>
  331. <div>考试用时:{{ calculateExamTime() }}</div>
  332. <div v-if="participantInfo.reviewStatus === 'reviewed'">
  333. 考试结果:
  334. <span
  335. style="color: #38b865"
  336. v-if="participantInfo.score >= examInfo.passScore"
  337. >及格
  338. </span>
  339. <span style="color: #eb5e12" v-else>不及格</span>
  340. </div>
  341. </div>
  342. </div>
  343. <div class="exam_info_right_main">
  344. <div
  345. class="rigth_main_content"
  346. v-for="(bigQuestion, bigIndex) in examInfo?.paper?.bigQuestionNames"
  347. :key="bigIndex"
  348. >
  349. <div class="rigth_main_content_title">
  350. <text>{{ bigQuestion.name }}</text>
  351. <text>
  352. 总{{ getQuestionsByBigIndex()[+bigIndex]?.length || 0 }}题/共
  353. {{ bigQuestion.score }} 分
  354. </text>
  355. </div>
  356. <div class="rigth_main_content_item">
  357. <div
  358. v-for="(question, questionIndex) in getQuestionsByBigIndex()[
  359. +bigIndex
  360. ] || []"
  361. class="rigth_main_content_items"
  362. :key="question.id"
  363. :style="{
  364. backgroundColor:
  365. getAnswerByPaperQuestionId(question.id).isCorrect === 1
  366. ? '#38b865'
  367. : getAnswerByPaperQuestionId(question.id).isCorrect === 0
  368. ? '#eb5e12'
  369. : getAnswerByPaperQuestionId(question.id).userAnswer
  370. ? '#215acd'
  371. : '#d4d6d9',
  372. }"
  373. >
  374. {{ +questionIndex + 1 }}
  375. </div>
  376. </div>
  377. </div>
  378. </div>
  379. </div>
  380. </div>
  381. <quoteModal>
  382. <knowledgemain ref="knowledgeRef" :data="selectedCategoryInfo" />
  383. </quoteModal>
  384. </Page>
  385. </template>
  386. <style lang="scss" scoped>
  387. .startexamin_box {
  388. width: 100%;
  389. height: 730px;
  390. display: flex;
  391. justify-content: space-between;
  392. gap: 10px;
  393. overflow: hidden;
  394. .left {
  395. flex: 1;
  396. // height: 730px;
  397. // border: 1px solid red;
  398. overflow-y: auto;
  399. display: flex;
  400. flex-direction: column;
  401. gap: 12px;
  402. .exam_info_left {
  403. display: flex;
  404. flex-direction: column;
  405. gap: 12px;
  406. .exam_info_left_title {
  407. width: 100%;
  408. height: 80px;
  409. background-color: #f7f9fa;
  410. font-size: 18px;
  411. font-weight: 500;
  412. line-height: 80px;
  413. box-sizing: border-box;
  414. padding-left: 24px;
  415. color: #31373d;
  416. }
  417. .exam_info_left_content {
  418. box-sizing: border-box;
  419. padding-left: 24px;
  420. padding-top: 24px;
  421. background-color: #f7f9fa;
  422. font-size: 20px;
  423. font-weight: 400;
  424. color: #31373d;
  425. .exam_info_left_content_title {
  426. margin-bottom: 24px;
  427. display: flex;
  428. align-items: center;
  429. flex-wrap: wrap;
  430. span {
  431. display: inline;
  432. p {
  433. display: inline;
  434. margin: 0;
  435. }
  436. }
  437. }
  438. .exam_info_left_content_option {
  439. display: flex;
  440. flex-direction: column;
  441. gap: 12px;
  442. .exam_info_left_content_option_item {
  443. display: flex;
  444. align-items: flex-start;
  445. font-size: 18px;
  446. font-weight: 400;
  447. color: #31373d;
  448. width: 100%;
  449. > span {
  450. display: flex;
  451. align-items: flex-start;
  452. gap: 5px;
  453. width: 100%;
  454. &:first-child {
  455. width: auto;
  456. }
  457. p {
  458. display: inline;
  459. margin: 0;
  460. vertical-align: top;
  461. }
  462. }
  463. }
  464. }
  465. .exam_info_left_content_answer {
  466. width: 100%;
  467. border-top: 1px solid #e6e8eb;
  468. display: flex;
  469. flex-direction: column;
  470. gap: 12px;
  471. box-sizing: border-box;
  472. padding-top: 24px;
  473. padding-bottom: 24px;
  474. margin-top: 24px;
  475. .exam_info_left_content_answer_title,
  476. .exam_info_left_content_answer_desc {
  477. font-size: 18px;
  478. font-weight: 500;
  479. color: #31373d;
  480. // display: flex;
  481. align-items: center;
  482. flex-wrap: wrap;
  483. span {
  484. display: inline;
  485. p {
  486. display: inline;
  487. margin: 0;
  488. }
  489. }
  490. .exam_info_left_content_answer_content {
  491. margin-top: 12px;
  492. margin-left: 8px;
  493. font-size: 16px;
  494. font-weight: 400;
  495. color: #4e5969;
  496. span {
  497. display: inline;
  498. p {
  499. display: inline;
  500. margin: 0;
  501. }
  502. }
  503. }
  504. }
  505. }
  506. }
  507. }
  508. }
  509. .rigth {
  510. width: 400px;
  511. display: flex;
  512. flex-direction: column;
  513. gap: 12px;
  514. // border: 1px solid red;
  515. .exam_info_right_top {
  516. background-color: #ffffff;
  517. width: 100%;
  518. height: 332px;
  519. padding: 24px;
  520. box-sizing: border-box;
  521. .exam_info_right_top_title {
  522. font-size: 18px;
  523. font-weight: 500;
  524. color: #31373d;
  525. margin-bottom: 28px;
  526. }
  527. .exam_info_right_top_content {
  528. display: flex;
  529. flex-direction: column;
  530. gap: 24px;
  531. font-size: 16px;
  532. font-weight: 500;
  533. color: #31373d;
  534. }
  535. }
  536. .exam_info_right_main {
  537. flex: 1;
  538. background-color: #ffffff;
  539. box-sizing: border-box;
  540. padding: 16px 24px;
  541. display: flex;
  542. flex-direction: column;
  543. gap: 28px;
  544. // height: 384px;
  545. // border: 1px solid red;
  546. overflow-y: auto;
  547. .rigth_main_content {
  548. display: flex;
  549. flex-direction: column;
  550. gap: 12px;
  551. .rigth_main_content_title {
  552. // height: 48px;
  553. display: flex;
  554. justify-content: space-between;
  555. align-items: center;
  556. font-size: 16px;
  557. font-weight: 500;
  558. }
  559. .rigth_main_content_item {
  560. display: flex;
  561. flex-wrap: wrap;
  562. gap: 12px;
  563. .rigth_main_content_items {
  564. width: 40px;
  565. height: 40px;
  566. border-radius: 4px;
  567. background-color: #38b865;
  568. display: flex;
  569. justify-content: center;
  570. align-items: center;
  571. color: #ffffff;
  572. font-size: 14px;
  573. font-weight: 400;
  574. border: 1px solid #d4d6d9;
  575. }
  576. .selectedactive {
  577. background-color: #e2eaf6;
  578. }
  579. .answered {
  580. background-color: #215acd;
  581. color: white;
  582. }
  583. .selectedactive.answered {
  584. background-color: #215acd;
  585. color: white;
  586. }
  587. }
  588. }
  589. }
  590. }
  591. }
  592. </style>