exam.vue 24 KB

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