onlineExamPlay.vue 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  1. <!-- 在线考试答题页 -->
  2. <template>
  3. <view class="exam-screen">
  4. <!-- 顶部栏 -->
  5. <view class="topbar">
  6. <!-- <view class="topbar-left" @click="requestSubmit(false)">‹ 交卷</view> -->
  7. <view class="topbar-left"></view>
  8. <view class="topbar-title">{{ examInfo.examName || '考试中' }}</view>
  9. <view class="topbar-right" @click="toggleQuestionNav">题号</view>
  10. </view>
  11. <!-- 剩余时间条 -->
  12. <view class="time-bar">
  13. <view class="time-bar-left">
  14. <text class="time-label">剩余时间</text>
  15. <text class="time-value">{{ formattedTime }}</text>
  16. </view>
  17. <text class="time-tip">请合理安排答题时间</text>
  18. </view>
  19. <!-- 答题统计 -->
  20. <view class="stat-row">
  21. <view class="stat-item">
  22. <text class="stat-num stat-answered">{{ answeredCount }}</text>
  23. <text class="stat-label">已答</text>
  24. </view>
  25. <view class="stat-divider"></view>
  26. <view class="stat-item">
  27. <text class="stat-num">{{ unansweredCount }}</text>
  28. <text class="stat-label">未答</text>
  29. </view>
  30. <view class="stat-divider"></view>
  31. <view class="stat-item">
  32. <text class="stat-num">{{ totalCount }}</text>
  33. <text class="stat-label">总题</text>
  34. </view>
  35. </view>
  36. <!-- 题号导航面板 -->
  37. <view v-if="showQuestionNav" class="q-nav-panel">
  38. <view class="q-nav-scroll-wrapper">
  39. <view class="q-nav-header">
  40. <text class="q-nav-title">题目列表</text>
  41. <text class="q-nav-close" @click="toggleQuestionNav">✕</text>
  42. </view>
  43. <scroll-view scroll-y class="q-nav-scroll">
  44. <view v-for="(group, gi) in questionTypeGroups" :key="gi" class="q-group">
  45. <view class="q-group-title">{{ group.questionTypeName }}({{ group.questionCount }}题 {{ group.totalScore }}分)</view>
  46. <view class="q-num-row">
  47. <view
  48. v-for="(q, qi) in group.questions"
  49. :key="qi"
  50. class="q-num"
  51. :class="gi === groupIndex && qi === questionIndex ? 'current' : (q.answered === 1 ? 'answered' : '')"
  52. @click="selectQuestion(gi, qi)"
  53. >{{ q.questionNo }}</view>
  54. </view>
  55. </view>
  56. </scroll-view>
  57. </view>
  58. </view>
  59. <!-- 题目内容 -->
  60. <scroll-view scroll-y class="q-scroll-content">
  61. <view v-if="currentQuestion.snapshotQuestionId" class="q-card">
  62. <view class="q-header">
  63. <view class="q-header-left">
  64. <text class="q-type-badge">{{ currentQuestion.questionTypeName }}</text>
  65. <text class="q-num-text">第 {{ currentQuestion.questionNo }} 题</text>
  66. <text class="q-score-text">({{ currentQuestion.questionScore }}分)</text>
  67. </view>
  68. <text v-if="currentQuestion.difficulty" class="q-difficulty">{{ getDifficultyText(currentQuestion.difficulty) }}</text>
  69. </view>
  70. <view class="q-content">
  71. <rich-text :nodes="currentQuestion.questionContent || ''"></rich-text>
  72. </view>
  73. <view class="q-options">
  74. <view
  75. v-for="(opt, oi) in (currentQuestion.options || [])"
  76. :key="oi"
  77. class="q-option"
  78. :class="{ selected: isSelected(opt.optionLabel) }"
  79. :data-oi="oi"
  80. @click="onOptionTap"
  81. >
  82. <view class="q-option-label">{{ opt.optionLabel }}</view>
  83. <view class="q-option-content">
  84. <rich-text :nodes="opt.optionContent || opt.optionLabel"></rich-text>
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. <view v-else-if="pageLoading" class="empty-tip">加载中...</view>
  90. <view v-else class="empty-tip">暂无题目</view>
  91. <view class="scroll-bottom-space"></view>
  92. </scroll-view>
  93. <!-- 上一题/下一题 -->
  94. <view class="q-nav">
  95. <view class="q-nav-btn" :class="{ disabled: isFirstQuestion }" @click="prevQuestion">上一题</view>
  96. <view class="q-nav-btn q-nav-btn-next" :class="{ disabled: isLastQuestion }" @click="nextQuestion">下一题</view>
  97. </view>
  98. <!-- 底部提交 -->
  99. <view class="exam-bottom">
  100. <view class="btn-primary" @click="requestSubmit(false)">提交试卷</view>
  101. </view>
  102. <!-- 交卷结果遮罩 -->
  103. <view v-if="showResult" class="result-shade">
  104. <view class="result-card">
  105. <view class="result-score-wrap">
  106. <text class="result-score-num">{{ resultData.score }}</text>
  107. <text class="result-score-unit">分</text>
  108. </view>
  109. <view class="result-score-label">本次考试成绩</view>
  110. <view class="result-pass-pill" :class="resultData.isPass ? 'is-pass' : 'is-fail'">
  111. <text class="result-pass-text">{{ resultData.isPass ? '考试通过' : '考试未通过' }}</text>
  112. </view>
  113. <view class="result-grid">
  114. <view class="result-grid-item">
  115. <view class="result-grid-label">满分</view>
  116. <view class="result-grid-value">{{ resultData.totalScore }}</view>
  117. </view>
  118. <view class="result-grid-item">
  119. <view class="result-grid-label">及格分</view>
  120. <view class="result-grid-value text-orange">{{ resultData.passScore }}</view>
  121. </view>
  122. <view class="result-grid-item">
  123. <view class="result-grid-label">用时</view>
  124. <view class="result-grid-value">{{ resultData.usedTime }}</view>
  125. </view>
  126. </view>
  127. <view class="result-stats">
  128. <view class="result-stats-row">
  129. <text class="result-stats-label">正确题数</text>
  130. <text class="result-stats-value text-green">{{ resultData.correctCount }}</text>
  131. </view>
  132. <view class="result-stats-row">
  133. <text class="result-stats-label">错误题数</text>
  134. <text class="result-stats-value text-red">{{ resultData.wrongCount }}</text>
  135. </view>
  136. <view class="result-stats-row">
  137. <text class="result-stats-label">正确率</text>
  138. <text class="result-stats-value text-blue">{{ resultData.accuracy }}</text>
  139. </view>
  140. </view>
  141. <view class="result-btns">
  142. <view v-if="!resultData.isPass" class="result-btn result-btn-outline" @click="reviewMistakes">查看错题</view>
  143. <!-- <view v-if="resultData.canRetake" class="result-btn result-btn-primary" @click="retakeExam">重新考试</view> -->
  144. <view class="result-btn result-btn-primary" @click="closeResult">返回</view>
  145. </view>
  146. <view class="result-cert" v-if="resultData.certificateName">
  147. <text class="result-cert-icon">🏆</text>
  148. <view class="result-cert-info">
  149. <view class="result-cert-title">您已获得证书!</view>
  150. <view class="result-cert-name">{{ resultData.certificateName }}</view>
  151. <!-- <view class="result-cert-btn" @click="goCertificate(resultData.certificatePath)">查看证书</view> -->
  152. </view>
  153. </view>
  154. </view>
  155. </view>
  156. </view>
  157. </template>
  158. <script>
  159. import {
  160. examElExamAttemptReviewSidebar,
  161. examElExamAttemptReviewQuestion,
  162. examUserExamGetExamSurplusTime,
  163. examUserExamAnswerSave,
  164. examUserExamSubmit,
  165. examUserExamStart,
  166. } from '@/pages_safetyEducationExamination/api/index.js'
  167. export default {
  168. data() {
  169. return {
  170. examId: '',
  171. attemptId: '',
  172. examKind: '',
  173. examInfo: {},
  174. questionTypeGroups: [],
  175. currentQuestion: {},
  176. groupIndex: 0,
  177. questionIndex: 0,
  178. remainingSeconds: 0,
  179. initialSeconds: 0,
  180. timer: null,
  181. hasWarnedTime: false,
  182. showQuestionNav: false,
  183. pageLoading: false,
  184. isSaving: false,
  185. isSubmitting: false,
  186. hasSubmitted: false,
  187. showResult: false,
  188. resultData: {},
  189. }
  190. },
  191. computed: {
  192. isFirstQuestion() {
  193. return this.groupIndex === 0 && this.questionIndex === 0;
  194. },
  195. isLastQuestion() {
  196. const lastGi = this.questionTypeGroups.length - 1;
  197. if (lastGi < 0) return true;
  198. const lastGroup = this.questionTypeGroups[lastGi];
  199. return this.groupIndex === lastGi && this.questionIndex === (lastGroup.questions.length - 1);
  200. },
  201. totalCount() {
  202. return this.questionTypeGroups.reduce((s, g) => s + (g.questions ? g.questions.length : 0), 0);
  203. },
  204. answeredCount() {
  205. return this.questionTypeGroups.reduce((s, g) => {
  206. return s + (g.questions || []).filter(q => q.answered === 1).length;
  207. }, 0);
  208. },
  209. unansweredCount() {
  210. return this.totalCount - this.answeredCount;
  211. },
  212. formattedTime() {
  213. const s = Math.max(0, Math.floor(this.remainingSeconds));
  214. const m = Math.floor(s / 60);
  215. const sec = s % 60;
  216. return m + '分' + (sec < 10 ? '0' : '') + sec + '秒';
  217. },
  218. },
  219. onLoad(options) {
  220. this.examId = options.examId || '';
  221. this.attemptId = options.attemptId || '';
  222. this.examKind = options.examKind || '';
  223. if (!this.attemptId) {
  224. uni.showToast({ title: '考试信息无效', icon: 'none' });
  225. setTimeout(() => uni.navigateBack(), 1500);
  226. return;
  227. }
  228. this.pageLoading = true;
  229. this.loadSidebar();
  230. },
  231. onShow() {
  232. if (this.hasSubmitted || !this.attemptId) return;
  233. if (this.questionTypeGroups.length > 0) {
  234. this.syncRemainingTime();
  235. }
  236. },
  237. onHide() {
  238. this.clearTimer();
  239. if (!this.hasSubmitted) this.saveCurrentAnswer();
  240. },
  241. onUnload() {
  242. this.clearTimer();
  243. if (!this.hasSubmitted) this.saveCurrentAnswer();
  244. },
  245. methods: {
  246. async loadSidebar() {
  247. try {
  248. const { data } = await examElExamAttemptReviewSidebar({
  249. attemptId: this.attemptId,
  250. examKind: this.examKind,
  251. });
  252. if (data.code === 200 && data.data) {
  253. this.examInfo = {
  254. examTypeName: data.data.examTypeName || '',
  255. examName: data.data.examName || '',
  256. questionCount: data.data.questionCount || 0,
  257. totalScore: data.data.totalScore || 0,
  258. passScore: data.data.passScore || 0,
  259. };
  260. this.$set(this, 'questionTypeGroups', data.data.questionTypeGroups || []);
  261. this.groupIndex = 0;
  262. this.questionIndex = 0;
  263. const firstGroup = this.questionTypeGroups[0];
  264. if (firstGroup && firstGroup.questions && firstGroup.questions.length > 0) {
  265. await this.loadQuestion(firstGroup.questions[0].snapshotQuestionId);
  266. this.syncRemainingTime();
  267. }
  268. } else {
  269. uni.showToast({ title: data.message || '加载失败', icon: 'none' });
  270. }
  271. } catch (e) {
  272. console.error('加载题号导航失败', e);
  273. } finally {
  274. this.pageLoading = false;
  275. }
  276. },
  277. async loadQuestion(snapshotQuestionId) {
  278. try {
  279. const { data } = await examElExamAttemptReviewQuestion({
  280. attemptId: this.attemptId,
  281. snapshotQuestionId: snapshotQuestionId,
  282. examScene: 1,
  283. });
  284. if (data.code === 200 && data.data) {
  285. this.$set(this, 'currentQuestion', data.data);
  286. } else {
  287. throw new Error(data.message || '加载题目失败');
  288. }
  289. } catch (e) {
  290. console.error('加载题目失败', e);
  291. throw e;
  292. }
  293. },
  294. async syncRemainingTime() {
  295. try {
  296. const { data } = await examUserExamGetExamSurplusTime({ attemptId: this.attemptId });
  297. if (data.code === 200) {
  298. this.remainingSeconds = Number(data.data) || 0;
  299. if (!this.initialSeconds) this.initialSeconds = this.remainingSeconds;
  300. this.clearTimer();
  301. this.startTimer();
  302. }
  303. } catch (e) {
  304. console.error('获取剩余时间失败', e);
  305. }
  306. },
  307. startTimer() {
  308. if (this.timer) return;
  309. this.timer = setInterval(() => {
  310. if (this.remainingSeconds <= 0) {
  311. this.clearTimer();
  312. this.autoSubmit();
  313. return;
  314. }
  315. this.remainingSeconds--;
  316. if (this.remainingSeconds === 60 && !this.hasWarnedTime) {
  317. this.hasWarnedTime = true;
  318. uni.showToast({ title: '请注意剩余时间', icon: 'none', duration: 2000 });
  319. }
  320. }, 1000);
  321. },
  322. clearTimer() {
  323. if (this.timer) {
  324. clearInterval(this.timer);
  325. this.timer = null;
  326. }
  327. },
  328. selectAnswer(optIndex) {
  329. const opt = (this.currentQuestion.options || [])[optIndex];
  330. if (!opt || !this.currentQuestion.snapshotQuestionId) return;
  331. let tags = Array.isArray(this.currentQuestion.answerTags) ? [...this.currentQuestion.answerTags] : [];
  332. if (this.currentQuestion.questionType === 2) {
  333. const idx = tags.indexOf(opt.optionLabel);
  334. if (idx === -1) {
  335. tags.push(opt.optionLabel);
  336. } else {
  337. tags.splice(idx, 1);
  338. }
  339. } else {
  340. tags = [opt.optionLabel];
  341. }
  342. this.$set(this.currentQuestion, 'answerTags', tags);
  343. },
  344. onOptionTap(e) {
  345. const oi = Number(e.currentTarget.dataset.oi);
  346. this.selectAnswer(oi);
  347. },
  348. isSelected(label) {
  349. const tags = this.currentQuestion.answerTags;
  350. return Array.isArray(tags) && tags.indexOf(label) !== -1;
  351. },
  352. saveCurrentAnswer() {
  353. const q = this.currentQuestion;
  354. if (!q || !q.snapshotQuestionId) return Promise.resolve();
  355. const tags = Array.isArray(q.answerTags) ? q.answerTags.filter(Boolean) : [];
  356. if (tags.length === 0) return Promise.resolve();
  357. // 保存时记录当前 index,.then 回调里用快照避免 index 已切换导致回写错题
  358. const gi = this.groupIndex;
  359. const qi = this.questionIndex;
  360. return examUserExamAnswerSave({
  361. attemptId: this.attemptId,
  362. snapshotQuestionId: q.snapshotQuestionId,
  363. userAnswer: tags.join(','),
  364. }).then(res => {
  365. if (res.data && res.data.code === 200) {
  366. const groups = this.questionTypeGroups;
  367. if (groups[gi] && groups[gi].questions[qi]) {
  368. this.$set(groups[gi].questions[qi], 'answered', 1);
  369. }
  370. }
  371. }).catch(e => {
  372. console.error('保存答案失败', e);
  373. });
  374. },
  375. async changeQuestion(targetGi, targetQi) {
  376. if (this.isSaving) return;
  377. if (targetGi === this.groupIndex && targetQi === this.questionIndex) return;
  378. const group = this.questionTypeGroups[targetGi];
  379. if (!group || !group.questions || !group.questions[targetQi]) return;
  380. const prevGi = this.groupIndex;
  381. const prevQi = this.questionIndex;
  382. this.isSaving = true;
  383. try {
  384. await this.saveCurrentAnswer();
  385. this.groupIndex = targetGi;
  386. this.questionIndex = targetQi;
  387. await this.loadQuestion(group.questions[targetQi].snapshotQuestionId);
  388. } catch (e) {
  389. this.groupIndex = prevGi;
  390. this.questionIndex = prevQi;
  391. uni.showToast({ title: '题目加载失败,请重试', icon: 'none' });
  392. } finally {
  393. this.isSaving = false;
  394. }
  395. },
  396. selectQuestion(gi, qi) {
  397. this.changeQuestion(gi, qi);
  398. this.showQuestionNav = false;
  399. },
  400. prevQuestion() {
  401. if (this.isFirstQuestion || this.isSaving) return;
  402. if (this.questionIndex > 0) {
  403. this.changeQuestion(this.groupIndex, this.questionIndex - 1);
  404. } else {
  405. const prevGi = this.groupIndex - 1;
  406. const prevGroup = this.questionTypeGroups[prevGi];
  407. if (prevGroup) {
  408. this.changeQuestion(prevGi, prevGroup.questions.length - 1);
  409. }
  410. }
  411. },
  412. nextQuestion() {
  413. if (this.isLastQuestion || this.isSaving) return;
  414. const currentGroup = this.questionTypeGroups[this.groupIndex];
  415. if (this.questionIndex < currentGroup.questions.length - 1) {
  416. this.changeQuestion(this.groupIndex, this.questionIndex + 1);
  417. } else {
  418. this.changeQuestion(this.groupIndex + 1, 0);
  419. }
  420. },
  421. toggleQuestionNav() {
  422. this.showQuestionNav = !this.showQuestionNav;
  423. },
  424. getNumClass(gi, qi, q) {
  425. if (gi === this.groupIndex && qi === this.questionIndex) return 'current';
  426. if (q.answered === 1) return 'answered';
  427. return '';
  428. },
  429. getDifficultyText(d) {
  430. return { 1: '简单', 2: '一般', 3: '较难', 4: '很难' }[d] || '';
  431. },
  432. async requestSubmit(isAuto) {
  433. if (this.isSubmitting || this.hasSubmitted) return;
  434. this.isSubmitting = true;
  435. await this.saveCurrentAnswer();
  436. const unanswered = this.unansweredCount;
  437. if (isAuto) {
  438. await this.doSubmit();
  439. this.isSubmitting = false;
  440. return;
  441. }
  442. const content = unanswered > 0 ? `还有${unanswered}题未答,确认要交卷吗?` : '确认要交卷吗?';
  443. uni.showModal({
  444. title: '提示',
  445. content: content,
  446. success: async (res) => {
  447. if (res.confirm) {
  448. await this.doSubmit();
  449. }
  450. this.isSubmitting = false;
  451. },
  452. fail: () => { this.isSubmitting = false; }
  453. });
  454. },
  455. async autoSubmit() {
  456. if (this.isSubmitting || this.hasSubmitted) return;
  457. this.isSubmitting = true;
  458. await this.saveCurrentAnswer();
  459. uni.showToast({ title: '考试时间结束,正在提交…', icon: 'none' });
  460. await this.doSubmit();
  461. this.isSubmitting = false;
  462. },
  463. async doSubmit() {
  464. try {
  465. const { data } = await examUserExamSubmit({ attemptId: this.attemptId });
  466. if (data.code === 200 && data.data) {
  467. this.hasSubmitted = true;
  468. this.clearTimer();
  469. this.buildResult(data.data);
  470. this.showResult = true;
  471. } else {
  472. uni.showToast({ title: data.message || '交卷失败', icon: 'none' });
  473. }
  474. } catch (e) {
  475. console.error('交卷失败', e);
  476. uni.showToast({ title: '交卷失败', icon: 'none' });
  477. }
  478. },
  479. buildResult(resp) {
  480. const score = resp.totalScore || 0;
  481. const passScore = this.examInfo.passScore || 0;
  482. const pass = score >= passScore;
  483. const correct = this.pickNumber(resp.correctCount, resp.correctNum);
  484. const wrong = this.pickNumber(resp.wrongCount, resp.wrongNum);
  485. const total = this.pickNumber(resp.totalQuestionNum, this.totalCount);
  486. this.resultData = {
  487. score: score,
  488. isPass: pass,
  489. totalScore: this.examInfo.totalScore || 0,
  490. passScore: passScore,
  491. usedTime: this.buildUsedTime(),
  492. correctCount: correct == null ? '-' : `${correct} 题`,
  493. wrongCount: wrong == null ? '-' : `${wrong} 题`,
  494. accuracy: (correct == null || !total) ? '-' : `${Math.round((correct / total) * 100)}%`,
  495. canRetake: !pass && resp.canContinueExam === 1,
  496. certName: resp.certName || '',
  497. certUrl: resp.certUrl || '',
  498. };
  499. },
  500. pickNumber(...vals) {
  501. for (const v of vals) {
  502. if (v !== undefined && v !== null && v !== '') return Number(v);
  503. }
  504. return null;
  505. },
  506. buildUsedTime() {
  507. if (!this.initialSeconds) return '-';
  508. const used = Math.max(0, this.initialSeconds - Math.floor(this.remainingSeconds));
  509. const m = Math.floor(used / 60);
  510. const s = used % 60;
  511. return `${m}'${s < 10 ? '0' : ''}${s}"`;
  512. },
  513. async retakeExam() {
  514. try {
  515. const { data } = await examUserExamStart({ examId: this.examId, examScene: 1 });
  516. if (data.code === 200 && data.data && data.data.attemptId) {
  517. this.attemptId = data.data.attemptId;
  518. this.showResult = false;
  519. this.hasSubmitted = false;
  520. this.isSubmitting = false;
  521. this.hasWarnedTime = false;
  522. this.$set(this, 'questionTypeGroups', []);
  523. this.$set(this, 'currentQuestion', {});
  524. this.groupIndex = 0;
  525. this.questionIndex = 0;
  526. this.remainingSeconds = 0;
  527. this.initialSeconds = 0;
  528. this.pageLoading = true;
  529. this.loadSidebar();
  530. } else {
  531. uni.showToast({ title: data.message || '重新考试失败', icon: 'none' });
  532. }
  533. } catch (e) {
  534. console.error('重新考试失败', e);
  535. uni.showToast({ title: '重新考试失败', icon: 'none' });
  536. }
  537. },
  538. closeResult() {
  539. this.showResult = false;
  540. uni.navigateBack();
  541. },
  542. reviewMistakes() {
  543. const examName = encodeURIComponent(this.examInfo.examName || '');
  544. uni.redirectTo({
  545. url: `/pages_safetyEducationExamination/views/exam/incorrectQuestionsList?attemptId=${this.attemptId}&examName=${examName}`
  546. });
  547. },
  548. goCertificate(url) {
  549. if (!url) {
  550. uni.showToast({ title: '暂无证书', icon: 'none' });
  551. return;
  552. }
  553. uni.showLoading({ title: '加载中...', mask: true });
  554. uni.downloadFile({
  555. url: url,
  556. success: (res) => {
  557. if (res.statusCode === 200) {
  558. uni.openDocument({
  559. filePath: res.tempFilePath,
  560. fileType: 'pdf',
  561. showMenu: true,
  562. fail: () => {
  563. uni.showToast({ title: '打开证书失败', icon: 'none' });
  564. },
  565. complete: () => {
  566. uni.hideLoading();
  567. }
  568. });
  569. } else {
  570. uni.hideLoading();
  571. uni.showToast({ title: '证书加载失败', icon: 'none' });
  572. }
  573. },
  574. fail: () => {
  575. uni.hideLoading();
  576. uni.showToast({ title: '证书加载失败', icon: 'none' });
  577. }
  578. });
  579. },
  580. }
  581. }
  582. </script>
  583. <style lang="stylus" scoped>
  584. .exam-screen
  585. height 100%
  586. display flex
  587. flex-direction column
  588. background #f5f7fa
  589. position relative
  590. .topbar
  591. display flex
  592. align-items center
  593. justify-content space-between
  594. height 88rpx
  595. padding 0 28rpx
  596. background #fff
  597. border-bottom 1rpx solid #e8edf3
  598. flex-shrink 0
  599. .topbar-left
  600. font-size 28rpx
  601. color #1677ff
  602. min-width 80rpx
  603. .topbar-title
  604. font-size 28rpx
  605. font-weight 600
  606. color #222
  607. flex 1
  608. text-align center
  609. .topbar-right
  610. font-size 28rpx
  611. color #1677ff
  612. min-width 80rpx
  613. text-align right
  614. .time-bar
  615. display flex
  616. align-items center
  617. justify-content space-between
  618. padding 20rpx 28rpx
  619. background linear-gradient(90deg, #1677ff 0%, #0958d9 100%)
  620. flex-shrink 0
  621. .time-bar-left
  622. display flex
  623. align-items baseline
  624. .time-label
  625. font-size 24rpx
  626. color rgba(255,255,255,0.85)
  627. margin-right 16rpx
  628. .time-value
  629. font-size 44rpx
  630. font-weight 700
  631. color #fff
  632. .time-tip
  633. font-size 22rpx
  634. color rgba(255,255,255,0.75)
  635. .stat-row
  636. display flex
  637. align-items center
  638. background #fff
  639. padding 20rpx 0
  640. flex-shrink 0
  641. border-bottom 1rpx solid #e8edf3
  642. .stat-item
  643. flex 1
  644. display flex
  645. flex-direction column
  646. align-items center
  647. .stat-divider
  648. width 1rpx
  649. height 40rpx
  650. background #eee
  651. .stat-num
  652. font-size 36rpx
  653. font-weight 700
  654. color #333
  655. line-height 1
  656. .stat-answered
  657. color #1677ff
  658. .stat-label
  659. font-size 22rpx
  660. color #999
  661. margin-top 6rpx
  662. .q-nav-panel
  663. position absolute
  664. top 0
  665. left 0
  666. right 0
  667. bottom 0
  668. background rgba(0,0,0,0.45)
  669. z-index 100
  670. display flex
  671. flex-direction column
  672. justify-content flex-end
  673. .q-nav-scroll-wrapper
  674. background #fff
  675. border-radius 32rpx 32rpx 0 0
  676. max-height 70vh
  677. display flex
  678. flex-direction column
  679. .q-nav-header
  680. display flex
  681. align-items center
  682. justify-content space-between
  683. padding 28rpx 28rpx 16rpx
  684. flex-shrink 0
  685. .q-nav-title
  686. font-size 30rpx
  687. font-weight 600
  688. color #222
  689. .q-nav-close
  690. font-size 32rpx
  691. color #999
  692. padding 10rpx
  693. .q-nav-scroll
  694. flex 1
  695. overflow hidden
  696. padding-bottom 40rpx
  697. .q-group
  698. padding 0 28rpx 16rpx
  699. .q-group-title
  700. font-size 24rpx
  701. color #666
  702. line-height 60rpx
  703. .q-num-row
  704. display flex
  705. flex-wrap wrap
  706. .q-num
  707. width 72rpx
  708. height 72rpx
  709. line-height 72rpx
  710. text-align center
  711. font-size 24rpx
  712. border-radius 12rpx
  713. margin 8rpx
  714. background #f4f6fa
  715. color #333
  716. border 1rpx solid transparent
  717. .q-num.answered
  718. background #e6f4ff
  719. color #1677ff
  720. border-color #91caff
  721. .q-num.current
  722. background #1677ff
  723. color #fff
  724. .q-scroll-content
  725. flex 1
  726. overflow hidden
  727. .q-card
  728. margin 24rpx
  729. padding 28rpx
  730. background #fff
  731. border-radius 20rpx
  732. border 1rpx solid #dde3ed
  733. .q-header
  734. display flex
  735. align-items center
  736. justify-content space-between
  737. margin-bottom 20rpx
  738. .q-header-left
  739. display flex
  740. align-items center
  741. .q-type-badge
  742. font-size 20rpx
  743. padding 4rpx 14rpx
  744. background #e6f4ff
  745. color #1677ff
  746. border 1rpx solid #91caff
  747. border-radius 8rpx
  748. margin-right 12rpx
  749. .q-num-text
  750. font-size 26rpx
  751. color #333
  752. .q-score-text
  753. font-size 22rpx
  754. color #999
  755. .q-difficulty
  756. font-size 22rpx
  757. color #fa8c16
  758. background #fff7e6
  759. padding 4rpx 12rpx
  760. border-radius 8rpx
  761. .q-content
  762. font-size 28rpx
  763. line-height 1.8
  764. color #222
  765. margin-bottom 24rpx
  766. .q-options
  767. display flex
  768. flex-direction column
  769. .q-option
  770. display flex
  771. align-items center
  772. padding 22rpx 20rpx
  773. margin-bottom 16rpx
  774. border 2rpx solid #dde3ed
  775. border-radius 16rpx
  776. background #fff
  777. .q-option.selected
  778. border-color #1677ff
  779. background #e6f4ff
  780. .q-option-label
  781. width 48rpx
  782. height 48rpx
  783. line-height 48rpx
  784. text-align center
  785. border-radius 50%
  786. background #f4f6fa
  787. color #333
  788. font-size 24rpx
  789. font-weight 600
  790. margin-right 20rpx
  791. flex-shrink 0
  792. .q-option.selected .q-option-label
  793. background #1677ff
  794. color #fff
  795. .q-option-content
  796. flex 1
  797. font-size 26rpx
  798. color #333
  799. line-height 1.6
  800. .scroll-bottom-space
  801. height 200rpx
  802. .q-nav
  803. display flex
  804. background #fff
  805. border-top 1rpx solid #e8edf3
  806. flex-shrink 0
  807. .q-nav-btn
  808. flex 1
  809. height 88rpx
  810. line-height 88rpx
  811. text-align center
  812. font-size 28rpx
  813. color #1677ff
  814. .q-nav-btn.q-nav-btn-next
  815. border-left 1rpx solid #e8edf3
  816. .q-nav-btn.disabled
  817. color #ccc
  818. .exam-bottom
  819. padding 20rpx 24rpx
  820. padding-bottom calc(20rpx + env(safe-area-inset-bottom))
  821. background #fff
  822. border-top 1rpx solid #e8edf3
  823. flex-shrink 0
  824. .btn-primary
  825. background #1677ff
  826. color #fff
  827. border-radius 16rpx
  828. font-size 30rpx
  829. font-weight 600
  830. height 88rpx
  831. line-height 88rpx
  832. text-align center
  833. .result-shade
  834. position fixed
  835. top 0
  836. left 0
  837. right 0
  838. bottom 0
  839. background rgba(0,0,0,0.55)
  840. z-index 200
  841. display flex
  842. align-items center
  843. justify-content center
  844. .result-card
  845. width 580rpx
  846. background #fff
  847. border-radius 24rpx
  848. padding 40rpx 32rpx 32rpx
  849. display flex
  850. flex-direction column
  851. align-items center
  852. .result-score-wrap
  853. display flex
  854. align-items baseline
  855. line-height 1
  856. .result-score-num
  857. font-size 112rpx
  858. font-weight 900
  859. color #1857d4
  860. .result-score-unit
  861. font-size 30rpx
  862. font-weight 700
  863. color #1857d4
  864. margin-left 6rpx
  865. .result-score-label
  866. font-size 24rpx
  867. color #8896a7
  868. margin-top 4rpx
  869. margin-bottom 20rpx
  870. .result-pass-pill
  871. display inline-flex
  872. align-items center
  873. justify-content center
  874. border-radius 40rpx
  875. padding 8rpx 40rpx
  876. margin-bottom 28rpx
  877. .result-pass-pill.is-pass
  878. background #f6ffed
  879. .result-pass-pill.is-fail
  880. background #fff5f5
  881. .result-pass-text
  882. font-size 30rpx
  883. font-weight 700
  884. .result-pass-pill.is-pass .result-pass-text
  885. color #10a37f
  886. .result-pass-pill.is-fail .result-pass-text
  887. color #e53e3e
  888. .result-grid
  889. display flex
  890. width 100%
  891. gap 16rpx
  892. margin-bottom 24rpx
  893. .result-grid-item
  894. flex 1
  895. background #f4f6fa
  896. border-radius 16rpx
  897. padding 18rpx 12rpx
  898. text-align center
  899. .result-grid-label
  900. font-size 22rpx
  901. color #8896a7
  902. margin-bottom 8rpx
  903. .result-grid-value
  904. font-size 28rpx
  905. font-weight 500
  906. color #1a2233
  907. .result-stats
  908. width 100%
  909. background #f4f6fa
  910. border-radius 16rpx
  911. padding 22rpx 24rpx
  912. margin-bottom 28rpx
  913. box-sizing border-box
  914. .result-stats-row
  915. display flex
  916. justify-content space-between
  917. align-items center
  918. font-size 26rpx
  919. color #4a5568
  920. .result-stats-row + .result-stats-row
  921. margin-top 16rpx
  922. .result-stats-value
  923. font-weight 500
  924. .result-btns
  925. display flex
  926. width 100%
  927. gap 16rpx
  928. .result-btn
  929. flex 1
  930. height 80rpx
  931. line-height 80rpx
  932. text-align center
  933. border-radius 14rpx
  934. font-size 28rpx
  935. .result-btn-outline
  936. border 1rpx solid #1857d4
  937. color #1857d4
  938. .result-btn-primary
  939. border 1rpx solid #1857d4
  940. background #1857d4
  941. color #fff
  942. .result-cert
  943. display flex
  944. align-items center
  945. width 100%
  946. margin-top 24rpx
  947. padding 24rpx 20rpx
  948. background #f4f6fa
  949. border-radius 16rpx
  950. box-sizing border-box
  951. .result-cert-icon
  952. font-size 56rpx
  953. margin-right 20rpx
  954. .result-cert-info
  955. flex 1
  956. .result-cert-title
  957. font-size 28rpx
  958. font-weight 500
  959. color #1a2233
  960. margin-bottom 8rpx
  961. .result-cert-name
  962. font-size 24rpx
  963. color #8896a7
  964. .result-cert-btn
  965. display inline-block
  966. margin-top 12rpx
  967. padding 0 24rpx
  968. height 56rpx
  969. line-height 56rpx
  970. background #1857d4
  971. color #fff
  972. font-size 24rpx
  973. border-radius 10rpx
  974. .text-orange
  975. color #e67e22
  976. .text-green
  977. color #10a37f
  978. .text-red
  979. color #e53e3e
  980. .text-blue
  981. color #1857d4
  982. .empty-tip
  983. text-align center
  984. padding 80rpx 0
  985. color #aaa
  986. font-size 26rpx
  987. </style>