exam.vue 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. <template>
  2. <view class="phone-kaoshi-page">
  3. <customNavbarVue :title="data.ksName" :show-back-btn="true" @back="handleBack"></customNavbarVue>
  4. <!-- 第一行 -->
  5. <view class="kaoshi-page-title">
  6. <view v-if="activeSt" class="title-types">{{dlName}}</view>
  7. <!-- 倒计时 -->
  8. <view v-if="!!data.endSecond">
  9. <uni-countdown class="exam-countdown" :show-day="false" :showHour="true" :showMinute="true"
  10. :second="data.endSecond" @timeup="onTimeUp" :start="startCountDown"></uni-countdown>
  11. </view>
  12. </view>
  13. <view class="kaoshi-shiti-content">
  14. <!-- 内容区域 -->
  15. <!-- 试题区域 -->
  16. <view v-if="activeSt">
  17. <template v-if="activeSt.stTypeId == 1">
  18. <!-- 单选 -->
  19. <danxuan :question="activeSt" :key="activeSt.stId"></danxuan>
  20. </template>
  21. <template v-if="activeSt.stTypeId == 2">
  22. <!-- 多选 -->
  23. <duoxuan :question="activeSt" :key="activeSt.stId"></duoxuan>
  24. </template>
  25. <template v-if="activeSt.stTypeId == 3">
  26. <!-- 判断 -->
  27. <panduan :question="activeSt" :key="activeSt.stId"></panduan>
  28. </template>
  29. <template v-if="activeSt.stTypeId == 4">
  30. <!-- 填空 -->
  31. <tiankong :question="activeSt" :key="activeSt.stId"></tiankong>
  32. </template>
  33. <template v-if="activeSt.stTypeId == 5">
  34. <!-- 简答 -->
  35. <jianda :question="activeSt" :key="activeSt.stId"></jianda>
  36. </template>
  37. <template v-if="activeSt.stTypeId == 6">
  38. <!-- 阅读 -->
  39. <yuedu :question="activeSt" :key="activeSt.stId"></yuedu>
  40. </template>
  41. </view>
  42. </view>
  43. <view class="kaoshi-bottom-box" v-if="activeSt">
  44. <button class="phone-green-btn" :class="[activeSt.marked ? 'qb-btn' : 'bj-btn']" hover-class="none"
  45. type="default" size="mini" @click="handleBiaoji">{{activeSt && activeSt.marked ? '取标':'标记'}}</button>
  46. <view @click="showAnswerCard" class="shiti-num-box">
  47. <icon class="shiti-num-icon"></icon>
  48. <text class="active-num">{{answercartsCount}}</text>/<text>{{data.StListForSearch.length}}</text>
  49. </view>
  50. <view class="save-btn-box">
  51. <button class="phone-green-btn save-btn" hover-class="none" type="default" size="mini"
  52. @click="handleSave(true)">保存</button>
  53. <button @click="handleJiaojuan" class="phone-green-btn save-btn" hover-class="none" type="default"
  54. size="mini">
  55. 交卷并查看成绩</button>
  56. </view>
  57. </view>
  58. <template v-if="activeSt">
  59. <button type="default" size="mini" hover-class="none" class="phone-green-btn ks-btn-prev"
  60. @click="handlePrev" v-if="!isFistStId">上一题</button>
  61. <button type="default" size="mini" hover-class="none" class="phone-green-btn ks-btn-next"
  62. @click="handleNext" v-if="!isLastStId">下一题</button>
  63. </template>
  64. <!-- 答题卡 -->
  65. <uni-popup ref="popupRef" background-color="#fff" :animation="false" :is-mask-click="false" :mask-click="false">
  66. <view class="answer-card-popup">
  67. <customNavbarVue class="card-navBar-box" title="答题卡" :show-back-btn="true" @back="handlePopupBack">
  68. </customNavbarVue>
  69. <view class="card-content-box">
  70. <view class="answer-card-content" v-for="(paragraph,paragraphIndex) in questionData"
  71. :key="paragraphIndex">
  72. <view class="paragraph-title">
  73. {{paragraph.name}}
  74. </view>
  75. <view class="paragraph-qa" v-for="(qa,qaIndex) in paragraph.qas" :key="qaIndex"
  76. :class="getQaClass(qa)" @click="answerCardItemClick(qa)">{{qa.onlyNum}}
  77. </view>
  78. </view>
  79. </view>
  80. <view class="answer-card-btn-box">
  81. <view class="card-btn card-save-btn" @click="handleSave(true)">保存</view>
  82. <view @click="handleJiaojuan" class="card-btn card-jj-btn"> 交卷并查看成绩</view>
  83. </view>
  84. </view>
  85. </uni-popup>
  86. <!-- 交卷确认 -->
  87. <answerQueren ref="answerQrRef" @confirm="handleQuerenConfirm"></answerQueren>
  88. <!-- 考试得分 -->
  89. <submitScoreVue ref="subScoreRef" @confirm="handleScoreConfirm" @close="handleScoreClose"></submitScoreVue>
  90. <!-- 人工 -->
  91. <common-dialog ref="dl4ref" title="考试得分" :showNotBtn="false" content="等待人工评分结束后,可登录 “个人成绩” 模块,查看本次考试的成绩!"
  92. @confirm-btn="handleBack"></common-dialog>
  93. <!-- 直接出成绩 -->
  94. <common-dialog ref="dl3ref" title="考试得分" :showNotBtn="false"
  95. :content="`您的成绩,将在${seeResultTime}公布。您可以登录“个人成绩”模块,查看本次考试的成绩!`" @confirm-btn="handleBack"></common-dialog>
  96. <!-- 不发布成绩 -->
  97. <common-dialog ref="dl5ref" :showNotBtn="false" title="提示" content="交卷成功!"
  98. @confirm-btn="handleBack"></common-dialog>
  99. </view>
  100. </template>
  101. <script setup>
  102. import {
  103. ref,
  104. reactive,
  105. computed,
  106. watch,
  107. nextTick
  108. } from "vue";
  109. import zhuapaiVue from "@/components/zhuapaiConfirm/zhuapai.vue";
  110. import qiepingVue from "@/components/zhuapaiConfirm/qieping.vue";
  111. import zhuapaiConfirm from "@/components/zhuapaiConfirm/index.vue";
  112. import answerQueren from "@/components/zhuapaiConfirm/answerQueren.vue";
  113. import submitScoreVue from "@/components/zhuapaiConfirm/submitScore.vue";
  114. import {
  115. onLoad
  116. } from "@dcloudio/uni-app";
  117. import * as ksApi from "@/api/exam.js"
  118. import danxuan from "@/components/questions/danxuan.vue";
  119. import duoxuan from "@/components/questions/duoxuan.vue";
  120. import tiankong from "@/components/questions/tiankong.vue";
  121. import panduan from "@/components/questions/panduan.vue";
  122. import jianda from "@/components/questions/jianda.vue";
  123. import yuedu from "@/components/questions/yuedu.vue";
  124. import { useQuestionTools } from "@/utils/useQuestionTools.js";
  125. import {
  126. useKaoShiCache
  127. } from "./examTools"
  128. import qiepingDlVue from "@/components/dialog/qiepingDl.vue";
  129. import customNavbarVue from "@/components/custom-navbar/custom-navbar.vue";
  130. import commonDialog from "@/components/dialog/commonDialog.vue"
  131. const {
  132. checkDanxuanReply,
  133. checkDuoxuanReply,
  134. checkPanduanReply,
  135. checkTiankongReply,
  136. getLetterByIndex,
  137. checkJiandaReply,
  138. checkYueduReply
  139. } = useQuestionTools();
  140. const {
  141. saveCacheKs,
  142. getCacheKs,
  143. removeCacheKs
  144. } = useKaoShiCache();
  145. onLoad((option) => {
  146. data.ksId = option.ksId;
  147. data.zhuapai = option.zhuapai;
  148. if (data.zhuapai && data.zhuapai != 0) {
  149. // 考试前确认摄像头
  150. nextTick(() => {
  151. // initBeforKaoshi();
  152. })
  153. } else {
  154. console.log('初始化')
  155. initKaoshi();
  156. }
  157. })
  158. const popupRef = ref(null)
  159. const zhuapaiRef = ref(null)
  160. const qiepingRef = ref(null)
  161. const zhuapaiConfirmRef = ref(null)
  162. const answerQrRef = ref(null);
  163. const startCountDown = ref(false);
  164. const subScoreRef = ref(null);
  165. const messageContent = ref('');
  166. const qiepingDlRef = ref(null);
  167. const timer1 = ref(null);
  168. const answercartsCount = ref(0); // 已答题数
  169. const dl3ref = ref(null)
  170. const dl4ref = ref(null)
  171. const dl5ref = ref(null)
  172. const seeResultTime = ref(null)
  173. const autoSaveInterval = ref(null)
  174. const autoSaveInterval2 = ref(null)
  175. const data = reactive({
  176. ksId: null,
  177. operId: null,
  178. ksName: '',
  179. stTotal: 0,
  180. stScore: 0,
  181. biaoji: {},
  182. endSecond: 0,
  183. pageSize: 0,
  184. toggleScreenFlag: 0,
  185. toggleScreenSecond: 0,
  186. zhuapai: 0,
  187. duanluo: [],
  188. StListForSearch: [],
  189. from: '',
  190. hisId: '',
  191. })
  192. const markDB = ref([]);
  193. const questionData = ref([]);
  194. const progress = reactive({
  195. dlIndex: 0,
  196. dtIndex: 0
  197. })
  198. const dlName = computed(() => {
  199. if (data.StListForSearch && activeSt.value) {
  200. return data.StListForSearch[activeSt.value.onlyNum - 1].paragraphName
  201. } else {
  202. return ''
  203. }
  204. })
  205. watch(() => questionData, (newVal) => {
  206. // 计算已答试题数量
  207. renderPage(newVal);
  208. }, {
  209. deep: true
  210. })
  211. function renderPage(data) {
  212. let count = 0;
  213. for (const paragraph of data.value) {
  214. for (const qa of paragraph.qas) {
  215. if (qa.stTypeId == 1) {
  216. if (checkDanxuanReply(qa)) {
  217. count++;
  218. }
  219. } else if (qa.stTypeId == 2) {
  220. if (checkDuoxuanReply(qa)) {
  221. count++;
  222. }
  223. } else if (qa.stTypeId == 3) {
  224. if (checkPanduanReply(qa)) {
  225. count++;
  226. }
  227. } else if (qa.stTypeId == 4) {
  228. if (checkTiankongReply(qa)) {
  229. count++;
  230. }
  231. } else if (qa.stTypeId == 5) {
  232. if (checkJiandaReply(qa)) {
  233. count++;
  234. }
  235. } else if (qa.stTypeId == 4) {
  236. if (checkYueduReply(qa)) {
  237. count++;
  238. }
  239. }
  240. }
  241. }
  242. answercartsCount.value = count;
  243. }
  244. const activeSt = computed(() => {
  245. if (questionData.value.length) {
  246. return questionData.value.length && questionData.value[progress.dlIndex].qas[progress.dtIndex];
  247. } else {
  248. return null
  249. }
  250. })
  251. const isFistStId = computed(() => {
  252. if (data.StListForSearch.length) {
  253. return data.StListForSearch[0].stId == activeSt.value.stId
  254. } else {
  255. return false
  256. }
  257. });
  258. const isLastStId = computed(() => {
  259. if (data.StListForSearch.length) {
  260. return data.StListForSearch[data.StListForSearch.length - 1].stId == activeSt.value.stId
  261. } else {
  262. return false
  263. }
  264. });
  265. function handleScoreClose() {
  266. handleBack()
  267. }
  268. // 考试得分相关 start
  269. function handleScoreConfirm() {
  270. // 跳转成绩
  271. uni.redirectTo({
  272. url: `/pages/score/kaoshiChengjiInfo?hisId=${data.hisId}`
  273. })
  274. }
  275. // 考试得分相关 end
  276. // 保存相关
  277. function handleSave(showToast) {
  278. if (timer1.value) {
  279. uni.showToast({
  280. title: '请勿连续保存',
  281. icon: 'none'
  282. })
  283. return
  284. }
  285. timer1.value = setTimeout(() => {
  286. clearTimeout(timer1.value);
  287. }, 10 * 1000);
  288. const result = []
  289. const option = {
  290. operId: data.operId,
  291. replyList: []
  292. }
  293. questionData.value.forEach(dl => {
  294. dl.qas.forEach(qa => {
  295. console.log('qa:', qa)
  296. if (qa.stTypeId == 5) {
  297. const opt = {
  298. stId: qa.stId,
  299. files: qa.files,
  300. reply: qa.reply,
  301. }
  302. result.push(opt)
  303. option.replyList.push(opt)
  304. } else if (qa.stTypeId != 6) {
  305. const opt = {
  306. stId: qa.stId,
  307. reply: qa.reply,
  308. }
  309. result.push(opt)
  310. option.replyList.push(opt)
  311. } else {
  312. // 阅读题
  313. let danxuanArr = [];
  314. for (const iDanxuan of qa.danxuan) {
  315. danxuanArr.push(iDanxuan.reply);
  316. }
  317. let duoxuanArr = [];
  318. for (const iDuoxuan of qa.duoxuan) {
  319. duoxuanArr.push(iDuoxuan.reply);
  320. }
  321. let panduanArr = [];
  322. for (const iPanduan of qa.panduan) {
  323. panduanArr.push(iPanduan.reply);
  324. }
  325. let tiankongArr = [];
  326. for (const iTiankong of qa.tiankong) {
  327. tiankongArr.push(iTiankong.reply);
  328. }
  329. let jiandaArr = [];
  330. for (const iJianda of qa.jianda) {
  331. const c = {
  332. files: iJianda.files,
  333. reply: iJianda.reply,
  334. };
  335. jiandaArr.push(c);
  336. }
  337. result.push({
  338. reply: {
  339. danxuan: danxuanArr,
  340. duoxuan: duoxuanArr,
  341. panduan: panduanArr,
  342. tiankong: tiankongArr,
  343. jianda: jiandaArr,
  344. },
  345. stId: qa.stId,
  346. })
  347. option.replyList.push({
  348. reply: {
  349. danxuan: danxuanArr,
  350. duoxuan: duoxuanArr,
  351. panduan: panduanArr,
  352. tiankong: tiankongArr,
  353. jianda: jiandaArr,
  354. },
  355. stId: qa.stId,
  356. });
  357. }
  358. })
  359. })
  360. // 保存试题答案
  361. saveCacheKs(data.operId, {
  362. replyList: result,
  363. position: {
  364. dlIndex: progress.dlIndex,
  365. dtIndex: progress.dtIndex
  366. }
  367. })
  368. // 保存答题进度
  369. ksApi.getClientKsSave(option).then(res => {
  370. if (res.data && showToast) {
  371. uni.showToast({
  372. title: '保存成功',
  373. })
  374. }
  375. })
  376. }
  377. // 交卷相关功能 start
  378. function checkJiaojuan() {
  379. const result = []
  380. let count = 0;
  381. let total = 0;
  382. questionData.value.forEach(item => {
  383. item.qas.forEach(qa => {
  384. total++;
  385. if (qa.stTypeId == 1 && !checkDanxuanReply(qa)) {
  386. count++;
  387. }
  388. if (qa.stTypeId == 2 && !checkDuoxuanReply(qa)) {
  389. count++;
  390. }
  391. if (qa.stTypeId == 3 && !checkPanduanReply(qa)) {
  392. count++;
  393. }
  394. if (qa.stTypeId == 4 && !checkTiankongReply(qa)) {
  395. count++;
  396. }
  397. if (qa.stTypeId == 5 && !checkJiandaReply(qa)) {
  398. count++;
  399. }
  400. if (qa.stTypeId == 6 && !checkYueduReply(qa)) {
  401. count++;
  402. }
  403. })
  404. })
  405. return {
  406. total,
  407. count,
  408. }
  409. }
  410. function handleJiaojuan() {
  411. const result = checkJiaojuan()
  412. if (result.count) {
  413. // 提示
  414. answerQrRef.value.showDialog({
  415. answercartsCount: result.total - result.count,
  416. answercartsTotal: result.total,
  417. })
  418. } else {
  419. handleSubmit()
  420. }
  421. }
  422. function handleQuerenConfirm() {
  423. handleSubmit()
  424. }
  425. function handleSubmit(force = false) {
  426. const result = {
  427. force,
  428. operId: data.operId,
  429. replyList: []
  430. };
  431. questionData.value.forEach(dl => {
  432. dl.qas.forEach(st => {
  433. if (st.stTypeId == 5) {
  434. // 简答题
  435. const opt = {
  436. stId: st.stId,
  437. reply: st.reply,
  438. files: st.files,
  439. }
  440. result.replyList.push(opt)
  441. } else if (st.stTypeId == 6) {
  442. // 阅读题
  443. // 阅读题
  444. let danxuanArr = [];
  445. for (const iDanxuan of st.danxuan) {
  446. danxuanArr.push(iDanxuan.reply);
  447. }
  448. let duoxuanArr = [];
  449. for (const iDuoxuan of st.duoxuan) {
  450. duoxuanArr.push(iDuoxuan.reply);
  451. }
  452. let panduanArr = [];
  453. for (const iPanduan of st.panduan) {
  454. panduanArr.push(iPanduan.reply);
  455. }
  456. let tiankongArr = [];
  457. for (const iTiankong of st.tiankong) {
  458. tiankongArr.push(iTiankong.reply);
  459. }
  460. let jiandaArr = [];
  461. for (const iJianda of st.jianda) {
  462. const c = {
  463. files: iJianda.files,
  464. reply: iJianda.reply,
  465. };
  466. jiandaArr.push(c);
  467. }
  468. result.replyList.push({
  469. reply: {
  470. danxuan: danxuanArr,
  471. duoxuan: duoxuanArr,
  472. panduan: panduanArr,
  473. tiankong: tiankongArr,
  474. jianda: jiandaArr,
  475. },
  476. stId: st.stId,
  477. })
  478. } else {
  479. // 其他
  480. const opt = {
  481. stId: st.stId,
  482. reply: st.reply
  483. }
  484. result.replyList.push(opt)
  485. }
  486. })
  487. })
  488. ksApi.getClientKsSubmit(result).then(res => {
  489. if (res.code == 0) {
  490. let data1 = res.data;
  491. console.log('data1',data1)
  492. console.log('data1.waitGrade === false',data1.waitGrade === false)
  493. // 清空缓存
  494. removeCacheKs(data1.operId);
  495. if (data1.waitGrade == false) {
  496. // describe:修改bug seeResultFlag 发布成绩标记(0不发布、1立即发布、2定时发布)
  497. if (data1.seeResultFlag === 1) {
  498. subScoreRef.value.showDialog(data1);
  499. data.hisId = data1.hisId;
  500. } else if (data1.seeResultFlag === 0) {
  501. dl5ref.value.handleShow();
  502. } else {
  503. // dialog3
  504. seeResultTime.value = data1.seeResultTime;
  505. dl3ref.value.handleShow()
  506. }
  507. } else {
  508. // dialog4
  509. dl4ref.value.handleShow()
  510. }
  511. clearInterval(autoSaveInterval.value)
  512. clearInterval(autoSaveInterval2.value)
  513. }
  514. })
  515. }
  516. function onTimeUp() {
  517. handleSubmit();
  518. }
  519. // 交卷相关功能 end
  520. // 切屏功能 start
  521. function qiepingToast(count) {
  522. messageContent.value = `已离开${count}次。${data.toggleScreenFlag}次将自动交卷!`
  523. qiepingDlRef.value.handleShow()
  524. }
  525. function forceSubmit() {
  526. // 强制交卷
  527. console.log('强制交卷')
  528. handleSubmit(true)
  529. }
  530. function qpZhuapai() {
  531. // 重新开启抓拍
  532. zhuapaiRef.value && zhuapaiRef.value.showVideoBtn();
  533. }
  534. // 切屏功能 end
  535. // 摄像头抓拍相关功能 start
  536. function zpSuccess() {}
  537. function zpError() {
  538. uni.showToast({
  539. title: '抓拍图片异常',
  540. icon: 'none'
  541. })
  542. handleBack()
  543. }
  544. // 摄像头抓拍相关功能 end
  545. // 摄像头确认相关功能 start
  546. function onProgress() {
  547. uni.showToast({
  548. icon: 'none',
  549. title: '摄像头运行环境异常,请重新进入考试',
  550. duration: 8000
  551. })
  552. handleBack();
  553. }
  554. function zpConfirmSuccess() {
  555. console.log('zpConfirmSuccess')
  556. initKaoshi();
  557. }
  558. function zpConfirmError() {
  559. handleBack()
  560. }
  561. function zpConfirmCancel() {
  562. handleBack()
  563. }
  564. // 摄像头确认相关功能 end
  565. function getQaClass(qa) {
  566. if (qa.marked && qa.marked === true) {
  567. return 'paragraph-qa-block-mark';
  568. } else {
  569. if (qa.stTypeId == 1) {
  570. if (checkDanxuanReply(qa)) {
  571. return 'paragraph-qa-block-done';
  572. } else {
  573. return 'paragraph-qa-block-init';
  574. }
  575. } else if (qa.stTypeId == 2) {
  576. if (checkDuoxuanReply(qa)) {
  577. return 'paragraph-qa-block-done';
  578. } else {
  579. return 'paragraph-qa-block-init';
  580. }
  581. } else if (qa.stTypeId == 3) {
  582. if (checkPanduanReply(qa)) {
  583. return 'paragraph-qa-block-done';
  584. } else {
  585. return 'paragraph-qa-block-init';
  586. }
  587. } else if (qa.stTypeId == 4) {
  588. if (checkTiankongReply(qa)) {
  589. return 'paragraph-qa-block-done';
  590. } else {
  591. return 'paragraph-qa-block-init';
  592. }
  593. } else if (qa.stTypeId == 5) {
  594. if (checkJiandaReply(qa)) {
  595. return 'paragraph-qa-block-done';
  596. } else {
  597. return 'paragraph-qa-block-init';
  598. }
  599. } else if (qa.stTypeId == 6) {
  600. if (checkYueduReply(qa)) {
  601. return 'paragraph-qa-block-done';
  602. } else {
  603. return 'paragraph-qa-block-init';
  604. }
  605. }
  606. }
  607. }
  608. function skipQuestion(dlIndex, dtIndex) {
  609. progress.dlIndex = dlIndex;
  610. progress.dtIndex = dtIndex;
  611. handlePopupBack()
  612. }
  613. function answerCardItemClick(qa) {
  614. const actQa = data.StListForSearch.find(item => item.stId == qa.stId);
  615. console.log('actQa', actQa)
  616. skipQuestion(actQa.dlIndex, actQa.dtIndex)
  617. }
  618. function handleBack() {
  619. // const pages = getCurrentPages();
  620. // if (pages.length > 1) {
  621. // uni.navigateBack()
  622. // } else {
  623. // history.back();
  624. // }
  625. uni.navigateBack()
  626. autoSaveInterval.value && clearInterval(autoSaveInterval.value)
  627. autoSaveInterval2.value && clearInterval(autoSaveInterval2.value)
  628. }
  629. function showAnswerCard() {
  630. popupRef.value.open('top')
  631. }
  632. function handlePopupBack() {
  633. popupRef.value.close()
  634. }
  635. function handlePrev() {
  636. const qa = data.StListForSearch.find(item => item.stId == activeSt.value.stId);
  637. const index = qa.onlyNum - 1;
  638. if (index > 0) {
  639. const result = data.StListForSearch[index - 1];
  640. progress.dlIndex = result.dlIndex;
  641. progress.dtIndex = result.dtIndex
  642. }
  643. }
  644. function handleNext() {
  645. const qa = data.StListForSearch.find(item => item.stId == activeSt.value.stId);
  646. const index = qa.onlyNum - 1;
  647. if (index < data.StListForSearch.length) {
  648. const result = data.StListForSearch[index + 1];
  649. progress.dlIndex = result.dlIndex;
  650. progress.dtIndex = result.dtIndex
  651. }
  652. }
  653. function formatDuanluoList(dlData) {
  654. let uIndex = 0; // 试题onlyNum
  655. let iDuanluo = 0; // 段落onlyNum
  656. let result = [];
  657. for (const duanluo of data.duanluo) {
  658. let paragraph = {
  659. qas: [],
  660. };
  661. paragraph.name = duanluo.name;
  662. let iQa = 0; // 当前试题序号
  663. let order = 0; // 当前题型中第几题
  664. for (const iDanxuan of duanluo.danxuan) {
  665. iDanxuan.type = 'danxuan';
  666. iDanxuan.marked = data.biaoji[iDanxuan.stId] ? true : false;
  667. iDanxuan.onlyNum = uIndex + 1;
  668. iDanxuan.order = order;
  669. iDanxuan.iQa = iQa;
  670. paragraph.qas.push(iDanxuan);
  671. uIndex++;
  672. order++;
  673. iQa++;
  674. data.StListForSearch.push({
  675. stId: iDanxuan.stId,
  676. paragraphName: paragraph.name,
  677. dlIndex: iDuanluo,
  678. dtIndex: iDanxuan.iQa,
  679. onlyNum: iDanxuan.onlyNum
  680. })
  681. }
  682. order = 0;
  683. for (const iDuoxuan of duanluo.duoxuan) {
  684. iDuoxuan.type = 'duoxuan';
  685. iDuoxuan.marked = data.biaoji[iDuoxuan.stId] ? true : false;
  686. iDuoxuan.onlyNum = uIndex + 1;
  687. iDuoxuan.order = order;
  688. paragraph.qas.push(iDuoxuan);
  689. iDuoxuan.iQa = iQa;
  690. iDuoxuan.reply = [];
  691. uIndex++;
  692. order++;
  693. iQa++;
  694. data.StListForSearch.push({
  695. stId: iDuoxuan.stId,
  696. paragraphName: paragraph.name,
  697. dlIndex: iDuanluo,
  698. dtIndex: iDuoxuan.iQa,
  699. onlyNum: iDuoxuan.onlyNum
  700. })
  701. }
  702. order = 0;
  703. for (const iPanduan of duanluo.panduan) {
  704. iPanduan.type = 'panduan';
  705. iPanduan.marked = data.biaoji[iPanduan.stId] ? true : false;
  706. iPanduan.onlyNum = uIndex + 1;
  707. iPanduan.order = order;
  708. paragraph.qas.push(iPanduan);
  709. iPanduan.iQa = iQa;
  710. uIndex++;
  711. order++;
  712. iQa++;
  713. data.StListForSearch.push({
  714. stId: iPanduan.stId,
  715. paragraphName: paragraph.name,
  716. dlIndex: iDuanluo,
  717. dtIndex: iPanduan.iQa,
  718. onlyNum: iPanduan.onlyNum
  719. })
  720. }
  721. order = 0;
  722. for (const iTiankong of duanluo.tiankong) {
  723. iTiankong.type = 'tiankong';
  724. iTiankong.marked = data.biaoji[iTiankong.stId] ? true : false;
  725. iTiankong.onlyNum = uIndex + 1;
  726. iTiankong.order = order;
  727. paragraph.qas.push(iTiankong);
  728. iTiankong.iQa = iQa;
  729. iTiankong.reply = new Array(iTiankong.count).fill('');
  730. uIndex++;
  731. order++;
  732. iQa++;
  733. data.StListForSearch.push({
  734. stId: iTiankong.stId,
  735. paragraphName: paragraph.name,
  736. dlIndex: iDuanluo,
  737. dtIndex: iTiankong.iQa,
  738. onlyNum: iTiankong.onlyNum
  739. })
  740. }
  741. order = 0;
  742. for (const iJianda of duanluo.jianda) {
  743. iJianda.marked = data.biaoji[iJianda.stId] ? true : false;
  744. iJianda.type = 'jianda';
  745. iJianda.onlyNum = uIndex + 1;
  746. iJianda.order = order;
  747. iJianda.iQa = iQa;
  748. paragraph.qas.push(iJianda);
  749. iJianda.reply = '';
  750. uIndex++;
  751. order++;
  752. iQa++;
  753. data.StListForSearch.push({
  754. stId: iJianda.stId,
  755. paragraphName: paragraph.name,
  756. dlIndex: iDuanluo,
  757. dtIndex: iJianda.iQa,
  758. onlyNum: iJianda.onlyNum
  759. })
  760. }
  761. order = 0;
  762. for (const iYuedu of duanluo.yuedu) {
  763. iYuedu.marked = data.biaoji[iYuedu.stId] ? true : false;
  764. iYuedu.type = 'yuedu';
  765. iYuedu.onlyNum = uIndex + 1;
  766. iYuedu.order = order;
  767. iYuedu.iQa = iQa;
  768. if (iYuedu.duoxuan && iYuedu.duoxuan.length) {
  769. iYuedu.duoxuan.map((qIt) => {
  770. qIt.reply = qIt.reply || [];
  771. return qIt
  772. })
  773. }
  774. if (iYuedu.tiankong && iYuedu.tiankong.length) {
  775. iYuedu.tiankong.map((qIt) => {
  776. qIt.reply = new Array(qIt.count).fill('');
  777. return qIt;
  778. });
  779. }
  780. paragraph.qas.push(iYuedu);
  781. iYuedu.reply = [];
  782. uIndex++;
  783. order++;
  784. iQa++;
  785. data.StListForSearch.push({
  786. stId: iYuedu.stId,
  787. paragraphName: paragraph.name,
  788. dlIndex: iDuanluo,
  789. dtIndex: iYuedu.iQa,
  790. onlyNum: iYuedu.onlyNum
  791. })
  792. }
  793. iDuanluo++;
  794. questionData.value.push(paragraph)
  795. }
  796. }
  797. function handleBiaoji() {
  798. activeSt.value.marked = !activeSt.value.marked;
  799. data.biaoji[activeSt.value.stId] = activeSt.value.marked
  800. ksApi.getClientKaoshiBiaoji({
  801. operId: data.operId,
  802. biaoji: JSON.stringify(data.biaoji)
  803. }).catch(err => {
  804. /* uni.redirectTo({
  805. url: '/pages/client/Kaoshi/list'
  806. }) */
  807. setTimeout(() => {
  808. handleBack()
  809. }, 1000)
  810. })
  811. }
  812. function formatKaoshiData() {
  813. const historyData = getCacheKs(data.operId);
  814. if (historyData) {
  815. const {
  816. replyList,
  817. position
  818. } = historyData;
  819. if (replyList) {
  820. questionData.value.forEach(dl => {
  821. dl.qas.forEach(st => {
  822. if (st.stTypeId == 5) {
  823. // 简答题
  824. st.reply = replyList.find(item => item.stId == st.stId).reply;
  825. st.files = replyList.find(item => item.stId == st.stId).files;
  826. } else if (st.stTypeId != 6) {
  827. st.reply = replyList.find(item => item.stId == st.stId).reply
  828. } else {
  829. // 阅读题
  830. const hisSt = replyList.find(item => item.stId == st.stId);
  831. if (hisSt) {
  832. st.danxuan.forEach((itm, index) => {
  833. itm.reply = hisSt.reply['danxuan'][index];
  834. })
  835. st.duoxuan.forEach((itm, index) => {
  836. itm.reply = hisSt.reply['duoxuan'][index];
  837. })
  838. st.panduan.forEach((itm, index) => {
  839. itm.reply = hisSt.reply['panduan'][index];
  840. })
  841. st.tiankong.forEach((itm, index) => {
  842. itm.reply = hisSt.reply['tiankong'][index];
  843. })
  844. st.jianda.forEach((itm, index) => {
  845. itm.reply = hisSt.reply['jianda'][index].reply;
  846. itm.files = hisSt.reply['jianda'][index].files;
  847. })
  848. }
  849. }
  850. })
  851. })
  852. }
  853. if (position) {
  854. progress.dlIndex = position.dlIndex;
  855. progress.dtIndex = position.dtIndex;
  856. }
  857. }
  858. }
  859. // 摄像头确认初始化
  860. function initBeforKaoshi() {
  861. console.log(zhuapaiConfirmRef.value)
  862. zhuapaiConfirmRef.value.showDialog()
  863. }
  864. function initKaoshi() {
  865. ksApi.getClientKsStart({
  866. ksId: data.ksId,
  867. }).then(res => {
  868. const {
  869. ksId,
  870. operId,
  871. ksName,
  872. stTotal,
  873. stScore,
  874. biaoji,
  875. endSecond,
  876. pageSize,
  877. toggleScreenFlag,
  878. toggleScreenSecond,
  879. zhuapai,
  880. duanluoList
  881. } = res.data;
  882. data.ksId = ksId;
  883. data.operId = operId;
  884. data.ksName = ksName;
  885. data.stTotal = stTotal;
  886. data.stScore = stScore;
  887. data.biaoji = biaoji ? JSON.parse(biaoji) : {};
  888. data.endSecond = endSecond;
  889. data.pageSize = pageSize;
  890. data.toggleScreenFlag = toggleScreenFlag;
  891. data.toggleScreenSecond = toggleScreenSecond;
  892. // data.zhuapai = zhuapai;
  893. data.duanluo = duanluoList;
  894. formatDuanluoList(data.duanluo);
  895. // 设置缓存
  896. formatKaoshiData();
  897. autoSaveInterval.value = setInterval(() => {
  898. handleSave()
  899. }, 1000 * 60 * 1)
  900. autoSaveInterval2.value = setInterval(() => {
  901. handleSave()
  902. }, 1000 * 60 * 5)
  903. startCountDown.value = true;
  904. uni.setNavigationBarTitle({
  905. title: data.ksName
  906. });
  907. }).catch(err => {
  908. console.log('asdasd', err)
  909. setTimeout(() => {
  910. handleBack()
  911. }, 1000)
  912. })
  913. }
  914. </script>