exam.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  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" :second="data.endSecond"
  10. @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" type="default" size="mini"
  45. @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" size="mini">
  54. 交卷并查看成绩</button>
  55. </view>
  56. </view>
  57. <template v-if="activeSt">
  58. <button type="default" size="mini" hover-class="none" class="phone-green-btn ks-btn-prev"
  59. @click="handlePrev" v-if="!isFistStId">上一题</button>
  60. <button type="default" size="mini" hover-class="none" class="phone-green-btn ks-btn-next"
  61. @click="handleNext" v-if="!isLastStId">下一题</button>
  62. </template>
  63. <!-- 答题卡 -->
  64. <uni-popup ref="popupRef" background-color="#fff" :animation="false" :is-mask-click="false" :mask-click="false">
  65. <view class="answer-card-popup">
  66. <customNavbarVue class="card-navBar-box" title="答题卡" :show-back-btn="true" @back="handlePopupBack"></customNavbarVue>
  67. <view class="card-content-box">
  68. <view class="answer-card-content" v-for="(paragraph,paragraphIndex) in questionData"
  69. :key="paragraphIndex">
  70. <view class="paragraph-title">
  71. {{paragraph.name}}
  72. </view>
  73. <view class="paragraph-qa" v-for="(qa,qaIndex) in paragraph.qas" :key="qaIndex"
  74. :class="getQaClass(qa)" @click="answerCardItemClick(qa)">{{qa.onlyNum}}
  75. </view>
  76. </view>
  77. </view>
  78. <view class="answer-card-btn-box">
  79. <view class="card-btn card-save-btn" @click="handleSave(true)">保存</view>
  80. <view @click="handleJiaojuan" class="card-btn card-jj-btn"> 交卷并查看成绩</view>
  81. </view>
  82. </view>
  83. </uni-popup>
  84. <!-- 摄像头确认 -->
  85. <!-- <zhuapaiConfirm ref="zhuapaiConfirmRef" @success="zpConfirmSuccess" @error="zpConfirmError"
  86. @cancel="zpConfirmCancel" key="1"></zhuapaiConfirm> -->
  87. <!-- <template v-if="data.zhuapai && data.zhuapai > 0"> -->
  88. <!-- 抓拍 -->
  89. <!-- <zhuapaiVue ref="zhuapaiRef" @error="zpError" @success="zpSuccess" key="2" @progress="onProgress"></zhuapaiVue> -->
  90. <!-- </template> -->
  91. <!-- 切屏 -->
  92. <!-- <qiepingVue ref="qiepingRef" @zhuapai="qpZhuapai" @forceSubmit="forceSubmit" @qiepingToast="qiepingToast"
  93. key="3"></qiepingVue> -->
  94. <!-- 交卷确认 -->
  95. <answerQueren ref="answerQrRef" @confirm="handleQuerenConfirm"></answerQueren>
  96. <!-- 考试得分 -->
  97. <submitScoreVue ref="subScoreRef" @confirm="handleScoreConfirm" @close="handleScoreClose"></submitScoreVue>
  98. <!-- 切屏确认弹窗 -->
  99. <!-- <qiepingDlVue ref="qiepingDlRef" :content="messageContent" title="注意" okBtn="知道了"></qiepingDlVue> -->
  100. </view>
  101. </template>
  102. <script setup>
  103. import {
  104. ref,
  105. reactive,
  106. computed,
  107. watch,
  108. nextTick
  109. } from "vue";
  110. import zhuapaiVue from "@/components/zhuapaiConfirm/zhuapai.vue";
  111. import qiepingVue from "@/components/zhuapaiConfirm/qieping.vue";
  112. import zhuapaiConfirm from "@/components/zhuapaiConfirm/index.vue";
  113. import answerQueren from "@/components/zhuapaiConfirm/answerQueren.vue";
  114. import submitScoreVue from "@/components/zhuapaiConfirm/submitScore.vue";
  115. import {
  116. onLoad
  117. } from "@dcloudio/uni-app";
  118. import * as ksApi from "@/api/exam.js"
  119. import danxuan from "@/components/questions/danxuan.vue";
  120. import duoxuan from "@/components/questions/duoxuan.vue";
  121. import tiankong from "@/components/questions/tiankong.vue";
  122. import panduan from "@/components/questions/panduan.vue";
  123. import jianda from "@/components/questions/jianda.vue";
  124. import yuedu from "@/components/questions/yuedu.vue";
  125. import {
  126. useQuestionTools
  127. } from "@/components/questions/useQuestionTools.js";
  128. import {
  129. useKaoShiCache
  130. } from "./examTools"
  131. import qiepingDlVue from "@/components/dialog/qiepingDl.vue";
  132. import customNavbarVue from "@/components/custom-navbar/custom-navbar.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 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. console.log(questionData.value)
  285. const result = []
  286. const option = {
  287. operId: data.operId,
  288. replyList: []
  289. }
  290. questionData.value.forEach(dl => {
  291. dl.qas.forEach(qa => {
  292. console.log('qa:', qa)
  293. if (qa.stTypeId == 5) {
  294. const opt = {
  295. stId: qa.stId,
  296. files: qa.files,
  297. reply: qa.reply,
  298. }
  299. result.push(opt)
  300. option.replyList.push(opt)
  301. } else if (qa.stTypeId != 6) {
  302. const opt = {
  303. stId: qa.stId,
  304. reply: qa.reply,
  305. }
  306. result.push(opt)
  307. option.replyList.push(opt)
  308. } else {
  309. // 阅读题
  310. let danxuanArr = [];
  311. for (const iDanxuan of qa.danxuan) {
  312. danxuanArr.push(iDanxuan.reply);
  313. }
  314. let duoxuanArr = [];
  315. for (const iDuoxuan of qa.duoxuan) {
  316. duoxuanArr.push(iDuoxuan.reply);
  317. }
  318. let panduanArr = [];
  319. for (const iPanduan of qa.panduan) {
  320. panduanArr.push(iPanduan.reply);
  321. }
  322. let tiankongArr = [];
  323. for (const iTiankong of qa.tiankong) {
  324. tiankongArr.push(iTiankong.reply);
  325. }
  326. let jiandaArr = [];
  327. for (const iJianda of qa.jianda) {
  328. const c = {
  329. files: iJianda.files,
  330. reply: iJianda.reply,
  331. };
  332. jiandaArr.push(c);
  333. }
  334. result.push({
  335. reply: {
  336. danxuan: danxuanArr,
  337. duoxuan: duoxuanArr,
  338. panduan: panduanArr,
  339. tiankong: tiankongArr,
  340. jianda: jiandaArr,
  341. },
  342. stId: qa.stId,
  343. })
  344. option.replyList.push({
  345. reply: {
  346. danxuan: danxuanArr,
  347. duoxuan: duoxuanArr,
  348. panduan: panduanArr,
  349. tiankong: tiankongArr,
  350. jianda: jiandaArr,
  351. },
  352. stId: qa.stId,
  353. });
  354. }
  355. })
  356. })
  357. // 保存试题答案
  358. saveCacheKs(data.operId, {
  359. replyList: result,
  360. position: {
  361. dlIndex: progress.dlIndex,
  362. dtIndex: progress.dtIndex
  363. }
  364. })
  365. // 保存答题进度
  366. ksApi.getClientKsSave(option).then(res => {
  367. if (res.data && showToast) {
  368. uni.showToast({
  369. title: '保存成功',
  370. })
  371. }
  372. })
  373. }
  374. // 交卷相关功能 start
  375. function checkJiaojuan() {
  376. const result = []
  377. let count = 0;
  378. let total = 0;
  379. questionData.value.forEach(item => {
  380. item.qas.forEach(qa => {
  381. total++;
  382. if (qa.stTypeId == 1 && !checkDanxuanReply(qa)) {
  383. count++;
  384. }
  385. if (qa.stTypeId == 2 && !checkDuoxuanReply(qa)) {
  386. count++;
  387. }
  388. if (qa.stTypeId == 3 && !checkPanduanReply(qa)) {
  389. count++;
  390. }
  391. if (qa.stTypeId == 4 && !checkTiankongReply(qa)) {
  392. count++;
  393. }
  394. if (qa.stTypeId == 5 && !checkJiandaReply(qa)) {
  395. count++;
  396. }
  397. if (qa.stTypeId == 6 && !checkYueduReply(qa)) {
  398. count++;
  399. }
  400. })
  401. })
  402. return {
  403. total,
  404. count,
  405. }
  406. }
  407. function handleJiaojuan() {
  408. const result = checkJiaojuan()
  409. if (result.count) {
  410. // 提示
  411. answerQrRef.value.showDialog({
  412. answercartsCount: result.total - result.count,
  413. answercartsTotal: result.total,
  414. })
  415. } else {
  416. handleSubmit()
  417. }
  418. }
  419. function handleQuerenConfirm() {
  420. handleSubmit()
  421. }
  422. function handleSubmit(force = false) {
  423. const result = {
  424. force,
  425. operId: data.operId,
  426. replyList: []
  427. };
  428. questionData.value.forEach(dl => {
  429. dl.qas.forEach(st => {
  430. if (st.stTypeId == 5) {
  431. // 简答题
  432. const opt = {
  433. stId: st.stId,
  434. reply: st.reply,
  435. files: st.files,
  436. }
  437. result.replyList.push(opt)
  438. } else if (st.stTypeId == 6) {
  439. // 阅读题
  440. // 阅读题
  441. let danxuanArr = [];
  442. for (const iDanxuan of st.danxuan) {
  443. danxuanArr.push(iDanxuan.reply);
  444. }
  445. let duoxuanArr = [];
  446. for (const iDuoxuan of st.duoxuan) {
  447. duoxuanArr.push(iDuoxuan.reply);
  448. }
  449. let panduanArr = [];
  450. for (const iPanduan of st.panduan) {
  451. panduanArr.push(iPanduan.reply);
  452. }
  453. let tiankongArr = [];
  454. for (const iTiankong of st.tiankong) {
  455. tiankongArr.push(iTiankong.reply);
  456. }
  457. let jiandaArr = [];
  458. for (const iJianda of st.jianda) {
  459. const c = {
  460. files: iJianda.files,
  461. reply: iJianda.reply,
  462. };
  463. jiandaArr.push(c);
  464. }
  465. result.replyList.push({
  466. reply: {
  467. danxuan: danxuanArr,
  468. duoxuan: duoxuanArr,
  469. panduan: panduanArr,
  470. tiankong: tiankongArr,
  471. jianda: jiandaArr,
  472. },
  473. stId: st.stId,
  474. })
  475. } else {
  476. // 其他
  477. const opt = {
  478. stId: st.stId,
  479. reply: st.reply
  480. }
  481. result.replyList.push(opt)
  482. }
  483. })
  484. })
  485. ksApi.getClientKsSubmit(result).then(res => {
  486. if (res.code == 0) {
  487. subScoreRef.value.showDialog(res.data);
  488. data.hisId = res.data.hisId;
  489. // 清空缓存
  490. removeCacheKs(data.operId);
  491. }
  492. })
  493. }
  494. function onTimeUp() {
  495. handleSubmit();
  496. }
  497. // 交卷相关功能 end
  498. // 切屏功能 start
  499. function qiepingToast(count) {
  500. messageContent.value = `已离开${count}次。${data.toggleScreenFlag}次将自动交卷!`
  501. qiepingDlRef.value.handleShow()
  502. }
  503. function forceSubmit() {
  504. // 强制交卷
  505. console.log('强制交卷')
  506. handleSubmit(true)
  507. }
  508. function qpZhuapai() {
  509. // 重新开启抓拍
  510. zhuapaiRef.value && zhuapaiRef.value.showVideoBtn();
  511. }
  512. // 切屏功能 end
  513. // 摄像头抓拍相关功能 start
  514. function zpSuccess() {}
  515. function zpError() {
  516. uni.showToast({
  517. title: '抓拍图片异常',
  518. icon: 'none'
  519. })
  520. handleBack()
  521. }
  522. // 摄像头抓拍相关功能 end
  523. // 摄像头确认相关功能 start
  524. function onProgress() {
  525. uni.showToast({
  526. icon: 'none',
  527. title: '摄像头运行环境异常,请重新进入考试',
  528. duration: 8000
  529. })
  530. handleBack();
  531. }
  532. function zpConfirmSuccess() {
  533. console.log('zpConfirmSuccess')
  534. initKaoshi();
  535. }
  536. function zpConfirmError() {
  537. handleBack()
  538. }
  539. function zpConfirmCancel() {
  540. handleBack()
  541. }
  542. // 摄像头确认相关功能 end
  543. function getQaClass(qa) {
  544. if (qa.marked && qa.marked === true) {
  545. return 'paragraph-qa-block-mark';
  546. } else {
  547. if (qa.stTypeId == 1) {
  548. if (checkDanxuanReply(qa)) {
  549. return 'paragraph-qa-block-done';
  550. } else {
  551. return 'paragraph-qa-block-init';
  552. }
  553. } else if (qa.stTypeId == 2) {
  554. if (checkDuoxuanReply(qa)) {
  555. return 'paragraph-qa-block-done';
  556. } else {
  557. return 'paragraph-qa-block-init';
  558. }
  559. } else if (qa.stTypeId == 3) {
  560. if (checkPanduanReply(qa)) {
  561. return 'paragraph-qa-block-done';
  562. } else {
  563. return 'paragraph-qa-block-init';
  564. }
  565. } else if (qa.stTypeId == 4) {
  566. if (checkTiankongReply(qa)) {
  567. return 'paragraph-qa-block-done';
  568. } else {
  569. return 'paragraph-qa-block-init';
  570. }
  571. } else if (qa.stTypeId == 5) {
  572. if (checkJiandaReply(qa)) {
  573. return 'paragraph-qa-block-done';
  574. } else {
  575. return 'paragraph-qa-block-init';
  576. }
  577. } else if (qa.stTypeId == 6) {
  578. if (checkYueduReply(qa)) {
  579. return 'paragraph-qa-block-done';
  580. } else {
  581. return 'paragraph-qa-block-init';
  582. }
  583. }
  584. }
  585. }
  586. function skipQuestion(dlIndex, dtIndex) {
  587. progress.dlIndex = dlIndex;
  588. progress.dtIndex = dtIndex;
  589. handlePopupBack()
  590. }
  591. function answerCardItemClick(qa) {
  592. const actQa = data.StListForSearch.find(item => item.stId == qa.stId);
  593. console.log('actQa', actQa)
  594. skipQuestion(actQa.dlIndex, actQa.dtIndex)
  595. }
  596. function handleBack() {
  597. // const pages = getCurrentPages();
  598. // if (pages.length > 1) {
  599. // uni.navigateBack()
  600. // } else {
  601. // history.back();
  602. // }
  603. uni.navigateBack()
  604. }
  605. function showAnswerCard() {
  606. popupRef.value.open('top')
  607. }
  608. function handlePopupBack() {
  609. popupRef.value.close()
  610. }
  611. function handlePrev() {
  612. const qa = data.StListForSearch.find(item => item.stId == activeSt.value.stId);
  613. const index = qa.onlyNum - 1;
  614. if (index > 0) {
  615. const result = data.StListForSearch[index - 1];
  616. progress.dlIndex = result.dlIndex;
  617. progress.dtIndex = result.dtIndex
  618. }
  619. }
  620. function handleNext() {
  621. const qa = data.StListForSearch.find(item => item.stId == activeSt.value.stId);
  622. const index = qa.onlyNum - 1;
  623. if (index < data.StListForSearch.length) {
  624. const result = data.StListForSearch[index + 1];
  625. progress.dlIndex = result.dlIndex;
  626. progress.dtIndex = result.dtIndex
  627. }
  628. }
  629. function formatDuanluoList(dlData) {
  630. let uIndex = 0; // 试题onlyNum
  631. let iDuanluo = 0; // 段落onlyNum
  632. let result = [];
  633. for (const duanluo of data.duanluo) {
  634. let paragraph = {
  635. qas: [],
  636. };
  637. paragraph.name = duanluo.name;
  638. let iQa = 0; // 当前试题序号
  639. let order = 0; // 当前题型中第几题
  640. for (const iDanxuan of duanluo.danxuan) {
  641. iDanxuan.type = 'danxuan';
  642. iDanxuan.marked = data.biaoji[iDanxuan.stId] ? true : false;
  643. iDanxuan.onlyNum = uIndex + 1;
  644. iDanxuan.order = order;
  645. iDanxuan.iQa = iQa;
  646. paragraph.qas.push(iDanxuan);
  647. uIndex++;
  648. order++;
  649. iQa++;
  650. data.StListForSearch.push({
  651. stId: iDanxuan.stId,
  652. paragraphName: paragraph.name,
  653. dlIndex: iDuanluo,
  654. dtIndex: iDanxuan.iQa,
  655. onlyNum: iDanxuan.onlyNum
  656. })
  657. }
  658. order = 0;
  659. for (const iDuoxuan of duanluo.duoxuan) {
  660. iDuoxuan.type = 'duoxuan';
  661. iDuoxuan.marked = data.biaoji[iDuoxuan.stId] ? true : false;
  662. iDuoxuan.onlyNum = uIndex + 1;
  663. iDuoxuan.order = order;
  664. paragraph.qas.push(iDuoxuan);
  665. iDuoxuan.iQa = iQa;
  666. iDuoxuan.reply = [];
  667. uIndex++;
  668. order++;
  669. iQa++;
  670. data.StListForSearch.push({
  671. stId: iDuoxuan.stId,
  672. paragraphName: paragraph.name,
  673. dlIndex: iDuanluo,
  674. dtIndex: iDuoxuan.iQa,
  675. onlyNum: iDuoxuan.onlyNum
  676. })
  677. }
  678. order = 0;
  679. for (const iPanduan of duanluo.panduan) {
  680. iPanduan.type = 'panduan';
  681. iPanduan.marked = data.biaoji[iPanduan.stId] ? true : false;
  682. iPanduan.onlyNum = uIndex + 1;
  683. iPanduan.order = order;
  684. paragraph.qas.push(iPanduan);
  685. iPanduan.iQa = iQa;
  686. uIndex++;
  687. order++;
  688. iQa++;
  689. data.StListForSearch.push({
  690. stId: iPanduan.stId,
  691. paragraphName: paragraph.name,
  692. dlIndex: iDuanluo,
  693. dtIndex: iPanduan.iQa,
  694. onlyNum: iPanduan.onlyNum
  695. })
  696. }
  697. order = 0;
  698. for (const iTiankong of duanluo.tiankong) {
  699. iTiankong.type = 'tiankong';
  700. iTiankong.marked = data.biaoji[iTiankong.stId] ? true : false;
  701. iTiankong.onlyNum = uIndex + 1;
  702. iTiankong.order = order;
  703. paragraph.qas.push(iTiankong);
  704. iTiankong.iQa = iQa;
  705. iTiankong.reply = new Array(iTiankong.count).fill('');
  706. uIndex++;
  707. order++;
  708. iQa++;
  709. data.StListForSearch.push({
  710. stId: iTiankong.stId,
  711. paragraphName: paragraph.name,
  712. dlIndex: iDuanluo,
  713. dtIndex: iTiankong.iQa,
  714. onlyNum: iTiankong.onlyNum
  715. })
  716. }
  717. order = 0;
  718. for (const iJianda of duanluo.jianda) {
  719. iJianda.marked = data.biaoji[iJianda.stId] ? true : false;
  720. iJianda.type = 'jianda';
  721. iJianda.onlyNum = uIndex + 1;
  722. iJianda.order = order;
  723. iJianda.iQa = iQa;
  724. paragraph.qas.push(iJianda);
  725. iJianda.reply = '';
  726. uIndex++;
  727. order++;
  728. iQa++;
  729. data.StListForSearch.push({
  730. stId: iJianda.stId,
  731. paragraphName: paragraph.name,
  732. dlIndex: iDuanluo,
  733. dtIndex: iJianda.iQa,
  734. onlyNum: iJianda.onlyNum
  735. })
  736. }
  737. order = 0;
  738. for (const iYuedu of duanluo.yuedu) {
  739. iYuedu.marked = data.biaoji[iYuedu.stId] ? true : false;
  740. iYuedu.type = 'yuedu';
  741. iYuedu.onlyNum = uIndex + 1;
  742. iYuedu.order = order;
  743. iYuedu.iQa = iQa;
  744. if (iYuedu.duoxuan && iYuedu.duoxuan.length) {
  745. iYuedu.duoxuan.map((qIt) => {
  746. qIt.reply = qIt.reply || [];
  747. return qIt
  748. })
  749. }
  750. if (iYuedu.tiankong && iYuedu.tiankong.length) {
  751. iYuedu.tiankong.map((qIt) => {
  752. qIt.reply = new Array(qIt.count).fill('');
  753. return qIt;
  754. });
  755. }
  756. paragraph.qas.push(iYuedu);
  757. iYuedu.reply = [];
  758. uIndex++;
  759. order++;
  760. iQa++;
  761. data.StListForSearch.push({
  762. stId: iYuedu.stId,
  763. paragraphName: paragraph.name,
  764. dlIndex: iDuanluo,
  765. dtIndex: iYuedu.iQa,
  766. onlyNum: iYuedu.onlyNum
  767. })
  768. }
  769. iDuanluo++;
  770. questionData.value.push(paragraph)
  771. }
  772. }
  773. function handleBiaoji() {
  774. activeSt.value.marked = !activeSt.value.marked;
  775. data.biaoji[activeSt.value.stId] = activeSt.value.marked
  776. ksApi.getClientKaoshiBiaoji({
  777. operId: data.operId,
  778. biaoji: JSON.stringify(data.biaoji)
  779. }).catch(err => {
  780. /* uni.redirectTo({
  781. url: '/pages/client/Kaoshi/list'
  782. }) */
  783. setTimeout(() => {
  784. handleBack()
  785. },1000)
  786. })
  787. }
  788. function formatKaoshiData() {
  789. const historyData = getCacheKs(data.operId);
  790. if (historyData) {
  791. const {
  792. replyList,
  793. position
  794. } = historyData;
  795. if (replyList) {
  796. questionData.value.forEach(dl => {
  797. dl.qas.forEach(st => {
  798. if (st.stTypeId == 5) {
  799. // 简答题
  800. st.reply = replyList.find(item => item.stId == st.stId).reply;
  801. st.files = replyList.find(item => item.stId == st.stId).files;
  802. } else if (st.stTypeId != 6) {
  803. st.reply = replyList.find(item => item.stId == st.stId).reply
  804. } else {
  805. // 阅读题
  806. const hisSt = replyList.find(item => item.stId == st.stId);
  807. if (hisSt) {
  808. st.danxuan.forEach((itm, index) => {
  809. itm.reply = hisSt.reply['danxuan'][index];
  810. })
  811. st.duoxuan.forEach((itm, index) => {
  812. itm.reply = hisSt.reply['duoxuan'][index];
  813. })
  814. st.panduan.forEach((itm, index) => {
  815. itm.reply = hisSt.reply['panduan'][index];
  816. })
  817. st.tiankong.forEach((itm, index) => {
  818. itm.reply = hisSt.reply['tiankong'][index];
  819. })
  820. st.jianda.forEach((itm, index) => {
  821. itm.reply = hisSt.reply['jianda'][index].reply;
  822. itm.files = hisSt.reply['jianda'][index].files;
  823. })
  824. }
  825. }
  826. })
  827. })
  828. }
  829. if (position) {
  830. progress.dlIndex = position.dlIndex;
  831. progress.dtIndex = position.dtIndex;
  832. }
  833. }
  834. }
  835. // 摄像头确认初始化
  836. function initBeforKaoshi() {
  837. console.log(zhuapaiConfirmRef.value)
  838. zhuapaiConfirmRef.value.showDialog()
  839. }
  840. function initKaoshi() {
  841. ksApi.getClientKsStart({
  842. ksId: data.ksId,
  843. }).then(res => {
  844. const {
  845. ksId,
  846. operId,
  847. ksName,
  848. stTotal,
  849. stScore,
  850. biaoji,
  851. endSecond,
  852. pageSize,
  853. toggleScreenFlag,
  854. toggleScreenSecond,
  855. zhuapai,
  856. duanluoList
  857. } = res.data;
  858. data.ksId = ksId;
  859. data.operId = operId;
  860. data.ksName = ksName;
  861. data.stTotal = stTotal;
  862. data.stScore = stScore;
  863. data.biaoji = biaoji ? JSON.parse(biaoji) : {};
  864. data.endSecond = endSecond;
  865. data.pageSize = pageSize;
  866. data.toggleScreenFlag = toggleScreenFlag;
  867. data.toggleScreenSecond = toggleScreenSecond;
  868. // data.zhuapai = zhuapai;
  869. data.duanluo = duanluoList;
  870. formatDuanluoList(data.duanluo);
  871. // 设置缓存
  872. formatKaoshiData();
  873. // 设置抓拍监听
  874. // if (data.zhuapai && data.zhuapai > 0) {
  875. // zhuapaiRef.value.init({
  876. // zhuapai: zhuapai,
  877. // operId: operId
  878. // });
  879. // }
  880. // 设置切屏监听
  881. // qiepingRef.value.init({
  882. // zhuapaiFlag: !!zhuapai,
  883. // toggleScreenFlag: toggleScreenFlag,
  884. // toggleScreenSecond: toggleScreenSecond,
  885. // ksId: data.ksId
  886. // })
  887. startCountDown.value = true;
  888. uni.setNavigationBarTitle({
  889. title: data.ksName
  890. });
  891. }).catch(err => {
  892. console.log('asdasd', err)
  893. setTimeout(() => {
  894. handleBack()
  895. },1000)
  896. })
  897. }
  898. </script>