exam.vue 13 KB

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