exam.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. <template>
  2. <view class="phone-kaoshi-page">
  3. <!-- 导航区域 -->
  4. <view class="icon-title-navBar-box">
  5. <view @click="handleBack" class="nav-bar-icon"></view>
  6. <text class="nav-bar-title">{{data.ksName}}</text>
  7. </view>
  8. <!-- 第一行 -->
  9. <view class="kaoshi-page-title">
  10. <!-- 倒计时 -->
  11. <view v-if="!!data.endSecond">
  12. <text>考试倒计时:</text>
  13. <uni-countdown :show-day="true" :second="1000" @timeup="onTimeUp"
  14. :start="startCountDown"></uni-countdown>
  15. </view>
  16. <view v-if="activeSt" class="title-types">{{dlName}}</view>
  17. <view>100分钟</view>
  18. </view>
  19. <view class="kaoshi-shiti-content">
  20. <!-- 内容区域 -->
  21. <!-- 试题区域 -->
  22. <view v-if="activeSt">
  23. <template v-if="activeSt.stTypeId == 1">
  24. <!-- 单选 -->
  25. <danxuan :question="activeSt" :key="activeSt.stId"></danxuan>
  26. </template>
  27. <template v-if="activeSt.stTypeId == 2">
  28. <!-- 多选 -->
  29. <duoxuan :question="activeSt" :key="activeSt.stId"></duoxuan>
  30. </template>
  31. <template v-if="activeSt.stTypeId == 3">
  32. <!-- 判断 -->
  33. <panduan :question="activeSt" :key="activeSt.stId"></panduan>
  34. </template>
  35. <template v-if="activeSt.stTypeId == 4">
  36. <!-- 填空 -->
  37. <tiankong :question="activeSt" :key="activeSt.stId"></tiankong>
  38. </template>
  39. </view>
  40. </view>
  41. <view class="kaoshi-bottom-box">
  42. <button class="phone-green-btn bj-btn" hover-class="none" type="default" size="mini"
  43. @click="handleBiaoji">标记</button>
  44. <view @click="showAnswerCard" class="shiti-num-box">
  45. <icon class="shiti-num-icon"></icon>
  46. <text
  47. class="active-num">{{activeSt ? activeSt.onlyNum: 0}}</text>/<text>{{data.StListForSearch.length}}</text>
  48. </view>
  49. <button class="phone-green-btn" hover-class="none" type="default" size="mini"
  50. @click="handleSave(true)">保存</button>
  51. </view>
  52. <template v-if="activeSt">
  53. <button type="default" size="mini" hover-class="none" class="phone-green-btn ks-btn-prev"
  54. @click="handlePrev" v-if="!isFistStId">上一题</button>
  55. <button type="default" size="mini" hover-class="none" class="phone-green-btn ks-btn-next"
  56. @click="handleNext" v-if="!isLastStId">下一题</button>
  57. <button type="default" size="mini" hover-class="none" class="phone-green-btn ks-btn-next"
  58. @click="handleJiaojuan" v-if="isLastStId">交卷</button>
  59. </template>
  60. <!-- 答题卡 -->
  61. <uni-popup ref="popupRef" background-color="#fff" :is-mask-click="false" :mask-click="false">
  62. <view class="answer-card-popup">
  63. <view class="icon-title-bjcolor-navBar-box">
  64. <view @click="handlePopupBack" class="nav-bar-icon"> </view>
  65. <text class="nav-bar-title">答题卡</text>
  66. </view>
  67. <view class="answer-card-content" v-for="(paragraph,paragraphIndex) in questionData"
  68. :key="paragraphIndex">
  69. <view class="paragraph-title">
  70. {{paragraph.name}}
  71. </view>
  72. <view class="paragraph-qa" v-for="(qa,qaIndex) in paragraph.qas" :key="qaIndex"
  73. :class="getQaClass(qa)" @click="answerCardItemClick(qa)">{{qa.onlyNum}}
  74. </view>
  75. </view>
  76. </view>
  77. </uni-popup>
  78. <!-- 摄像头确认 -->
  79. <zhuapaiConfirm ref="zhuapaiConfirmRef" @success="zpConfirmSuccess" @error="zpConfirmError"
  80. @cancel="zpConfirmCancel" key="1"></zhuapaiConfirm>
  81. <!-- 抓拍 -->
  82. <zhuapaiVue ref="zhuapaiRef" @error="zpError" @success="zpSuccess" key="2"></zhuapaiVue>
  83. <!-- 切屏 -->
  84. <qiepingVue ref="qiepingRef" @zhuapai="qpZhuapai" @forceSubmit="forceSubmit" @qiepingToast="qiepingToast"
  85. key="3"></qiepingVue>
  86. <!-- 交卷确认 -->
  87. <answerQueren ref="answerQrRef" @confirm="handleQuerenConfirm"></answerQueren>
  88. <!-- 考试得分 -->
  89. <submitScoreVue ref="subScoreRef" @confirm="handleScoreConfirm" @close="handleScoreClose"></submitScoreVue>
  90. </view>
  91. </template>
  92. <script setup>
  93. import {
  94. ref,
  95. reactive,
  96. computed,
  97. watch,
  98. nextTick
  99. } from "vue";
  100. import zhuapaiVue from "@/components/zhuapaiConfirm/zhuapai.vue";
  101. import qiepingVue from "@/components/zhuapaiConfirm/qieping.vue";
  102. import zhuapaiConfirm from "@/components/zhuapaiConfirm/index.vue";
  103. import answerQueren from "@/components/zhuapaiConfirm/answerQueren.vue";
  104. import submitScoreVue from "@/components/zhuapaiConfirm/submitScore.vue";
  105. import {
  106. onLoad
  107. } from "@dcloudio/uni-app";
  108. import * as ksApi from "@/api/kaoshi.js"
  109. import danxuan from "@/components/questions/danxuan.vue";
  110. import duoxuan from "@/components/questions/duoxuan.vue";
  111. import tiankong from "@/components/questions/tiankong.vue";
  112. import panduan from "@/components/questions/panduan.vue";
  113. import {
  114. useQuestionTools
  115. } from "@/components/questions/useQuestionTools.js";
  116. import {
  117. useKaoShiCache
  118. } from "./examTools"
  119. const {
  120. checkDanxuanReply,
  121. checkDuoxuanReply,
  122. checkPanduanReply,
  123. checkTiankongReply,
  124. getLetterByIndex
  125. } = useQuestionTools();
  126. const {
  127. saveCacheKs,
  128. getCacheKs,
  129. removeCacheKs
  130. } = useKaoShiCache();
  131. onLoad((option) => {
  132. data.ksId = option.ksId;
  133. data.zhuapai = option.zhuapai
  134. if (data.zhuapai && data.zhuapai != 0) {
  135. // 考试前确认摄像头
  136. nextTick(() => {
  137. initBeforKaoshi();
  138. })
  139. } else {
  140. initKaoshi();
  141. }
  142. })
  143. const popupRef = ref(null)
  144. const zhuapaiRef = ref(null)
  145. const qiepingRef = ref(null)
  146. const zhuapaiConfirmRef = ref(null)
  147. const answerQrRef = ref(null);
  148. const startCountDown = ref(false);
  149. const subScoreRef = ref(null)
  150. const timer1 = ref(null);
  151. const data = reactive({
  152. ksId: null,
  153. operId: null,
  154. ksName: '',
  155. stTotal: 0,
  156. stScore: 0,
  157. biaoji: null,
  158. endSecond: 0,
  159. pageSize: 0,
  160. toggleScreenFlag: 0,
  161. toggleScreenSecond: 0,
  162. zhuapai: 0,
  163. duanluo: [],
  164. markDB: [],
  165. StListForSearch: [],
  166. })
  167. const questionData = ref([]);
  168. const progress = reactive({
  169. dlIndex: 0,
  170. dtIndex: 0
  171. })
  172. const dlName = computed(() => {
  173. if (data.StListForSearch && activeSt.value) {
  174. return data.StListForSearch[activeSt.value.onlyNum - 1].paragraphName
  175. } else {
  176. return ''
  177. }
  178. })
  179. watch(() => data.duanluo, (newVal) => {
  180. // 计算已答试题数量
  181. }, {
  182. deep: true
  183. })
  184. const activeSt = computed(() => {
  185. if (questionData.value.length) {
  186. return questionData.value.length && questionData.value[progress.dlIndex].qas[progress.dtIndex];
  187. } else {
  188. return null
  189. }
  190. })
  191. const isFistStId = computed(() => {
  192. if (data.StListForSearch.length) {
  193. return data.StListForSearch[0].stId == activeSt.value.stId
  194. } else {
  195. return false
  196. }
  197. });
  198. const isLastStId = computed(() => {
  199. if (data.StListForSearch.length) {
  200. return data.StListForSearch[data.StListForSearch.length - 1].stId == activeSt.value.stId
  201. } else {
  202. return false
  203. }
  204. });
  205. function handleScoreClose() {
  206. uni.redirectTo({
  207. url: '/pages/client/Kaoshi/list'
  208. })
  209. }
  210. // 考试得分相关 start
  211. function handleScoreConfirm() {
  212. uni.redirectTo({
  213. url: '/pages/client/Score/list'
  214. })
  215. }
  216. // 考试得分相关 end
  217. // 保存相关
  218. function handleSave(showToast) {
  219. if (timer1.value) {
  220. uni.showToast({
  221. title: '请勿连续保存',
  222. icon: 'none'
  223. })
  224. return
  225. }
  226. timer1.value = setTimeout(() => {
  227. clearTimeout(timer1.value);
  228. },10*1000);
  229. console.log(questionData.value)
  230. const result = []
  231. const option = {
  232. force: false,
  233. operId: data.operId,
  234. replyList: []
  235. }
  236. questionData.value.forEach(dl => {
  237. dl.qas.forEach(st => {
  238. const opt = {
  239. stId: st.stId,
  240. reply: st.reply,
  241. }
  242. result.push(opt)
  243. option.replyList.push(opt)
  244. })
  245. })
  246. // 保存试题答案
  247. saveCacheKs(data.operId, {replyList:result, position: {dlIndex:progress.dlIndex, dtIndex: progress.dtIndex}})
  248. // 保存答题进度
  249. ksApi.getClientKsSave(option).then(res => {
  250. if (res.data && showToast) {
  251. uni.showToast({
  252. title: '保存成功',
  253. })
  254. }
  255. })
  256. }
  257. // 交卷相关功能 start
  258. function checkJiaojuan() {
  259. const result = []
  260. let count = 0;
  261. let total = 0;
  262. questionData.value.forEach(dl => {
  263. dl.qas.forEach(st => {
  264. const opt = {
  265. stId: st.stId,
  266. reply: st.reply,
  267. stTypeId: st.stTypeId
  268. }
  269. result.push(opt)
  270. })
  271. })
  272. result.forEach(item => {
  273. total++;
  274. if (item.stTypeId == 1 && !checkDanxuanReply(item)) {
  275. count++;
  276. }
  277. if (item.stTypeId == 2 && !checkDuoxuanReply(item)) {
  278. count++;
  279. }
  280. if (item.stTypeId == 3 && !checkPanduanReply(item)) {
  281. count++;
  282. }
  283. if (item.stTypeId == 4 && !checkTiankongReply(item)) {
  284. count++;
  285. }
  286. })
  287. return {
  288. total,
  289. count,
  290. }
  291. }
  292. function handleJiaojuan() {
  293. const result = checkJiaojuan()
  294. console.log(result)
  295. if (result.count) {
  296. // 提示
  297. answerQrRef.value.showDialog({
  298. answercartsCount: result.count,
  299. answercartsTotal: result.total,
  300. })
  301. } else {
  302. handleSubmit()
  303. }
  304. }
  305. function handleQuerenConfirm() {
  306. handleSubmit()
  307. }
  308. function handleSubmit(force = false) {
  309. const result = {
  310. force,
  311. operId: data.operId,
  312. replyList: []
  313. };
  314. console.log(questionData.value)
  315. questionData.value.forEach(dl => {
  316. dl.qas.forEach(st => {
  317. const opt = {
  318. stId: st.stId,
  319. reply: st.reply
  320. }
  321. result.replyList.push(opt)
  322. })
  323. })
  324. ksApi.getClientKsSubmit(result).then(res => {
  325. console.log('result', result)
  326. if (res.code == 0) {
  327. subScoreRef.value.showDialog(res.data)
  328. }
  329. })
  330. }
  331. function onTimeUp() {
  332. handleSubmit(true);
  333. }
  334. // 交卷相关功能 end
  335. // 切屏功能 start
  336. function qiepingToast(count) {
  337. uni.showToast({
  338. title: '请在考试界面操作,注意考试纪律!'
  339. })
  340. }
  341. function forceSubmit() {
  342. // 强制交卷
  343. console.log('强制交卷')
  344. handleSubmit(true)
  345. }
  346. function qpZhuapai() {
  347. // 重新开启抓拍
  348. zhuapaiRef.value && zhuapaiRef.value.showVideoBtn()
  349. }
  350. // 切屏功能 end
  351. // 摄像头抓拍相关功能 start
  352. function zpSuccess() {}
  353. function zpError() {
  354. uni.showToast({
  355. title: '摄像头唤起异常'
  356. })
  357. uni.redirectTo({
  358. url: '/pages/client/Kaoshi/list'
  359. })
  360. }
  361. // 摄像头抓拍相关功能 end
  362. // 摄像头确认相关功能 start
  363. function zpConfirmSuccess() {
  364. initKaoshi();
  365. }
  366. function zpConfirmError() {
  367. uni.showToast({
  368. title: '摄像头唤起异常'
  369. })
  370. uni.redirectTo({
  371. url: '/pages/client/Kaoshi/list'
  372. })
  373. }
  374. function zpConfirmCancel() {
  375. uni.redirectTo({
  376. url: '/pages/client/Kaoshi/list'
  377. })
  378. }
  379. // 摄像头确认相关功能 end
  380. function getQaClass(qa) {
  381. if (qa.marked && qa.marked === true) {
  382. return 'paragraph-qa-block-mark';
  383. } else {
  384. if (qa.stTypeId == 1) {
  385. if (checkDanxuanReply(qa)) {
  386. return 'paragraph-qa-block-done';
  387. } else {
  388. return 'paragraph-qa-block-init';
  389. }
  390. } else if (qa.stTypeId == 2) {
  391. if (checkDuoxuanReply(qa)) {
  392. return 'paragraph-qa-block-done';
  393. } else {
  394. return 'paragraph-qa-block-init';
  395. }
  396. } else if (qa.stTypeId == 3) {
  397. if (checkPanduanReply(qa)) {
  398. return 'paragraph-qa-block-done';
  399. } else {
  400. return 'paragraph-qa-block-init';
  401. }
  402. } else if (qa.stTypeId == 4) {
  403. if (checkTiankongReply(qa)) {
  404. return 'paragraph-qa-block-done';
  405. } else {
  406. return 'paragraph-qa-block-init';
  407. }
  408. }
  409. }
  410. }
  411. function skipQuestion(dlIndex, dtIndex) {
  412. progress.dlIndex = dlIndex;
  413. progress.dtIndex = dtIndex;
  414. handlePopupBack()
  415. }
  416. function answerCardItemClick(qa) {
  417. const actQa = data.StListForSearch.find(item => item.stId == qa.stId);
  418. skipQuestion(actQa.dlIndex, actQa.dtIndex)
  419. }
  420. function handleBack() {
  421. uni.redirectTo({
  422. url: "/pages/client/Kaoshi/list"
  423. })
  424. }
  425. function showAnswerCard() {
  426. popupRef.value.open('bottom')
  427. }
  428. function handlePopupBack() {
  429. popupRef.value.close()
  430. }
  431. function handlePrev() {
  432. const qa = data.StListForSearch.find(item => item.stId == activeSt.value.stId);
  433. const index = qa.onlyNum - 1;
  434. if (index > 0) {
  435. const result = data.StListForSearch[index - 1];
  436. progress.dlIndex = result.dlIndex;
  437. progress.dtIndex = result.dtIndex
  438. }
  439. }
  440. function handleNext() {
  441. const qa = data.StListForSearch.find(item => item.stId == activeSt.value.stId);
  442. const index = qa.onlyNum - 1;
  443. if (index < data.StListForSearch.length) {
  444. const result = data.StListForSearch[index + 1];
  445. progress.dlIndex = result.dlIndex;
  446. progress.dtIndex = result.dtIndex
  447. }
  448. }
  449. function formatDuanluoList(dlData) {
  450. let uIndex = 0; // 试题onlyNum
  451. let iDuanluo = 0; // 段落onlyNum
  452. let result = [];
  453. for (const duanluo of data.duanluo) {
  454. let paragraph = {
  455. qas: [],
  456. };
  457. paragraph.name = duanluo.name;
  458. let iQa = 0; // 当前试题序号
  459. let order = 0; // 当前题型中第几题
  460. for (const iDanxuan of duanluo.danxuan) {
  461. iDanxuan.type = 'danxuan';
  462. iDanxuan.marked = false;
  463. iDanxuan.onlyNum = uIndex + 1;
  464. iDanxuan.order = order;
  465. iDanxuan.iQa = iQa;
  466. paragraph.qas.push(iDanxuan);
  467. uIndex++;
  468. order++;
  469. iQa++;
  470. data.StListForSearch.push({
  471. stId: iDanxuan.stId,
  472. paragraphName: paragraph.name,
  473. dlIndex: iDuanluo,
  474. dtIndex: iDanxuan.iQa,
  475. onlyNum: iDanxuan.onlyNum
  476. })
  477. }
  478. order = 0;
  479. for (const iDuoxuan of duanluo.duoxuan) {
  480. iDuoxuan.type = 'duoxuan';
  481. iDuoxuan.marked = false;
  482. iDuoxuan.onlyNum = uIndex + 1;
  483. iDuoxuan.order = order;
  484. paragraph.qas.push(iDuoxuan);
  485. iDuoxuan.iQa = iQa;
  486. iDuoxuan.reply = [];
  487. uIndex++;
  488. order++;
  489. iQa++;
  490. data.StListForSearch.push({
  491. stId: iDuoxuan.stId,
  492. paragraphName: paragraph.name,
  493. dlIndex: iDuanluo,
  494. dtIndex: iDuoxuan.iQa,
  495. onlyNum: iDuoxuan.onlyNum
  496. })
  497. }
  498. order = 0;
  499. for (const iPanduan of duanluo.panduan) {
  500. iPanduan.type = 'panduan';
  501. iPanduan.marked = false;
  502. iPanduan.onlyNum = uIndex + 1;
  503. iPanduan.order = order;
  504. paragraph.qas.push(iPanduan);
  505. iPanduan.iQa = iQa;
  506. uIndex++;
  507. order++;
  508. iQa++;
  509. data.StListForSearch.push({
  510. stId: iPanduan.stId,
  511. paragraphName: paragraph.name,
  512. dlIndex: iDuanluo,
  513. dtIndex: iPanduan.iQa,
  514. onlyNum: iPanduan.onlyNum
  515. })
  516. }
  517. order = 0;
  518. for (const iTiankong of duanluo.tiankong) {
  519. iTiankong.type = 'tiankong';
  520. iTiankong.marked = false;
  521. iTiankong.onlyNum = uIndex + 1;
  522. iTiankong.order = order;
  523. paragraph.qas.push(iTiankong);
  524. iTiankong.iQa = iQa;
  525. iTiankong.reply = new Array(iTiankong.count).fill('');;
  526. uIndex++;
  527. order++;
  528. iQa++;
  529. data.StListForSearch.push({
  530. stId: iTiankong.stId,
  531. paragraphName: paragraph.name,
  532. dlIndex: iDuanluo,
  533. dtIndex: iTiankong.iQa,
  534. onlyNum: iTiankong.onlyNum
  535. })
  536. }
  537. iDuanluo++;
  538. questionData.value.push(paragraph)
  539. console.log('1', questionData.value)
  540. console.log('2', data.StListForSearch)
  541. }
  542. }
  543. function handleBiaoji() {
  544. activeSt.value.marked = !activeSt.value.marked;
  545. }
  546. function formatKaoshiData() {
  547. const historyData = getCacheKs(data.operId);
  548. if (historyData) {
  549. const { replyList ,position } = historyData;
  550. if (replyList) {
  551. questionData.value.forEach(dl => {
  552. dl.qas.forEach(st => {
  553. st.reply = replyList.find(item => item.stId == st.stId).reply
  554. })
  555. })
  556. }
  557. if (position) {
  558. progress.dlIndex = position.dlIndex;
  559. progress.dtIndex = position.dtIndex;
  560. }
  561. }
  562. }
  563. // 摄像头确认初始化
  564. function initBeforKaoshi() {
  565. console.log(zhuapaiConfirmRef.value)
  566. zhuapaiConfirmRef.value.showDialog()
  567. }
  568. function initKaoshi() {
  569. ksApi.getClientKsStart({
  570. ksId: data.ksId
  571. }).then(res => {
  572. const {
  573. ksId,
  574. operId,
  575. ksName,
  576. stTotal,
  577. stScore,
  578. biaoji,
  579. endSecond,
  580. pageSize,
  581. toggleScreenFlag,
  582. toggleScreenSecond,
  583. zhuapai,
  584. duanluoList
  585. } = res.data;
  586. data.ksId = ksId;
  587. data.operId = operId;
  588. data.ksName = ksName;
  589. data.stTotal = stTotal;
  590. data.stScore = stScore;
  591. data.biaoji = biaoji;
  592. data.endSecond = endSecond;
  593. data.pageSize = pageSize;
  594. data.toggleScreenFlag = toggleScreenFlag;
  595. data.toggleScreenSecond = toggleScreenSecond;
  596. data.zhuapai = zhuapai;
  597. data.duanluo = duanluoList;
  598. formatDuanluoList(data.duanluo);
  599. // 设置缓存
  600. formatKaoshiData();
  601. // 设置抓拍监听
  602. zhuapaiRef.value.init({
  603. zhuapai: zhuapai
  604. });
  605. // 设置切屏监听
  606. qiepingRef.value.init({
  607. zhuapaiFlag: true,
  608. toggleScreenFlag: toggleScreenFlag,
  609. toggleScreenSecond: toggleScreenSecond,
  610. ksId: data.ksId
  611. })
  612. uni.setNavigationBarTitle({
  613. title: data.ksName
  614. });
  615. startCountDown.value = true;
  616. })
  617. }
  618. </script>