exam.vue 13 KB

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