exam.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. <template>
  2. <view class="phone-kaoshi-page">
  3. <!-- 导航区域 -->
  4. <view class="icon-title-bjcolor-navBar-box">
  5. <view @click="handleBack" class="nav-bar-icon"></view>
  6. <text class="nav-bar-title">{{data.lxName}}</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>
  18. <view class="kaoshi-shiti-content">
  19. <!-- 内容区域 -->
  20. <!-- 试题区域 -->
  21. <view v-if="activeSt">
  22. <template v-if="activeSt.stTypeId == 1">
  23. <!-- 单选 -->
  24. <danxuan :question="activeSt" :key="activeSt.stId"></danxuan>
  25. </template>
  26. <template v-if="activeSt.stTypeId == 2">
  27. <!-- 多选 -->
  28. <duoxuan :question="activeSt" :key="activeSt.stId"></duoxuan>
  29. </template>
  30. <template v-if="activeSt.stTypeId == 3">
  31. <!-- 判断 -->
  32. <panduan :question="activeSt" :key="activeSt.stId"></panduan>
  33. </template>
  34. <template v-if="activeSt.stTypeId == 4">
  35. <!-- 填空 -->
  36. <tiankong :question="activeSt" :key="activeSt.stId"></tiankong>
  37. </template>
  38. </view>
  39. </view>
  40. <view class="kaoshi-bottom-box">
  41. <button class="phone-green-btn bj-btn" hover-class="none" type="default" size="mini"
  42. @click="handleBiaoji">{{activeSt && activeSt.marked ? '取标':'标记'}}</button>
  43. <view @click="showAnswerCard" class="shiti-num-box">
  44. <icon class="shiti-num-icon"></icon>
  45. <text
  46. class="active-num">{{activeSt ? activeSt.onlyNum: 0}}</text>/<text>{{data.StListForSearch.length}}</text>
  47. </view>
  48. </view>
  49. <template v-if="activeSt">
  50. <button type="default" size="mini" hover-class="none" class="phone-green-btn ks-btn-prev"
  51. @click="handlePrev" v-if="!isFistStId">上一题</button>
  52. <button type="default" size="mini" hover-class="none" class="phone-green-btn ks-btn-next"
  53. @click="handleNext" v-if="!isLastStId">下一题</button>
  54. <button type="default" size="mini" hover-class="none" class="phone-green-btn ks-btn-next"
  55. @click="handleJiaojuan" v-if="isLastStId">交卷</button>
  56. </template>
  57. <!-- 答题卡 -->
  58. <uni-popup ref="popupRef" background-color="#fff" :is-mask-click="false" :mask-click="false">
  59. <view class="answer-card-popup">
  60. <view class="icon-title-bjcolor-navBar-box">
  61. <view @click="handlePopupBack" class="nav-bar-icon"> </view>
  62. <text class="nav-bar-title">答题卡</text>
  63. </view>
  64. <view class="answer-card-content" v-for="(paragraph,paragraphIndex) in questionData"
  65. :key="paragraphIndex">
  66. <view class="paragraph-title">
  67. {{paragraph.name}}
  68. </view>
  69. <view class="paragraph-qa" v-for="(qa,qaIndex) in paragraph.qas" :key="qaIndex"
  70. :class="getQaClass(qa)" @click="answerCardItemClick(qa)">{{qa.onlyNum}}
  71. </view>
  72. </view>
  73. </view>
  74. </uni-popup>
  75. <!-- 交卷确认 -->
  76. <answerQueren ref="answerQrRef" @confirm="handleQuerenConfirm"></answerQueren>
  77. <!-- 考试得分 -->
  78. <submitScoreVue title="练习得分" ref="subScoreRef" @confirm="handleScoreConfirm" @close="handleScoreClose"></submitScoreVue>
  79. </view>
  80. </template>
  81. <script setup>
  82. import {
  83. ref,
  84. reactive,
  85. computed,
  86. watch,
  87. nextTick
  88. } from "vue";
  89. import answerQueren from "@/components/zhuapaiConfirm/answerQueren.vue";
  90. import submitScoreVue from "@/components/zhuapaiConfirm/submitScore.vue";
  91. import {
  92. onLoad
  93. } from "@dcloudio/uni-app";
  94. import * as lxApi from "@/api/lianxi.js"
  95. import danxuan from "@/components/questions/danxuan.vue";
  96. import duoxuan from "@/components/questions/duoxuan.vue";
  97. import tiankong from "@/components/questions/tiankong.vue";
  98. import panduan from "@/components/questions/panduan.vue";
  99. import {
  100. useQuestionTools
  101. } from "@/components/questions/useQuestionTools.js";
  102. const {
  103. checkDanxuanReply,
  104. checkDuoxuanReply,
  105. checkPanduanReply,
  106. checkTiankongReply,
  107. getLetterByIndex
  108. } = useQuestionTools();
  109. onLoad((option) => {
  110. data.lxId = option.lxId;
  111. data.zhuapai = option.zhuapai;
  112. data.from = option.from;
  113. initKaoshi();
  114. })
  115. const popupRef = ref(null)
  116. const zhuapaiConfirmRef = ref(null)
  117. const answerQrRef = ref(null);
  118. const startCountDown = ref(false);
  119. const subScoreRef = ref(null)
  120. const timer1 = ref(null);
  121. const data = reactive({
  122. lxId: null,
  123. operId: null,
  124. lxName: '',
  125. stTotal: 0,
  126. stScore: 0,
  127. biaoji: {},
  128. endSecond: 0,
  129. pageSize: 0,
  130. toggleScreenFlag: 0,
  131. toggleScreenSecond: 0,
  132. zhuapai: 0,
  133. duanluo: [],
  134. StListForSearch: [],
  135. from: '',
  136. hisId: null
  137. })
  138. const markDB = ref([]);
  139. const questionData = ref([]);
  140. const progress = reactive({
  141. dlIndex: 0,
  142. dtIndex: 0
  143. })
  144. const dlName = computed(() => {
  145. if (data.StListForSearch && activeSt.value) {
  146. return data.StListForSearch[activeSt.value.onlyNum - 1].paragraphName
  147. } else {
  148. return ''
  149. }
  150. })
  151. watch(() => data.duanluo, (newVal) => {
  152. // 计算已答试题数量
  153. }, {
  154. deep: true
  155. })
  156. const activeSt = computed(() => {
  157. if (questionData.value.length) {
  158. return questionData.value.length && questionData.value[progress.dlIndex].qas[progress.dtIndex];
  159. } else {
  160. return null
  161. }
  162. })
  163. const isFistStId = computed(() => {
  164. if (data.StListForSearch.length) {
  165. return data.StListForSearch[0].stId == activeSt.value.stId
  166. } else {
  167. return false
  168. }
  169. });
  170. const isLastStId = computed(() => {
  171. if (data.StListForSearch.length) {
  172. return data.StListForSearch[data.StListForSearch.length - 1].stId == activeSt.value.stId
  173. } else {
  174. return false
  175. }
  176. });
  177. function handleScoreClose() {
  178. if (data.from == 'shouye') {
  179. uni.redirectTo({
  180. url: '/pages/client/ShouYe/shouye'
  181. })
  182. } else if (data.from == 'lianxiList') {
  183. uni.redirectTo({
  184. url: '/pages/client/Lianxi/list'
  185. })
  186. } else {
  187. uni.redirectTo({
  188. url: "/pages/client/ShouYe/shouye"
  189. })
  190. }
  191. }
  192. // 考试得分相关 start
  193. function handleScoreConfirm() {
  194. uni.redirectTo({
  195. url: `/pages/client/Chengji/lxScoreShijuan?hisId=${data.hisId}&from=lianxi`
  196. })
  197. }
  198. // 考试得分相关 end
  199. // 交卷相关功能 start
  200. function checkJiaojuan() {
  201. const result = []
  202. let count = 0;
  203. let total = 0;
  204. questionData.value.forEach(dl => {
  205. dl.qas.forEach(st => {
  206. const opt = {
  207. stId: st.stId,
  208. reply: st.reply,
  209. stTypeId: st.stTypeId
  210. }
  211. result.push(opt)
  212. })
  213. })
  214. result.forEach(item => {
  215. total++;
  216. if (item.stTypeId == 1 && !checkDanxuanReply(item)) {
  217. count++;
  218. }
  219. if (item.stTypeId == 2 && !checkDuoxuanReply(item)) {
  220. count++;
  221. }
  222. if (item.stTypeId == 3 && !checkPanduanReply(item)) {
  223. count++;
  224. }
  225. if (item.stTypeId == 4 && !checkTiankongReply(item)) {
  226. count++;
  227. }
  228. })
  229. return {
  230. total,
  231. count,
  232. }
  233. }
  234. function handleJiaojuan() {
  235. const result = checkJiaojuan()
  236. console.log(result)
  237. if (result.count) {
  238. // 提示
  239. answerQrRef.value.showDialog({
  240. answercartsCount: result.count,
  241. answercartsTotal: result.total,
  242. })
  243. } else {
  244. handleSubmit()
  245. }
  246. }
  247. function handleQuerenConfirm() {
  248. handleSubmit()
  249. }
  250. function handleSubmit(force = false) {
  251. const result = {
  252. force,
  253. operId: data.operId,
  254. replyList: []
  255. };
  256. questionData.value.forEach(dl => {
  257. dl.qas.forEach(st => {
  258. const opt = {
  259. stId: st.stId,
  260. reply: st.reply
  261. }
  262. result.replyList.push(opt)
  263. })
  264. })
  265. uni.showLoading({
  266. title: '加载中'
  267. })
  268. lxApi.getClientLianxiSubmit(result).then(res => {
  269. if (res.code == 0) {
  270. data.hisId = res.data.hisId;
  271. subScoreRef.value.showDialog(res.data);
  272. }
  273. }).finally(() => {
  274. uni.hideLoading()
  275. })
  276. }
  277. function onTimeUp() {
  278. handleSubmit(true);
  279. }
  280. // 交卷相关功能 end
  281. function forceSubmit() {
  282. // 强制交卷
  283. console.log('强制交卷')
  284. handleSubmit(true)
  285. }
  286. function getQaClass(qa) {
  287. if (qa.marked && qa.marked === true) {
  288. return 'paragraph-qa-block-mark';
  289. } else {
  290. if (qa.stTypeId == 1) {
  291. if (checkDanxuanReply(qa)) {
  292. return 'paragraph-qa-block-done';
  293. } else {
  294. return 'paragraph-qa-block-init';
  295. }
  296. } else if (qa.stTypeId == 2) {
  297. if (checkDuoxuanReply(qa)) {
  298. return 'paragraph-qa-block-done';
  299. } else {
  300. return 'paragraph-qa-block-init';
  301. }
  302. } else if (qa.stTypeId == 3) {
  303. if (checkPanduanReply(qa)) {
  304. return 'paragraph-qa-block-done';
  305. } else {
  306. return 'paragraph-qa-block-init';
  307. }
  308. } else if (qa.stTypeId == 4) {
  309. if (checkTiankongReply(qa)) {
  310. return 'paragraph-qa-block-done';
  311. } else {
  312. return 'paragraph-qa-block-init';
  313. }
  314. }
  315. }
  316. }
  317. function skipQuestion(dlIndex, dtIndex) {
  318. progress.dlIndex = dlIndex;
  319. progress.dtIndex = dtIndex;
  320. handlePopupBack()
  321. }
  322. function answerCardItemClick(qa) {
  323. const actQa = data.StListForSearch.find(item => item.stId == qa.stId);
  324. skipQuestion(actQa.dlIndex, actQa.dtIndex)
  325. }
  326. function handleBack() {
  327. uni.redirectTo({
  328. url: "/pages/client/Lianxi/list"
  329. })
  330. }
  331. function showAnswerCard() {
  332. popupRef.value.open('bottom')
  333. }
  334. function handlePopupBack() {
  335. 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. })
  494. }
  495. </script>