exam.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. <template>
  2. <view class="phone-kaoshi-page">
  3. <!-- 导航区域 -->
  4. <customNavbarVue :title="data.lxName" :show-back-btn="true" @back="handleBack"></customNavbarVue>
  5. <!-- 第一行 -->
  6. <view class="kaoshi-page-title">
  7. <!-- 倒计时 -->
  8. <view v-if="!!data.endSecond">
  9. <text>考试倒计时:</text>
  10. <uni-countdown :show-day="true" :second="1000" @timeup="onTimeUp"
  11. :start="startCountDown"></uni-countdown>
  12. </view>
  13. <view v-if="activeSt" class="title-types">{{dlName}}</view>
  14. </view>
  15. <view class="kaoshi-shiti-content">
  16. <!-- 内容区域 -->
  17. <!-- 试题区域 -->
  18. <view v-if="activeSt">
  19. <template v-if="activeSt.stTypeId == 1">
  20. <!-- 单选 -->
  21. <danxuan :question="activeSt" :key="activeSt.stId"></danxuan>
  22. </template>
  23. <template v-if="activeSt.stTypeId == 2">
  24. <!-- 多选 -->
  25. <duoxuan :question="activeSt" :key="activeSt.stId"></duoxuan>
  26. </template>
  27. <template v-if="activeSt.stTypeId == 3">
  28. <!-- 判断 -->
  29. <panduan :question="activeSt" :key="activeSt.stId"></panduan>
  30. </template>
  31. <template v-if="activeSt.stTypeId == 4">
  32. <!-- 填空 -->
  33. <tiankong :question="activeSt" :key="activeSt.stId"></tiankong>
  34. </template>
  35. </view>
  36. </view>
  37. <view class="kaoshi-bottom-box">
  38. <button class="phone-green-btn bj-btn" hover-class="none" type="default" size="mini"
  39. @click="handleBiaoji">{{activeSt && activeSt.marked ? '取标':'标记'}}</button>
  40. <view @click="showAnswerCard" class="shiti-num-box">
  41. <icon class="shiti-num-icon" :style="{ backgroundImage: 'url(' + data.imgsArr.shitiNumIcon + ')' }"></icon>
  42. <text
  43. class="active-num">{{activeSt ? activeSt.onlyNum: 0}}</text>/<text>{{data.StListForSearch.length}}</text>
  44. </view>
  45. </view>
  46. <template v-if="activeSt">
  47. <button type="default" size="mini" hover-class="none" class="phone-green-btn ks-btn-prev"
  48. @click="handlePrev" v-if="!isFistStId">上一题</button>
  49. <button type="default" size="mini" hover-class="none" class="phone-green-btn ks-btn-next"
  50. @click="handleNext" v-if="!isLastStId">下一题</button>
  51. <button type="default" size="mini" hover-class="none" class="phone-green-btn ks-btn-next"
  52. @click="handleJiaojuan" v-if="isLastStId">交卷</button>
  53. </template>
  54. <!-- 答题卡 -->
  55. <uni-popup ref="popupRef" background-color="#fff" :animation="false" :is-mask-click="false" :mask-click="false">
  56. <view class="answer-card-popup">
  57. <customNavbarVue title="答题卡" :show-back-btn="true" @back="handlePopupBack"></customNavbarVue>
  58. <view class="card-content-box">
  59. <view class="answer-card-content" v-for="(paragraph,paragraphIndex) in questionData"
  60. :key="paragraphIndex">
  61. <view class="paragraph-title">
  62. {{paragraph.name}}
  63. </view>
  64. <view class="paragraph-qa" v-for="(qa,qaIndex) in paragraph.qas" :key="qaIndex"
  65. :class="getQaClass(qa)" @click="answerCardItemClick(qa)">{{qa.onlyNum}}
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. </uni-popup>
  71. <!-- 交卷确认 -->
  72. <answerQueren ref="answerQrRef" @confirm="handleQuerenConfirm"></answerQueren>
  73. <!-- 考试得分 -->
  74. <submitScoreVue title="练习得分" nameKey="lxName" ref="subScoreRef" labelName="练习总分" @goIndex="handleGoIndex" @confirm="handleScoreConfirm" @close="handleScoreClose"></submitScoreVue>
  75. </view>
  76. </template>
  77. <script setup>
  78. import cacheManager from '@/utils/cacheManager.js';
  79. import {ref,reactive,computed,watch,nextTick} from "vue";
  80. import customNavbarVue from "@/components/custom-navbar/custom-navbar.vue";
  81. import answerQueren from "@/components/zhuapaiConfirm/answerQueren.vue";
  82. import submitScoreVue from "@/components/zhuapaiConfirm/submitScore.vue";
  83. import {
  84. onLoad
  85. } from "@dcloudio/uni-app";
  86. import * as lxApi from "@/api/lianxi.js"
  87. import danxuan from "@/components/questions/danxuan.vue";
  88. import duoxuan from "@/components/questions/duoxuan.vue";
  89. import tiankong from "@/components/questions/tiankong.vue";
  90. import panduan from "@/components/questions/panduan.vue";
  91. import {
  92. useQuestionTools
  93. } from "@/components/questions/useQuestionTools.js";
  94. const {
  95. checkDanxuanReply,
  96. checkDuoxuanReply,
  97. checkPanduanReply,
  98. checkTiankongReply,
  99. getLetterByIndex
  100. } = useQuestionTools();
  101. onLoad((option) => {
  102. data.lxId = option.lxId;
  103. data.zhuapai = option.zhuapai;
  104. data.from = option.from;
  105. data.imgsArr.shitiNumIcon = cacheManager.get('projectImg').shiti_num_icon;
  106. initKaoshi();
  107. })
  108. const popupRef = ref(null)
  109. const zhuapaiConfirmRef = ref(null)
  110. const answerQrRef = ref(null);
  111. const startCountDown = ref(false);
  112. const subScoreRef = ref(null)
  113. const timer1 = ref(null);
  114. const data = reactive({
  115. lxId: null,
  116. operId: null,
  117. lxName: '',
  118. stTotal: 0,
  119. stScore: 0,
  120. biaoji: {},
  121. endSecond: 0,
  122. pageSize: 0,
  123. toggleScreenFlag: 0,
  124. toggleScreenSecond: 0,
  125. zhuapai: 0,
  126. duanluo: [],
  127. StListForSearch: [],
  128. from: '',
  129. hisId: null,
  130. imgsArr: {
  131. shitiNumIcon: '',
  132. },
  133. })
  134. const markDB = ref([]);
  135. const questionData = ref([]);
  136. const progress = reactive({
  137. dlIndex: 0,
  138. dtIndex: 0
  139. })
  140. const dlName = computed(() => {
  141. if (data.StListForSearch && activeSt.value) {
  142. return data.StListForSearch[activeSt.value.onlyNum - 1].paragraphName
  143. } else {
  144. return ''
  145. }
  146. })
  147. watch(() => data.duanluo, (newVal) => {
  148. // 计算已答试题数量
  149. }, {
  150. deep: true
  151. })
  152. const activeSt = computed(() => {
  153. if (questionData.value.length) {
  154. return questionData.value.length && questionData.value[progress.dlIndex].qas[progress.dtIndex];
  155. } else {
  156. return null
  157. }
  158. })
  159. const isFistStId = computed(() => {
  160. if (data.StListForSearch.length) {
  161. return data.StListForSearch[0].stId == activeSt.value.stId
  162. } else {
  163. return false
  164. }
  165. });
  166. const isLastStId = computed(() => {
  167. if (data.StListForSearch.length) {
  168. return data.StListForSearch[data.StListForSearch.length - 1].stId == activeSt.value.stId
  169. } else {
  170. return false
  171. }
  172. });
  173. function handleGoIndex() {
  174. handleBack()
  175. }
  176. function handleScoreClose() {
  177. handleBack()
  178. }
  179. // 考试得分相关 start
  180. function handleScoreConfirm() {
  181. uni.redirectTo({
  182. url: `/pages/client/Chengji/lxScoreShijuan?hisId=${data.hisId}&from=lianxi`
  183. })
  184. }
  185. // 考试得分相关 end
  186. // 交卷相关功能 start
  187. function checkJiaojuan() {
  188. const result = []
  189. let count = 0;
  190. let total = 0;
  191. questionData.value.forEach(dl => {
  192. dl.qas.forEach(st => {
  193. const opt = {
  194. stId: st.stId,
  195. reply: st.reply,
  196. stTypeId: st.stTypeId
  197. }
  198. result.push(opt)
  199. })
  200. })
  201. result.forEach(item => {
  202. total++;
  203. if (item.stTypeId == 1 && !checkDanxuanReply(item)) {
  204. count++;
  205. }
  206. if (item.stTypeId == 2 && !checkDuoxuanReply(item)) {
  207. count++;
  208. }
  209. if (item.stTypeId == 3 && !checkPanduanReply(item)) {
  210. count++;
  211. }
  212. if (item.stTypeId == 4 && !checkTiankongReply(item)) {
  213. count++;
  214. }
  215. })
  216. return {
  217. total,
  218. count,
  219. }
  220. }
  221. function handleJiaojuan() {
  222. const result = checkJiaojuan()
  223. console.log(result)
  224. if (result.count) {
  225. // 提示
  226. answerQrRef.value.showDialog({
  227. answercartsCount: result.total - result.count,
  228. answercartsTotal: result.total,
  229. })
  230. } else {
  231. handleSubmit()
  232. }
  233. }
  234. function handleQuerenConfirm() {
  235. handleSubmit()
  236. }
  237. function handleSubmit(force = false) {
  238. const result = {
  239. force,
  240. operId: data.operId,
  241. replyList: []
  242. };
  243. questionData.value.forEach(dl => {
  244. dl.qas.forEach(st => {
  245. const opt = {
  246. stId: st.stId,
  247. reply: st.reply
  248. }
  249. result.replyList.push(opt)
  250. })
  251. })
  252. // uni.showLoading({
  253. // title: '提交中'
  254. // })
  255. lxApi.getClientLianxiSubmit(result).then(res => {
  256. if (res.code == 0) {
  257. data.hisId = res.data.hisId;
  258. subScoreRef.value.showDialog(res.data);
  259. }
  260. }).finally(() => {
  261. // uni.hideLoading()
  262. })
  263. }
  264. function onTimeUp() {
  265. handleSubmit(true);
  266. }
  267. // 交卷相关功能 end
  268. function forceSubmit() {
  269. // 强制交卷
  270. console.log('强制交卷')
  271. handleSubmit(true)
  272. }
  273. function getQaClass(qa) {
  274. if (qa.marked && qa.marked === true) {
  275. return 'paragraph-qa-block-mark';
  276. } else {
  277. if (qa.stTypeId == 1) {
  278. if (checkDanxuanReply(qa)) {
  279. return 'paragraph-qa-block-done';
  280. } else {
  281. return 'paragraph-qa-block-init';
  282. }
  283. } else if (qa.stTypeId == 2) {
  284. if (checkDuoxuanReply(qa)) {
  285. return 'paragraph-qa-block-done';
  286. } else {
  287. return 'paragraph-qa-block-init';
  288. }
  289. } else if (qa.stTypeId == 3) {
  290. if (checkPanduanReply(qa)) {
  291. return 'paragraph-qa-block-done';
  292. } else {
  293. return 'paragraph-qa-block-init';
  294. }
  295. } else if (qa.stTypeId == 4) {
  296. if (checkTiankongReply(qa)) {
  297. return 'paragraph-qa-block-done';
  298. } else {
  299. return 'paragraph-qa-block-init';
  300. }
  301. }
  302. }
  303. }
  304. function skipQuestion(dlIndex, dtIndex) {
  305. progress.dlIndex = dlIndex;
  306. progress.dtIndex = dtIndex;
  307. handlePopupBack()
  308. }
  309. function answerCardItemClick(qa) {
  310. const actQa = data.StListForSearch.find(item => item.stId == qa.stId);
  311. skipQuestion(actQa.dlIndex, actQa.dtIndex)
  312. }
  313. function handleBack() {
  314. const pages = getCurrentPages();
  315. if (pages.length>1) {
  316. uni.navigateBack()
  317. } else {
  318. /* if (data.from == 'shouye') {
  319. uni.redirectTo({
  320. url: '/pages/client/ShouYe/shouye'
  321. })
  322. } else if (data.from == 'lianxiList') {
  323. uni.redirectTo({
  324. url: '/pages/client/Lianxi/list'
  325. })
  326. } else {
  327. uni.redirectTo({
  328. url: "/pages/client/ShouYe/shouye"
  329. })
  330. } */
  331. history.back();
  332. }
  333. }
  334. function showAnswerCard() {
  335. popupRef.value.open('top')
  336. }
  337. function handlePopupBack() {
  338. popupRef.value && popupRef.value.close()
  339. }
  340. function handlePrev() {
  341. const qa = data.StListForSearch.find(item => item.stId == activeSt.value.stId);
  342. const index = qa.onlyNum - 1;
  343. if (index > 0) {
  344. const result = data.StListForSearch[index - 1];
  345. progress.dlIndex = result.dlIndex;
  346. progress.dtIndex = result.dtIndex
  347. }
  348. }
  349. function handleNext() {
  350. const qa = data.StListForSearch.find(item => item.stId == activeSt.value.stId);
  351. const index = qa.onlyNum - 1;
  352. if (index < data.StListForSearch.length) {
  353. const result = data.StListForSearch[index + 1];
  354. progress.dlIndex = result.dlIndex;
  355. progress.dtIndex = result.dtIndex
  356. }
  357. }
  358. function formatDuanluoList(dlData) {
  359. let uIndex = 0; // 试题onlyNum
  360. let iDuanluo = 0; // 段落onlyNum
  361. let result = [];
  362. for (const duanluo of data.duanluo) {
  363. let paragraph = {
  364. qas: [],
  365. };
  366. paragraph.name = duanluo.name;
  367. let iQa = 0; // 当前试题序号
  368. let order = 0; // 当前题型中第几题
  369. for (const iDanxuan of duanluo.danxuan) {
  370. iDanxuan.type = 'danxuan';
  371. iDanxuan.marked = data.biaoji[iDanxuan.stId] ? true: false;
  372. iDanxuan.onlyNum = uIndex + 1;
  373. iDanxuan.order = order;
  374. iDanxuan.iQa = iQa;
  375. paragraph.qas.push(iDanxuan);
  376. uIndex++;
  377. order++;
  378. iQa++;
  379. data.StListForSearch.push({
  380. stId: iDanxuan.stId,
  381. paragraphName: paragraph.name,
  382. dlIndex: iDuanluo,
  383. dtIndex: iDanxuan.iQa,
  384. onlyNum: iDanxuan.onlyNum
  385. })
  386. }
  387. order = 0;
  388. for (const iDuoxuan of duanluo.duoxuan) {
  389. iDuoxuan.type = 'duoxuan';
  390. iDuoxuan.marked = data.biaoji[iDuoxuan.stId] ? true: false;
  391. iDuoxuan.onlyNum = uIndex + 1;
  392. iDuoxuan.order = order;
  393. paragraph.qas.push(iDuoxuan);
  394. iDuoxuan.iQa = iQa;
  395. iDuoxuan.reply = [];
  396. uIndex++;
  397. order++;
  398. iQa++;
  399. data.StListForSearch.push({
  400. stId: iDuoxuan.stId,
  401. paragraphName: paragraph.name,
  402. dlIndex: iDuanluo,
  403. dtIndex: iDuoxuan.iQa,
  404. onlyNum: iDuoxuan.onlyNum
  405. })
  406. }
  407. order = 0;
  408. for (const iPanduan of duanluo.panduan) {
  409. iPanduan.type = 'panduan';
  410. iPanduan.marked = data.biaoji[iPanduan.stId] ? true: false;
  411. iPanduan.onlyNum = uIndex + 1;
  412. iPanduan.order = order;
  413. paragraph.qas.push(iPanduan);
  414. iPanduan.iQa = iQa;
  415. uIndex++;
  416. order++;
  417. iQa++;
  418. data.StListForSearch.push({
  419. stId: iPanduan.stId,
  420. paragraphName: paragraph.name,
  421. dlIndex: iDuanluo,
  422. dtIndex: iPanduan.iQa,
  423. onlyNum: iPanduan.onlyNum
  424. })
  425. }
  426. order = 0;
  427. for (const iTiankong of duanluo.tiankong) {
  428. iTiankong.type = 'tiankong';
  429. iTiankong.marked = data.biaoji[iTiankong.stId] ? true: false;
  430. iTiankong.onlyNum = uIndex + 1;
  431. iTiankong.order = order;
  432. paragraph.qas.push(iTiankong);
  433. iTiankong.iQa = iQa;
  434. iTiankong.reply = new Array(iTiankong.count).fill('');;
  435. uIndex++;
  436. order++;
  437. iQa++;
  438. data.StListForSearch.push({
  439. stId: iTiankong.stId,
  440. paragraphName: paragraph.name,
  441. dlIndex: iDuanluo,
  442. dtIndex: iTiankong.iQa,
  443. onlyNum: iTiankong.onlyNum
  444. })
  445. }
  446. iDuanluo++;
  447. questionData.value.push(paragraph)
  448. console.log('1', questionData.value)
  449. console.log('2', data.StListForSearch)
  450. }
  451. }
  452. function handleBiaoji() {
  453. activeSt.value.marked = !activeSt.value.marked;
  454. data.biaoji.value[activeSt.value.stId] = activeSt.value.marked
  455. lxApi.getClientLianxiBiaoji({
  456. operId: data.operId,
  457. biaoji: JSON.stringify(data.biaoji)
  458. }).catch(err => {
  459. uni.redirectTo({
  460. url: '/pages/client/Lianxi/list'
  461. })
  462. })
  463. }
  464. function initKaoshi() {
  465. lxApi.getClientLianxiStart({
  466. lxId: data.lxId
  467. }).then(res => {
  468. const {
  469. lxId,
  470. operId,
  471. lxName,
  472. stTotal,
  473. stScore,
  474. biaoji,
  475. endSecond,
  476. pageSize,
  477. toggleScreenFlag,
  478. toggleScreenSecond,
  479. zhuapai,
  480. duanluoList
  481. } = res.data;
  482. data.lxId = lxId;
  483. data.operId = operId;
  484. data.lxName = lxName;
  485. data.stTotal = stTotal;
  486. data.stScore = stScore;
  487. data.biaoji = biaoji ? JSON.parse(biaoji): {};
  488. data.endSecond = endSecond;
  489. data.pageSize = pageSize;
  490. data.duanluo = duanluoList;
  491. formatDuanluoList(data.duanluo);
  492. uni.setNavigationBarTitle({
  493. title: data.lxName
  494. });
  495. startCountDown.value = true;
  496. }).catch(err => {
  497. handleBack()
  498. })
  499. }
  500. </script>