exam.vue 13 KB

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