exam.vue 13 KB

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