exam.vue 24 KB

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