exam.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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="练习总分" @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 handleScoreClose() {
  174. handleBack()
  175. }
  176. // 考试得分相关 start
  177. function handleScoreConfirm() {
  178. uni.redirectTo({
  179. url: `/pages/client/Chengji/lxScoreShijuan?hisId=${data.hisId}&from=lianxi`
  180. })
  181. }
  182. // 考试得分相关 end
  183. // 交卷相关功能 start
  184. function checkJiaojuan() {
  185. const result = []
  186. let count = 0;
  187. let total = 0;
  188. questionData.value.forEach(dl => {
  189. dl.qas.forEach(st => {
  190. const opt = {
  191. stId: st.stId,
  192. reply: st.reply,
  193. stTypeId: st.stTypeId
  194. }
  195. result.push(opt)
  196. })
  197. })
  198. result.forEach(item => {
  199. total++;
  200. if (item.stTypeId == 1 && !checkDanxuanReply(item)) {
  201. count++;
  202. }
  203. if (item.stTypeId == 2 && !checkDuoxuanReply(item)) {
  204. count++;
  205. }
  206. if (item.stTypeId == 3 && !checkPanduanReply(item)) {
  207. count++;
  208. }
  209. if (item.stTypeId == 4 && !checkTiankongReply(item)) {
  210. count++;
  211. }
  212. })
  213. return {
  214. total,
  215. count,
  216. }
  217. }
  218. function handleJiaojuan() {
  219. const result = checkJiaojuan()
  220. console.log(result)
  221. if (result.count) {
  222. // 提示
  223. answerQrRef.value.showDialog({
  224. answercartsCount: result.total - result.count,
  225. answercartsTotal: result.total,
  226. })
  227. } else {
  228. handleSubmit()
  229. }
  230. }
  231. function handleQuerenConfirm() {
  232. handleSubmit()
  233. }
  234. function handleSubmit(force = false) {
  235. const result = {
  236. force,
  237. operId: data.operId,
  238. replyList: []
  239. };
  240. questionData.value.forEach(dl => {
  241. dl.qas.forEach(st => {
  242. const opt = {
  243. stId: st.stId,
  244. reply: st.reply
  245. }
  246. result.replyList.push(opt)
  247. })
  248. })
  249. // uni.showLoading({
  250. // title: '提交中'
  251. // })
  252. lxApi.getClientLianxiSubmit(result).then(res => {
  253. if (res.code == 0) {
  254. data.hisId = res.data.hisId;
  255. subScoreRef.value.showDialog(res.data);
  256. }
  257. }).finally(() => {
  258. // uni.hideLoading()
  259. })
  260. }
  261. function onTimeUp() {
  262. handleSubmit(true);
  263. }
  264. // 交卷相关功能 end
  265. function forceSubmit() {
  266. // 强制交卷
  267. console.log('强制交卷')
  268. handleSubmit(true)
  269. }
  270. function getQaClass(qa) {
  271. if (qa.marked && qa.marked === true) {
  272. return 'paragraph-qa-block-mark';
  273. } else {
  274. if (qa.stTypeId == 1) {
  275. if (checkDanxuanReply(qa)) {
  276. return 'paragraph-qa-block-done';
  277. } else {
  278. return 'paragraph-qa-block-init';
  279. }
  280. } else if (qa.stTypeId == 2) {
  281. if (checkDuoxuanReply(qa)) {
  282. return 'paragraph-qa-block-done';
  283. } else {
  284. return 'paragraph-qa-block-init';
  285. }
  286. } else if (qa.stTypeId == 3) {
  287. if (checkPanduanReply(qa)) {
  288. return 'paragraph-qa-block-done';
  289. } else {
  290. return 'paragraph-qa-block-init';
  291. }
  292. } else if (qa.stTypeId == 4) {
  293. if (checkTiankongReply(qa)) {
  294. return 'paragraph-qa-block-done';
  295. } else {
  296. return 'paragraph-qa-block-init';
  297. }
  298. }
  299. }
  300. }
  301. function skipQuestion(dlIndex, dtIndex) {
  302. progress.dlIndex = dlIndex;
  303. progress.dtIndex = dtIndex;
  304. handlePopupBack()
  305. }
  306. function answerCardItemClick(qa) {
  307. const actQa = data.StListForSearch.find(item => item.stId == qa.stId);
  308. skipQuestion(actQa.dlIndex, actQa.dtIndex)
  309. }
  310. function handleBack() {
  311. const pages = getCurrentPages();
  312. if (pages.length>1) {
  313. uni.navigateBack()
  314. } else {
  315. /* if (data.from == 'shouye') {
  316. uni.redirectTo({
  317. url: '/pages/client/ShouYe/shouye'
  318. })
  319. } else if (data.from == 'lianxiList') {
  320. uni.redirectTo({
  321. url: '/pages/client/Lianxi/list'
  322. })
  323. } else {
  324. uni.redirectTo({
  325. url: "/pages/client/ShouYe/shouye"
  326. })
  327. } */
  328. history.back();
  329. }
  330. }
  331. function showAnswerCard() {
  332. popupRef.value.open('top')
  333. }
  334. function handlePopupBack() {
  335. popupRef.value && popupRef.value.close()
  336. }
  337. function handlePrev() {
  338. const qa = data.StListForSearch.find(item => item.stId == activeSt.value.stId);
  339. const index = qa.onlyNum - 1;
  340. if (index > 0) {
  341. const result = data.StListForSearch[index - 1];
  342. progress.dlIndex = result.dlIndex;
  343. progress.dtIndex = result.dtIndex
  344. }
  345. }
  346. function handleNext() {
  347. const qa = data.StListForSearch.find(item => item.stId == activeSt.value.stId);
  348. const index = qa.onlyNum - 1;
  349. if (index < data.StListForSearch.length) {
  350. const result = data.StListForSearch[index + 1];
  351. progress.dlIndex = result.dlIndex;
  352. progress.dtIndex = result.dtIndex
  353. }
  354. }
  355. function formatDuanluoList(dlData) {
  356. let uIndex = 0; // 试题onlyNum
  357. let iDuanluo = 0; // 段落onlyNum
  358. let result = [];
  359. for (const duanluo of data.duanluo) {
  360. let paragraph = {
  361. qas: [],
  362. };
  363. paragraph.name = duanluo.name;
  364. let iQa = 0; // 当前试题序号
  365. let order = 0; // 当前题型中第几题
  366. for (const iDanxuan of duanluo.danxuan) {
  367. iDanxuan.type = 'danxuan';
  368. iDanxuan.marked = data.biaoji[iDanxuan.stId] ? true: false;
  369. iDanxuan.onlyNum = uIndex + 1;
  370. iDanxuan.order = order;
  371. iDanxuan.iQa = iQa;
  372. paragraph.qas.push(iDanxuan);
  373. uIndex++;
  374. order++;
  375. iQa++;
  376. data.StListForSearch.push({
  377. stId: iDanxuan.stId,
  378. paragraphName: paragraph.name,
  379. dlIndex: iDuanluo,
  380. dtIndex: iDanxuan.iQa,
  381. onlyNum: iDanxuan.onlyNum
  382. })
  383. }
  384. order = 0;
  385. for (const iDuoxuan of duanluo.duoxuan) {
  386. iDuoxuan.type = 'duoxuan';
  387. iDuoxuan.marked = data.biaoji[iDuoxuan.stId] ? true: false;
  388. iDuoxuan.onlyNum = uIndex + 1;
  389. iDuoxuan.order = order;
  390. paragraph.qas.push(iDuoxuan);
  391. iDuoxuan.iQa = iQa;
  392. iDuoxuan.reply = [];
  393. uIndex++;
  394. order++;
  395. iQa++;
  396. data.StListForSearch.push({
  397. stId: iDuoxuan.stId,
  398. paragraphName: paragraph.name,
  399. dlIndex: iDuanluo,
  400. dtIndex: iDuoxuan.iQa,
  401. onlyNum: iDuoxuan.onlyNum
  402. })
  403. }
  404. order = 0;
  405. for (const iPanduan of duanluo.panduan) {
  406. iPanduan.type = 'panduan';
  407. iPanduan.marked = data.biaoji[iPanduan.stId] ? true: false;
  408. iPanduan.onlyNum = uIndex + 1;
  409. iPanduan.order = order;
  410. paragraph.qas.push(iPanduan);
  411. iPanduan.iQa = iQa;
  412. uIndex++;
  413. order++;
  414. iQa++;
  415. data.StListForSearch.push({
  416. stId: iPanduan.stId,
  417. paragraphName: paragraph.name,
  418. dlIndex: iDuanluo,
  419. dtIndex: iPanduan.iQa,
  420. onlyNum: iPanduan.onlyNum
  421. })
  422. }
  423. order = 0;
  424. for (const iTiankong of duanluo.tiankong) {
  425. iTiankong.type = 'tiankong';
  426. iTiankong.marked = data.biaoji[iTiankong.stId] ? true: false;
  427. iTiankong.onlyNum = uIndex + 1;
  428. iTiankong.order = order;
  429. paragraph.qas.push(iTiankong);
  430. iTiankong.iQa = iQa;
  431. iTiankong.reply = new Array(iTiankong.count).fill('');;
  432. uIndex++;
  433. order++;
  434. iQa++;
  435. data.StListForSearch.push({
  436. stId: iTiankong.stId,
  437. paragraphName: paragraph.name,
  438. dlIndex: iDuanluo,
  439. dtIndex: iTiankong.iQa,
  440. onlyNum: iTiankong.onlyNum
  441. })
  442. }
  443. iDuanluo++;
  444. questionData.value.push(paragraph)
  445. console.log('1', questionData.value)
  446. console.log('2', data.StListForSearch)
  447. }
  448. }
  449. function handleBiaoji() {
  450. activeSt.value.marked = !activeSt.value.marked;
  451. data.biaoji.value[activeSt.value.stId] = activeSt.value.marked
  452. lxApi.getClientLianxiBiaoji({
  453. operId: data.operId,
  454. biaoji: JSON.stringify(data.biaoji)
  455. }).catch(err => {
  456. uni.redirectTo({
  457. url: '/pages/client/Lianxi/list'
  458. })
  459. })
  460. }
  461. function initKaoshi() {
  462. lxApi.getClientLianxiStart({
  463. lxId: data.lxId
  464. }).then(res => {
  465. const {
  466. lxId,
  467. operId,
  468. lxName,
  469. stTotal,
  470. stScore,
  471. biaoji,
  472. endSecond,
  473. pageSize,
  474. toggleScreenFlag,
  475. toggleScreenSecond,
  476. zhuapai,
  477. duanluoList
  478. } = res.data;
  479. data.lxId = lxId;
  480. data.operId = operId;
  481. data.lxName = lxName;
  482. data.stTotal = stTotal;
  483. data.stScore = stScore;
  484. data.biaoji = biaoji ? JSON.parse(biaoji): {};
  485. data.endSecond = endSecond;
  486. data.pageSize = pageSize;
  487. data.duanluo = duanluoList;
  488. formatDuanluoList(data.duanluo);
  489. uni.setNavigationBarTitle({
  490. title: data.lxName
  491. });
  492. startCountDown.value = true;
  493. }).catch(err => {
  494. handleBack()
  495. })
  496. }
  497. </script>