exam.vue 13 KB

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