exam.vue 25 KB

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