onlineExamPlay.vue 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  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. }
  287. } catch (e) {
  288. console.error('加载题目失败', e);
  289. }
  290. },
  291. async syncRemainingTime() {
  292. try {
  293. const { data } = await examUserExamGetExamSurplusTime({ attemptId: this.attemptId });
  294. if (data.code === 200) {
  295. this.remainingSeconds = Number(data.data) || 0;
  296. if (!this.initialSeconds) this.initialSeconds = this.remainingSeconds;
  297. this.clearTimer();
  298. this.startTimer();
  299. }
  300. } catch (e) {
  301. console.error('获取剩余时间失败', e);
  302. }
  303. },
  304. startTimer() {
  305. if (this.timer) return;
  306. this.timer = setInterval(() => {
  307. if (this.remainingSeconds <= 0) {
  308. this.clearTimer();
  309. this.autoSubmit();
  310. return;
  311. }
  312. this.remainingSeconds--;
  313. if (this.remainingSeconds === 60 && !this.hasWarnedTime) {
  314. this.hasWarnedTime = true;
  315. uni.showToast({ title: '请注意剩余时间', icon: 'none', duration: 2000 });
  316. }
  317. }, 1000);
  318. },
  319. clearTimer() {
  320. if (this.timer) {
  321. clearInterval(this.timer);
  322. this.timer = null;
  323. }
  324. },
  325. selectAnswer(optIndex) {
  326. const opt = (this.currentQuestion.options || [])[optIndex];
  327. if (!opt || !this.currentQuestion.snapshotQuestionId) return;
  328. let tags = Array.isArray(this.currentQuestion.answerTags) ? [...this.currentQuestion.answerTags] : [];
  329. if (this.currentQuestion.questionType === 2) {
  330. const idx = tags.indexOf(opt.optionLabel);
  331. if (idx === -1) {
  332. tags.push(opt.optionLabel);
  333. } else {
  334. tags.splice(idx, 1);
  335. }
  336. } else {
  337. tags = [opt.optionLabel];
  338. }
  339. this.$set(this.currentQuestion, 'answerTags', tags);
  340. },
  341. onOptionTap(e) {
  342. const oi = Number(e.currentTarget.dataset.oi);
  343. this.selectAnswer(oi);
  344. },
  345. isSelected(label) {
  346. const tags = this.currentQuestion.answerTags;
  347. return Array.isArray(tags) && tags.indexOf(label) !== -1;
  348. },
  349. saveCurrentAnswer() {
  350. const q = this.currentQuestion;
  351. if (!q || !q.snapshotQuestionId) return Promise.resolve();
  352. const tags = Array.isArray(q.answerTags) ? q.answerTags.filter(Boolean) : [];
  353. if (tags.length === 0) return Promise.resolve();
  354. return examUserExamAnswerSave({
  355. attemptId: this.attemptId,
  356. snapshotQuestionId: q.snapshotQuestionId,
  357. userAnswer: tags.join(','),
  358. }).then(res => {
  359. if (res.data && res.data.code === 200) {
  360. const groups = this.questionTypeGroups;
  361. if (groups[this.groupIndex] && groups[this.groupIndex].questions[this.questionIndex]) {
  362. this.$set(groups[this.groupIndex].questions[this.questionIndex], 'answered', 1);
  363. }
  364. }
  365. }).catch(e => {
  366. console.error('保存答案失败', e);
  367. });
  368. },
  369. async changeQuestion(targetGi, targetQi) {
  370. if (this.isSaving) return;
  371. if (targetGi === this.groupIndex && targetQi === this.questionIndex) return;
  372. const group = this.questionTypeGroups[targetGi];
  373. if (!group || !group.questions || !group.questions[targetQi]) return;
  374. this.isSaving = true;
  375. await this.saveCurrentAnswer();
  376. this.isSaving = false;
  377. const prevGi = this.groupIndex;
  378. const prevQi = this.questionIndex;
  379. this.groupIndex = targetGi;
  380. this.questionIndex = targetQi;
  381. try {
  382. await this.loadQuestion(group.questions[targetQi].snapshotQuestionId);
  383. } catch (e) {
  384. // 加载失败则回滚 index,避免 index 与 currentQuestion 错位
  385. this.groupIndex = prevGi;
  386. this.questionIndex = prevQi;
  387. uni.showToast({ title: '题目加载失败,请重试', icon: 'none' });
  388. }
  389. },
  390. selectQuestion(gi, qi) {
  391. this.changeQuestion(gi, qi);
  392. this.showQuestionNav = false;
  393. },
  394. prevQuestion() {
  395. if (this.isFirstQuestion || this.isSaving) return;
  396. if (this.questionIndex > 0) {
  397. this.changeQuestion(this.groupIndex, this.questionIndex - 1);
  398. } else {
  399. const prevGi = this.groupIndex - 1;
  400. const prevGroup = this.questionTypeGroups[prevGi];
  401. if (prevGroup) {
  402. this.changeQuestion(prevGi, prevGroup.questions.length - 1);
  403. }
  404. }
  405. },
  406. nextQuestion() {
  407. if (this.isLastQuestion || this.isSaving) return;
  408. const currentGroup = this.questionTypeGroups[this.groupIndex];
  409. if (this.questionIndex < currentGroup.questions.length - 1) {
  410. this.changeQuestion(this.groupIndex, this.questionIndex + 1);
  411. } else {
  412. this.changeQuestion(this.groupIndex + 1, 0);
  413. }
  414. },
  415. toggleQuestionNav() {
  416. this.showQuestionNav = !this.showQuestionNav;
  417. },
  418. getNumClass(gi, qi, q) {
  419. if (gi === this.groupIndex && qi === this.questionIndex) return 'current';
  420. if (q.answered === 1) return 'answered';
  421. return '';
  422. },
  423. getDifficultyText(d) {
  424. return { 1: '简单', 2: '一般', 3: '较难', 4: '很难' }[d] || '';
  425. },
  426. async requestSubmit(isAuto) {
  427. if (this.isSubmitting || this.hasSubmitted) return;
  428. this.isSubmitting = true;
  429. await this.saveCurrentAnswer();
  430. const unanswered = this.unansweredCount;
  431. if (isAuto) {
  432. await this.doSubmit();
  433. this.isSubmitting = false;
  434. return;
  435. }
  436. const content = unanswered > 0 ? `还有${unanswered}题未答,确认要交卷吗?` : '确认要交卷吗?';
  437. uni.showModal({
  438. title: '提示',
  439. content: content,
  440. success: async (res) => {
  441. if (res.confirm) {
  442. await this.doSubmit();
  443. }
  444. this.isSubmitting = false;
  445. },
  446. fail: () => { this.isSubmitting = false; }
  447. });
  448. },
  449. async autoSubmit() {
  450. if (this.isSubmitting || this.hasSubmitted) return;
  451. this.isSubmitting = true;
  452. await this.saveCurrentAnswer();
  453. uni.showToast({ title: '考试时间结束,正在提交…', icon: 'none' });
  454. await this.doSubmit();
  455. this.isSubmitting = false;
  456. },
  457. async doSubmit() {
  458. try {
  459. const { data } = await examUserExamSubmit({ attemptId: this.attemptId });
  460. if (data.code === 200 && data.data) {
  461. this.hasSubmitted = true;
  462. this.clearTimer();
  463. this.buildResult(data.data);
  464. this.showResult = true;
  465. } else {
  466. uni.showToast({ title: data.message || '交卷失败', icon: 'none' });
  467. }
  468. } catch (e) {
  469. console.error('交卷失败', e);
  470. uni.showToast({ title: '交卷失败', icon: 'none' });
  471. }
  472. },
  473. buildResult(resp) {
  474. const score = resp.totalScore || 0;
  475. const passScore = this.examInfo.passScore || 0;
  476. const pass = score >= passScore;
  477. const correct = this.pickNumber(resp.correctCount, resp.correctNum);
  478. const wrong = this.pickNumber(resp.wrongCount, resp.wrongNum);
  479. const total = this.pickNumber(resp.totalQuestionNum, this.totalCount);
  480. this.resultData = {
  481. score: score,
  482. isPass: pass,
  483. totalScore: this.examInfo.totalScore || 0,
  484. passScore: passScore,
  485. usedTime: this.buildUsedTime(),
  486. correctCount: correct == null ? '-' : `${correct} 题`,
  487. wrongCount: wrong == null ? '-' : `${wrong} 题`,
  488. accuracy: (correct == null || !total) ? '-' : `${Math.round((correct / total) * 100)}%`,
  489. canRetake: !pass && resp.canContinueExam === 1,
  490. certName: resp.certName || '',
  491. certUrl: resp.certUrl || '',
  492. };
  493. },
  494. pickNumber(...vals) {
  495. for (const v of vals) {
  496. if (v !== undefined && v !== null && v !== '') return Number(v);
  497. }
  498. return null;
  499. },
  500. buildUsedTime() {
  501. if (!this.initialSeconds) return '-';
  502. const used = Math.max(0, this.initialSeconds - Math.floor(this.remainingSeconds));
  503. const m = Math.floor(used / 60);
  504. const s = used % 60;
  505. return `${m}'${s < 10 ? '0' : ''}${s}"`;
  506. },
  507. async retakeExam() {
  508. try {
  509. const { data } = await examUserExamStart({ examId: this.examId, examScene: 1 });
  510. if (data.code === 200 && data.data && data.data.attemptId) {
  511. this.attemptId = data.data.attemptId;
  512. this.showResult = false;
  513. this.hasSubmitted = false;
  514. this.isSubmitting = false;
  515. this.hasWarnedTime = false;
  516. this.$set(this, 'questionTypeGroups', []);
  517. this.$set(this, 'currentQuestion', {});
  518. this.groupIndex = 0;
  519. this.questionIndex = 0;
  520. this.remainingSeconds = 0;
  521. this.initialSeconds = 0;
  522. this.pageLoading = true;
  523. this.loadSidebar();
  524. } else {
  525. uni.showToast({ title: data.message || '重新考试失败', icon: 'none' });
  526. }
  527. } catch (e) {
  528. console.error('重新考试失败', e);
  529. uni.showToast({ title: '重新考试失败', icon: 'none' });
  530. }
  531. },
  532. closeResult() {
  533. this.showResult = false;
  534. uni.navigateBack();
  535. },
  536. reviewMistakes() {
  537. const examName = encodeURIComponent(this.examInfo.examName || '');
  538. uni.redirectTo({
  539. url: `/pages_safetyEducationExamination/views/exam/incorrectQuestionsList?attemptId=${this.attemptId}&examName=${examName}`
  540. });
  541. },
  542. goCertificate(url) {
  543. if (!url) {
  544. uni.showToast({ title: '暂无证书', icon: 'none' });
  545. return;
  546. }
  547. uni.showLoading({ title: '加载中...', mask: true });
  548. uni.downloadFile({
  549. url: url,
  550. success: (res) => {
  551. if (res.statusCode === 200) {
  552. uni.openDocument({
  553. filePath: res.tempFilePath,
  554. fileType: 'pdf',
  555. showMenu: true,
  556. fail: () => {
  557. uni.showToast({ title: '打开证书失败', icon: 'none' });
  558. },
  559. complete: () => {
  560. uni.hideLoading();
  561. }
  562. });
  563. } else {
  564. uni.hideLoading();
  565. uni.showToast({ title: '证书加载失败', icon: 'none' });
  566. }
  567. },
  568. fail: () => {
  569. uni.hideLoading();
  570. uni.showToast({ title: '证书加载失败', icon: 'none' });
  571. }
  572. });
  573. },
  574. }
  575. }
  576. </script>
  577. <style lang="stylus" scoped>
  578. .exam-screen
  579. height 100%
  580. display flex
  581. flex-direction column
  582. background #f5f7fa
  583. position relative
  584. .topbar
  585. display flex
  586. align-items center
  587. justify-content space-between
  588. height 88rpx
  589. padding 0 28rpx
  590. background #fff
  591. border-bottom 1rpx solid #e8edf3
  592. flex-shrink 0
  593. .topbar-left
  594. font-size 28rpx
  595. color #1677ff
  596. min-width 80rpx
  597. .topbar-title
  598. font-size 28rpx
  599. font-weight 600
  600. color #222
  601. flex 1
  602. text-align center
  603. .topbar-right
  604. font-size 28rpx
  605. color #1677ff
  606. min-width 80rpx
  607. text-align right
  608. .time-bar
  609. display flex
  610. align-items center
  611. justify-content space-between
  612. padding 20rpx 28rpx
  613. background linear-gradient(90deg, #1677ff 0%, #0958d9 100%)
  614. flex-shrink 0
  615. .time-bar-left
  616. display flex
  617. align-items baseline
  618. .time-label
  619. font-size 24rpx
  620. color rgba(255,255,255,0.85)
  621. margin-right 16rpx
  622. .time-value
  623. font-size 44rpx
  624. font-weight 700
  625. color #fff
  626. .time-tip
  627. font-size 22rpx
  628. color rgba(255,255,255,0.75)
  629. .stat-row
  630. display flex
  631. align-items center
  632. background #fff
  633. padding 20rpx 0
  634. flex-shrink 0
  635. border-bottom 1rpx solid #e8edf3
  636. .stat-item
  637. flex 1
  638. display flex
  639. flex-direction column
  640. align-items center
  641. .stat-divider
  642. width 1rpx
  643. height 40rpx
  644. background #eee
  645. .stat-num
  646. font-size 36rpx
  647. font-weight 700
  648. color #333
  649. line-height 1
  650. .stat-answered
  651. color #1677ff
  652. .stat-label
  653. font-size 22rpx
  654. color #999
  655. margin-top 6rpx
  656. .q-nav-panel
  657. position absolute
  658. top 0
  659. left 0
  660. right 0
  661. bottom 0
  662. background rgba(0,0,0,0.45)
  663. z-index 100
  664. display flex
  665. flex-direction column
  666. justify-content flex-end
  667. .q-nav-scroll-wrapper
  668. background #fff
  669. border-radius 32rpx 32rpx 0 0
  670. max-height 70vh
  671. display flex
  672. flex-direction column
  673. .q-nav-header
  674. display flex
  675. align-items center
  676. justify-content space-between
  677. padding 28rpx 28rpx 16rpx
  678. flex-shrink 0
  679. .q-nav-title
  680. font-size 30rpx
  681. font-weight 600
  682. color #222
  683. .q-nav-close
  684. font-size 32rpx
  685. color #999
  686. padding 10rpx
  687. .q-nav-scroll
  688. flex 1
  689. overflow hidden
  690. padding-bottom 40rpx
  691. .q-group
  692. padding 0 28rpx 16rpx
  693. .q-group-title
  694. font-size 24rpx
  695. color #666
  696. line-height 60rpx
  697. .q-num-row
  698. display flex
  699. flex-wrap wrap
  700. .q-num
  701. width 72rpx
  702. height 72rpx
  703. line-height 72rpx
  704. text-align center
  705. font-size 24rpx
  706. border-radius 12rpx
  707. margin 8rpx
  708. background #f4f6fa
  709. color #333
  710. border 1rpx solid transparent
  711. .q-num.answered
  712. background #e6f4ff
  713. color #1677ff
  714. border-color #91caff
  715. .q-num.current
  716. background #1677ff
  717. color #fff
  718. .q-scroll-content
  719. flex 1
  720. overflow hidden
  721. .q-card
  722. margin 24rpx
  723. padding 28rpx
  724. background #fff
  725. border-radius 20rpx
  726. border 1rpx solid #dde3ed
  727. .q-header
  728. display flex
  729. align-items center
  730. justify-content space-between
  731. margin-bottom 20rpx
  732. .q-header-left
  733. display flex
  734. align-items center
  735. .q-type-badge
  736. font-size 20rpx
  737. padding 4rpx 14rpx
  738. background #e6f4ff
  739. color #1677ff
  740. border 1rpx solid #91caff
  741. border-radius 8rpx
  742. margin-right 12rpx
  743. .q-num-text
  744. font-size 26rpx
  745. color #333
  746. .q-score-text
  747. font-size 22rpx
  748. color #999
  749. .q-difficulty
  750. font-size 22rpx
  751. color #fa8c16
  752. background #fff7e6
  753. padding 4rpx 12rpx
  754. border-radius 8rpx
  755. .q-content
  756. font-size 28rpx
  757. line-height 1.8
  758. color #222
  759. margin-bottom 24rpx
  760. .q-options
  761. display flex
  762. flex-direction column
  763. .q-option
  764. display flex
  765. align-items center
  766. padding 22rpx 20rpx
  767. margin-bottom 16rpx
  768. border 2rpx solid #dde3ed
  769. border-radius 16rpx
  770. background #fff
  771. .q-option.selected
  772. border-color #1677ff
  773. background #e6f4ff
  774. .q-option-label
  775. width 48rpx
  776. height 48rpx
  777. line-height 48rpx
  778. text-align center
  779. border-radius 50%
  780. background #f4f6fa
  781. color #333
  782. font-size 24rpx
  783. font-weight 600
  784. margin-right 20rpx
  785. flex-shrink 0
  786. .q-option.selected .q-option-label
  787. background #1677ff
  788. color #fff
  789. .q-option-content
  790. flex 1
  791. font-size 26rpx
  792. color #333
  793. line-height 1.6
  794. .scroll-bottom-space
  795. height 200rpx
  796. .q-nav
  797. display flex
  798. background #fff
  799. border-top 1rpx solid #e8edf3
  800. flex-shrink 0
  801. .q-nav-btn
  802. flex 1
  803. height 88rpx
  804. line-height 88rpx
  805. text-align center
  806. font-size 28rpx
  807. color #1677ff
  808. .q-nav-btn.q-nav-btn-next
  809. border-left 1rpx solid #e8edf3
  810. .q-nav-btn.disabled
  811. color #ccc
  812. .exam-bottom
  813. padding 20rpx 24rpx
  814. padding-bottom calc(20rpx + env(safe-area-inset-bottom))
  815. background #fff
  816. border-top 1rpx solid #e8edf3
  817. flex-shrink 0
  818. .btn-primary
  819. background #1677ff
  820. color #fff
  821. border-radius 16rpx
  822. font-size 30rpx
  823. font-weight 600
  824. height 88rpx
  825. line-height 88rpx
  826. text-align center
  827. .result-shade
  828. position fixed
  829. top 0
  830. left 0
  831. right 0
  832. bottom 0
  833. background rgba(0,0,0,0.55)
  834. z-index 200
  835. display flex
  836. align-items center
  837. justify-content center
  838. .result-card
  839. width 580rpx
  840. background #fff
  841. border-radius 24rpx
  842. padding 40rpx 32rpx 32rpx
  843. display flex
  844. flex-direction column
  845. align-items center
  846. .result-score-wrap
  847. display flex
  848. align-items baseline
  849. line-height 1
  850. .result-score-num
  851. font-size 112rpx
  852. font-weight 900
  853. color #1857d4
  854. .result-score-unit
  855. font-size 30rpx
  856. font-weight 700
  857. color #1857d4
  858. margin-left 6rpx
  859. .result-score-label
  860. font-size 24rpx
  861. color #8896a7
  862. margin-top 4rpx
  863. margin-bottom 20rpx
  864. .result-pass-pill
  865. display inline-flex
  866. align-items center
  867. justify-content center
  868. border-radius 40rpx
  869. padding 8rpx 40rpx
  870. margin-bottom 28rpx
  871. .result-pass-pill.is-pass
  872. background #f6ffed
  873. .result-pass-pill.is-fail
  874. background #fff5f5
  875. .result-pass-text
  876. font-size 30rpx
  877. font-weight 700
  878. .result-pass-pill.is-pass .result-pass-text
  879. color #10a37f
  880. .result-pass-pill.is-fail .result-pass-text
  881. color #e53e3e
  882. .result-grid
  883. display flex
  884. width 100%
  885. gap 16rpx
  886. margin-bottom 24rpx
  887. .result-grid-item
  888. flex 1
  889. background #f4f6fa
  890. border-radius 16rpx
  891. padding 18rpx 12rpx
  892. text-align center
  893. .result-grid-label
  894. font-size 22rpx
  895. color #8896a7
  896. margin-bottom 8rpx
  897. .result-grid-value
  898. font-size 28rpx
  899. font-weight 500
  900. color #1a2233
  901. .result-stats
  902. width 100%
  903. background #f4f6fa
  904. border-radius 16rpx
  905. padding 22rpx 24rpx
  906. margin-bottom 28rpx
  907. box-sizing border-box
  908. .result-stats-row
  909. display flex
  910. justify-content space-between
  911. align-items center
  912. font-size 26rpx
  913. color #4a5568
  914. .result-stats-row + .result-stats-row
  915. margin-top 16rpx
  916. .result-stats-value
  917. font-weight 500
  918. .result-btns
  919. display flex
  920. width 100%
  921. gap 16rpx
  922. .result-btn
  923. flex 1
  924. height 80rpx
  925. line-height 80rpx
  926. text-align center
  927. border-radius 14rpx
  928. font-size 28rpx
  929. .result-btn-outline
  930. border 1rpx solid #1857d4
  931. color #1857d4
  932. .result-btn-primary
  933. border 1rpx solid #1857d4
  934. background #1857d4
  935. color #fff
  936. .result-cert
  937. display flex
  938. align-items center
  939. width 100%
  940. margin-top 24rpx
  941. padding 24rpx 20rpx
  942. background #f4f6fa
  943. border-radius 16rpx
  944. box-sizing border-box
  945. .result-cert-icon
  946. font-size 56rpx
  947. margin-right 20rpx
  948. .result-cert-info
  949. flex 1
  950. .result-cert-title
  951. font-size 28rpx
  952. font-weight 500
  953. color #1a2233
  954. margin-bottom 8rpx
  955. .result-cert-name
  956. font-size 24rpx
  957. color #8896a7
  958. .result-cert-btn
  959. display inline-block
  960. margin-top 12rpx
  961. padding 0 24rpx
  962. height 56rpx
  963. line-height 56rpx
  964. background #1857d4
  965. color #fff
  966. font-size 24rpx
  967. border-radius 10rpx
  968. .text-orange
  969. color #e67e22
  970. .text-green
  971. color #10a37f
  972. .text-red
  973. color #e53e3e
  974. .text-blue
  975. color #1857d4
  976. .empty-tip
  977. text-align center
  978. padding 80rpx 0
  979. color #aaa
  980. font-size 26rpx
  981. </style>