exam.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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"></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 {ref,reactive,computed,watch,nextTick} from "vue";
  79. import customNavbarVue from "@/components/custom-navbar/custom-navbar.vue";
  80. import answerQueren from "@/components/zhuapaiConfirm/answerQueren.vue";
  81. import submitScoreVue from "@/components/zhuapaiConfirm/submitScore.vue";
  82. import {
  83. onLoad
  84. } from "@dcloudio/uni-app";
  85. import * as lxApi from "@/api/lianxi.js"
  86. import danxuan from "@/components/questions/danxuan.vue";
  87. import duoxuan from "@/components/questions/duoxuan.vue";
  88. import tiankong from "@/components/questions/tiankong.vue";
  89. import panduan from "@/components/questions/panduan.vue";
  90. import {
  91. useQuestionTools
  92. } from "@/components/questions/useQuestionTools.js";
  93. const {
  94. checkDanxuanReply,
  95. checkDuoxuanReply,
  96. checkPanduanReply,
  97. checkTiankongReply,
  98. getLetterByIndex
  99. } = useQuestionTools();
  100. onLoad((option) => {
  101. data.lxId = option.lxId;
  102. data.zhuapai = option.zhuapai;
  103. data.from = option.from;
  104. initKaoshi();
  105. })
  106. const popupRef = ref(null)
  107. const zhuapaiConfirmRef = ref(null)
  108. const answerQrRef = ref(null);
  109. const startCountDown = ref(false);
  110. const subScoreRef = ref(null)
  111. const timer1 = ref(null);
  112. const data = reactive({
  113. lxId: null,
  114. operId: null,
  115. lxName: '',
  116. stTotal: 0,
  117. stScore: 0,
  118. biaoji: {},
  119. endSecond: 0,
  120. pageSize: 0,
  121. toggleScreenFlag: 0,
  122. toggleScreenSecond: 0,
  123. zhuapai: 0,
  124. duanluo: [],
  125. StListForSearch: [],
  126. from: '',
  127. hisId: null
  128. })
  129. const markDB = ref([]);
  130. const questionData = ref([]);
  131. const progress = reactive({
  132. dlIndex: 0,
  133. dtIndex: 0
  134. })
  135. const dlName = computed(() => {
  136. if (data.StListForSearch && activeSt.value) {
  137. return data.StListForSearch[activeSt.value.onlyNum - 1].paragraphName
  138. } else {
  139. return ''
  140. }
  141. })
  142. watch(() => data.duanluo, (newVal) => {
  143. // 计算已答试题数量
  144. }, {
  145. deep: true
  146. })
  147. const activeSt = computed(() => {
  148. if (questionData.value.length) {
  149. return questionData.value.length && questionData.value[progress.dlIndex].qas[progress.dtIndex];
  150. } else {
  151. return null
  152. }
  153. })
  154. const isFistStId = computed(() => {
  155. if (data.StListForSearch.length) {
  156. return data.StListForSearch[0].stId == activeSt.value.stId
  157. } else {
  158. return false
  159. }
  160. });
  161. const isLastStId = computed(() => {
  162. if (data.StListForSearch.length) {
  163. return data.StListForSearch[data.StListForSearch.length - 1].stId == activeSt.value.stId
  164. } else {
  165. return false
  166. }
  167. });
  168. function handleScoreClose() {
  169. handleBack()
  170. }
  171. // 考试得分相关 start
  172. function handleScoreConfirm() {
  173. uni.redirectTo({
  174. url: `/pages/client/Chengji/lxScoreShijuan?hisId=${data.hisId}&from=lianxi`
  175. })
  176. }
  177. // 考试得分相关 end
  178. // 交卷相关功能 start
  179. function checkJiaojuan() {
  180. const result = []
  181. let count = 0;
  182. let total = 0;
  183. questionData.value.forEach(dl => {
  184. dl.qas.forEach(st => {
  185. const opt = {
  186. stId: st.stId,
  187. reply: st.reply,
  188. stTypeId: st.stTypeId
  189. }
  190. result.push(opt)
  191. })
  192. })
  193. result.forEach(item => {
  194. total++;
  195. if (item.stTypeId == 1 && !checkDanxuanReply(item)) {
  196. count++;
  197. }
  198. if (item.stTypeId == 2 && !checkDuoxuanReply(item)) {
  199. count++;
  200. }
  201. if (item.stTypeId == 3 && !checkPanduanReply(item)) {
  202. count++;
  203. }
  204. if (item.stTypeId == 4 && !checkTiankongReply(item)) {
  205. count++;
  206. }
  207. })
  208. return {
  209. total,
  210. count,
  211. }
  212. }
  213. function handleJiaojuan() {
  214. const result = checkJiaojuan()
  215. console.log(result)
  216. if (result.count) {
  217. // 提示
  218. answerQrRef.value.showDialog({
  219. answercartsCount: result.total - result.count,
  220. answercartsTotal: result.total,
  221. })
  222. } else {
  223. handleSubmit()
  224. }
  225. }
  226. function handleQuerenConfirm() {
  227. handleSubmit()
  228. }
  229. function handleSubmit(force = false) {
  230. const result = {
  231. force,
  232. operId: data.operId,
  233. replyList: []
  234. };
  235. questionData.value.forEach(dl => {
  236. dl.qas.forEach(st => {
  237. const opt = {
  238. stId: st.stId,
  239. reply: st.reply
  240. }
  241. result.replyList.push(opt)
  242. })
  243. })
  244. // uni.showLoading({
  245. // title: '提交中'
  246. // })
  247. lxApi.getClientLianxiSubmit(result).then(res => {
  248. if (res.code == 0) {
  249. data.hisId = res.data.hisId;
  250. subScoreRef.value.showDialog(res.data);
  251. }
  252. }).finally(() => {
  253. // uni.hideLoading()
  254. })
  255. }
  256. function onTimeUp() {
  257. handleSubmit(true);
  258. }
  259. // 交卷相关功能 end
  260. function forceSubmit() {
  261. // 强制交卷
  262. console.log('强制交卷')
  263. handleSubmit(true)
  264. }
  265. function getQaClass(qa) {
  266. if (qa.marked && qa.marked === true) {
  267. return 'paragraph-qa-block-mark';
  268. } else {
  269. if (qa.stTypeId == 1) {
  270. if (checkDanxuanReply(qa)) {
  271. return 'paragraph-qa-block-done';
  272. } else {
  273. return 'paragraph-qa-block-init';
  274. }
  275. } else if (qa.stTypeId == 2) {
  276. if (checkDuoxuanReply(qa)) {
  277. return 'paragraph-qa-block-done';
  278. } else {
  279. return 'paragraph-qa-block-init';
  280. }
  281. } else if (qa.stTypeId == 3) {
  282. if (checkPanduanReply(qa)) {
  283. return 'paragraph-qa-block-done';
  284. } else {
  285. return 'paragraph-qa-block-init';
  286. }
  287. } else if (qa.stTypeId == 4) {
  288. if (checkTiankongReply(qa)) {
  289. return 'paragraph-qa-block-done';
  290. } else {
  291. return 'paragraph-qa-block-init';
  292. }
  293. }
  294. }
  295. }
  296. function skipQuestion(dlIndex, dtIndex) {
  297. progress.dlIndex = dlIndex;
  298. progress.dtIndex = dtIndex;
  299. handlePopupBack()
  300. }
  301. function answerCardItemClick(qa) {
  302. const actQa = data.StListForSearch.find(item => item.stId == qa.stId);
  303. skipQuestion(actQa.dlIndex, actQa.dtIndex)
  304. }
  305. function handleBack() {
  306. const pages = getCurrentPages();
  307. if (pages.length>1) {
  308. uni.navigateBack()
  309. } else {
  310. /* if (data.from == 'shouye') {
  311. uni.redirectTo({
  312. url: '/pages/client/ShouYe/shouye'
  313. })
  314. } else if (data.from == 'lianxiList') {
  315. uni.redirectTo({
  316. url: '/pages/client/Lianxi/list'
  317. })
  318. } else {
  319. uni.redirectTo({
  320. url: "/pages/client/ShouYe/shouye"
  321. })
  322. } */
  323. history.back();
  324. }
  325. }
  326. function showAnswerCard() {
  327. popupRef.value.open('top')
  328. }
  329. function handlePopupBack() {
  330. popupRef.value && popupRef.value.close()
  331. }
  332. function handlePrev() {
  333. const qa = data.StListForSearch.find(item => item.stId == activeSt.value.stId);
  334. const index = qa.onlyNum - 1;
  335. if (index > 0) {
  336. const result = data.StListForSearch[index - 1];
  337. progress.dlIndex = result.dlIndex;
  338. progress.dtIndex = result.dtIndex
  339. }
  340. }
  341. function handleNext() {
  342. const qa = data.StListForSearch.find(item => item.stId == activeSt.value.stId);
  343. const index = qa.onlyNum - 1;
  344. if (index < data.StListForSearch.length) {
  345. const result = data.StListForSearch[index + 1];
  346. progress.dlIndex = result.dlIndex;
  347. progress.dtIndex = result.dtIndex
  348. }
  349. }
  350. function formatDuanluoList(dlData) {
  351. let uIndex = 0; // 试题onlyNum
  352. let iDuanluo = 0; // 段落onlyNum
  353. let result = [];
  354. for (const duanluo of data.duanluo) {
  355. let paragraph = {
  356. qas: [],
  357. };
  358. paragraph.name = duanluo.name;
  359. let iQa = 0; // 当前试题序号
  360. let order = 0; // 当前题型中第几题
  361. for (const iDanxuan of duanluo.danxuan) {
  362. iDanxuan.type = 'danxuan';
  363. iDanxuan.marked = data.biaoji[iDanxuan.stId] ? true: false;
  364. iDanxuan.onlyNum = uIndex + 1;
  365. iDanxuan.order = order;
  366. iDanxuan.iQa = iQa;
  367. paragraph.qas.push(iDanxuan);
  368. uIndex++;
  369. order++;
  370. iQa++;
  371. data.StListForSearch.push({
  372. stId: iDanxuan.stId,
  373. paragraphName: paragraph.name,
  374. dlIndex: iDuanluo,
  375. dtIndex: iDanxuan.iQa,
  376. onlyNum: iDanxuan.onlyNum
  377. })
  378. }
  379. order = 0;
  380. for (const iDuoxuan of duanluo.duoxuan) {
  381. iDuoxuan.type = 'duoxuan';
  382. iDuoxuan.marked = data.biaoji[iDuoxuan.stId] ? true: false;
  383. iDuoxuan.onlyNum = uIndex + 1;
  384. iDuoxuan.order = order;
  385. paragraph.qas.push(iDuoxuan);
  386. iDuoxuan.iQa = iQa;
  387. iDuoxuan.reply = [];
  388. uIndex++;
  389. order++;
  390. iQa++;
  391. data.StListForSearch.push({
  392. stId: iDuoxuan.stId,
  393. paragraphName: paragraph.name,
  394. dlIndex: iDuanluo,
  395. dtIndex: iDuoxuan.iQa,
  396. onlyNum: iDuoxuan.onlyNum
  397. })
  398. }
  399. order = 0;
  400. for (const iPanduan of duanluo.panduan) {
  401. iPanduan.type = 'panduan';
  402. iPanduan.marked = data.biaoji[iPanduan.stId] ? true: false;
  403. iPanduan.onlyNum = uIndex + 1;
  404. iPanduan.order = order;
  405. paragraph.qas.push(iPanduan);
  406. iPanduan.iQa = iQa;
  407. uIndex++;
  408. order++;
  409. iQa++;
  410. data.StListForSearch.push({
  411. stId: iPanduan.stId,
  412. paragraphName: paragraph.name,
  413. dlIndex: iDuanluo,
  414. dtIndex: iPanduan.iQa,
  415. onlyNum: iPanduan.onlyNum
  416. })
  417. }
  418. order = 0;
  419. for (const iTiankong of duanluo.tiankong) {
  420. iTiankong.type = 'tiankong';
  421. iTiankong.marked = data.biaoji[iTiankong.stId] ? true: false;
  422. iTiankong.onlyNum = uIndex + 1;
  423. iTiankong.order = order;
  424. paragraph.qas.push(iTiankong);
  425. iTiankong.iQa = iQa;
  426. iTiankong.reply = new Array(iTiankong.count).fill('');;
  427. uIndex++;
  428. order++;
  429. iQa++;
  430. data.StListForSearch.push({
  431. stId: iTiankong.stId,
  432. paragraphName: paragraph.name,
  433. dlIndex: iDuanluo,
  434. dtIndex: iTiankong.iQa,
  435. onlyNum: iTiankong.onlyNum
  436. })
  437. }
  438. iDuanluo++;
  439. questionData.value.push(paragraph)
  440. console.log('1', questionData.value)
  441. console.log('2', data.StListForSearch)
  442. }
  443. }
  444. function handleBiaoji() {
  445. activeSt.value.marked = !activeSt.value.marked;
  446. data.biaoji.value[activeSt.value.stId] = activeSt.value.marked
  447. lxApi.getClientLianxiBiaoji({
  448. operId: data.operId,
  449. biaoji: JSON.stringify(data.biaoji)
  450. }).catch(err => {
  451. uni.redirectTo({
  452. url: '/pages/client/Lianxi/list'
  453. })
  454. })
  455. }
  456. function initKaoshi() {
  457. lxApi.getClientLianxiStart({
  458. lxId: data.lxId
  459. }).then(res => {
  460. const {
  461. lxId,
  462. operId,
  463. lxName,
  464. stTotal,
  465. stScore,
  466. biaoji,
  467. endSecond,
  468. pageSize,
  469. toggleScreenFlag,
  470. toggleScreenSecond,
  471. zhuapai,
  472. duanluoList
  473. } = res.data;
  474. data.lxId = lxId;
  475. data.operId = operId;
  476. data.lxName = lxName;
  477. data.stTotal = stTotal;
  478. data.stScore = stScore;
  479. data.biaoji = biaoji ? JSON.parse(biaoji): {};
  480. data.endSecond = endSecond;
  481. data.pageSize = pageSize;
  482. data.duanluo = duanluoList;
  483. formatDuanluoList(data.duanluo);
  484. uni.setNavigationBarTitle({
  485. title: data.lxName
  486. });
  487. startCountDown.value = true;
  488. }).catch(err => {
  489. handleBack()
  490. })
  491. }
  492. </script>