exam.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. <template>
  2. <view class="phone-kaoshi-page">
  3. <!-- 导航区域 -->
  4. <view class="phone-navBar-box">
  5. <view @click="handleBack" class="nav-bar-icon"><uni-icons type="left" size="20"></uni-icons></view>
  6. <text class="nav-bar-title">{{data.ksName}}</text>
  7. </view>
  8. <!-- 第一行 -->
  9. <view class="kaoshi-page-title">
  10. <view v-if="activeSt">{{stTypes[activeSt.stTypeId]}}</view>
  11. <view>100分钟</view>
  12. </view>
  13. <view class="kaoshi-shiti-content">
  14. <!-- 内容区域 -->
  15. <!-- 试题区域 -->
  16. <view v-if="activeSt">
  17. <template v-if="activeSt.stTypeId == 1">
  18. <!-- 单选 -->
  19. <danxuan :question="activeSt" :key="activeSt.stId"></danxuan>
  20. </template>
  21. <template v-if="activeSt.stTypeId == 2" >
  22. <!-- 多选 -->
  23. <duoxuan :question="activeSt" :key="activeSt.stId"></duoxuan>
  24. </template>
  25. <template v-if="activeSt.stTypeId == 3">
  26. <!-- 判断 -->
  27. <panduan :question="activeSt" :key="activeSt.stId"></panduan>
  28. </template>
  29. <template v-if="activeSt.stTypeId == 4">
  30. <!-- 填空 -->
  31. <tiankong :question="activeSt" :key="activeSt.stId"></tiankong>
  32. </template>
  33. </view>
  34. </view>
  35. <view class="kaoshi-bottom-card">
  36. <view style="margin:0 10px">
  37. <button class="biaoji-btn" type="primary" size="mini" @click="handleBiaoji">标记</button>
  38. </view>
  39. <view @click="showAnswerCard">
  40. <text style="color: green;">{{activeSt ? activeSt.onlyNum: 0}}</text>/<text>{{data.StListForSearch.length}}</text>
  41. </view>
  42. <view style="flex:1;text-align: right;">
  43. <button type="primary" size="mini" @click="handleCheckJiexi" style="margin-right: 10px">解析</button>
  44. <button type="primary" size="mini" @click="handleBack">完成</button>
  45. </view>
  46. </view>
  47. <template v-if="activeSt">
  48. <button type="primary" size="mini" class="ks-btn-prev" @click="handlePrev" v-if="!isFistStId">上一题</button>
  49. <button type="primary" size="mini" class="ks-btn-next" @click="handleNext" v-if="!isLastStId">下一题</button>
  50. </template>
  51. <!-- 答题卡 -->
  52. <uni-popup ref="popupRef" background-color="#fff" :is-mask-click="false" :mask-click="false">
  53. <view class="popup-content" style="height: 100vh">
  54. <view class="popup-phone-navBar-box">
  55. <view @click="handlePopupBack" class="nav-bar-icon"><uni-icons type="left" size="20"></uni-icons>
  56. </view>
  57. <text class="nav-bar-title">答题卡</text>
  58. </view>
  59. <view class="main-container">
  60. <view class="paragraph" v-for="(paragraph,paragraphIndex) in questionData" :key="paragraphIndex">
  61. <view class="paragraph-title">
  62. {{paragraph.name}}
  63. </view>
  64. <view class="paragraph-qa-content">
  65. <view class="paragraph-qa" v-for="(qa,qaIndex) in paragraph.qas" :key="qaIndex">
  66. <view class="paragraph-qa-block">
  67. <view :class="getQaClass(qa)" @click="answerCardItemClick(qa)">
  68. {{qa.onlyNum}}
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. </uni-popup>
  77. <!--
  78. // 倒计时
  79. <view v-if="!!data.endSecond">
  80. <text>考试倒计时:</text>
  81. <uni-countdown :show-day="false" :second="1000" @timeup="onTimeUp" :start="startCountDown"></uni-countdown>
  82. </view>
  83. -->
  84. <!-- 答案解析 -->
  85. <scoreAndAnswerVue ref="scoreAnswerRef"></scoreAndAnswerVue>
  86. </view>
  87. </template>
  88. <script setup>
  89. import {
  90. ref,
  91. reactive,
  92. computed,
  93. watch
  94. } from "vue";
  95. import {
  96. onLoad
  97. } from "@dcloudio/uni-app";
  98. import * as ksApi from "@/api/kaoshi.js"
  99. import danxuan from "@/components/questions/danxuan.vue";
  100. import duoxuan from "@/components/questions/duoxuan.vue";
  101. import tiankong from "@/components/questions/tiankong.vue";
  102. import panduan from "@/components/questions/panduan.vue";
  103. import scoreAndAnswerVue from "@/components/scoreAndAnswer/scoreAndAnswerAdmin.vue";
  104. import {useQuestionTools} from "@/components/questions/useQuestionTools.js";
  105. const {
  106. checkDanxuanReply,
  107. checkDuoxuanReply,
  108. checkPanduanReply,
  109. checkTiankongReply,
  110. getLetterByIndex
  111. } = useQuestionTools();
  112. const stTypes = {
  113. 1: '单选题',
  114. 2: '多选题',
  115. 3: '判断题',
  116. 4: '填空题',
  117. }
  118. const popupRef = ref(null)
  119. const scoreAnswerRef = ref(null)
  120. const startCountDown = ref(false);
  121. const data = reactive({
  122. ksId: null,
  123. ksName: '',
  124. stTotal: 0,
  125. stScore: 0,
  126. biaoji: null,
  127. endSecond: 0,
  128. pageSize: 0,
  129. toggleScreenFlag: 0,
  130. toggleScreenSecond: 0,
  131. zhuapai: 0,
  132. duanluo: [],
  133. markDB: [],
  134. StListForSearch: [],
  135. })
  136. const questionData = ref([]);
  137. const progress = reactive({
  138. dlIndex: 0,
  139. dtIndex: 0
  140. })
  141. watch(() => data.duanluo, (newVal) => {
  142. // 计算已答试题数量
  143. }, {
  144. deep: true
  145. })
  146. const activeSt = computed(() => {
  147. if (questionData.value.length) {
  148. return questionData.value.length && questionData.value[progress.dlIndex].qas[progress.dtIndex];
  149. } else {
  150. return null
  151. }
  152. })
  153. const isFistStId = computed(() => {
  154. if (data.StListForSearch.length) {
  155. return data.StListForSearch[0].stId == activeSt.value.stId
  156. } else {
  157. return false
  158. }
  159. });
  160. const isLastStId = computed(() => {
  161. if (data.StListForSearch.length) {
  162. return data.StListForSearch[data.StListForSearch.length - 1].stId == activeSt.value.stId
  163. } else {
  164. return false
  165. }
  166. });
  167. onLoad((option) => {
  168. data.ksId = option.ksId;
  169. initKaoshi();
  170. })
  171. function getQaClass(qa) {
  172. if (qa.marked && qa.marked === true) {
  173. return 'paragraph-qa-block-mark';
  174. } else {
  175. if (qa.stTypeId == 1) {
  176. if (checkDanxuanReply(qa)) {
  177. return 'paragraph-qa-block-done';
  178. } else {
  179. return 'paragraph-qa-block-init';
  180. }
  181. } else if (qa.stTypeId == 2) {
  182. if (checkDuoxuanReply(qa)) {
  183. return 'paragraph-qa-block-done';
  184. } else {
  185. return 'paragraph-qa-block-init';
  186. }
  187. } else if (qa.stTypeId == 3) {
  188. if (checkPanduanReply(qa)) {
  189. return 'paragraph-qa-block-done';
  190. } else {
  191. return 'paragraph-qa-block-init';
  192. }
  193. } else if (qa.stTypeId == 4) {
  194. if (checkTiankongReply(qa)) {
  195. return 'paragraph-qa-block-done';
  196. } else {
  197. return 'paragraph-qa-block-init';
  198. }
  199. }
  200. }
  201. }
  202. function skipQuestion(dlIndex, dtIndex) {
  203. progress.dlIndex = dlIndex;
  204. progress.dtIndex = dtIndex;
  205. handlePopupBack()
  206. }
  207. function answerCardItemClick(qa) {
  208. const actQa = data.StListForSearch.find(item => item.stId == qa.stId);
  209. skipQuestion(actQa.dlIndex, actQa.dtIndex)
  210. }
  211. function handleBack() {
  212. uni.redirectTo({
  213. url: "/pages/admin/Kaoshi/list"
  214. })
  215. }
  216. function onTimeUp() {
  217. console.log('end')
  218. }
  219. function showAnswerCard() {
  220. popupRef.value.open('bottom')
  221. }
  222. function handlePopupBack() {
  223. popupRef.value.close()
  224. }
  225. function handlePrev() {
  226. const qa = data.StListForSearch.find(item => item.stId == activeSt.value.stId);
  227. const index = qa.num - 1;
  228. if (index > 0) {
  229. const result = data.StListForSearch[index - 1];
  230. progress.dlIndex = result.dlIndex;
  231. progress.dtIndex = result.dtIndex
  232. }
  233. }
  234. function handleNext() {
  235. const qa = data.StListForSearch.find(item => item.stId == activeSt.value.stId);
  236. const index = qa.num - 1;
  237. if (index < data.StListForSearch.length) {
  238. const result = data.StListForSearch[index + 1];
  239. progress.dlIndex = result.dlIndex;
  240. progress.dtIndex = result.dtIndex
  241. }
  242. }
  243. function formatDuanluoList(dlData) {
  244. let uIndex = 0; // 试题num
  245. let iDuanluo = 0; // 段落num
  246. let result = [];
  247. for (const duanluo of data.duanluo) {
  248. let paragraph = {
  249. qas: [],
  250. };
  251. paragraph.name = duanluo.name;
  252. let iQa = 0; // 当前试题序号
  253. let order = 0; // 当前题型中第几题
  254. for (const iDanxuan of duanluo.danxuan) {
  255. iDanxuan.type = 'danxuan';
  256. iDanxuan.marked = false;
  257. iDanxuan.onlyNum = uIndex + 1;
  258. iDanxuan.order = order;
  259. iDanxuan.iQa = iQa;
  260. iDanxuan.reply = iDanxuan.result;
  261. paragraph.qas.push(iDanxuan);
  262. uIndex++;
  263. order++;
  264. iQa++;
  265. data.StListForSearch.push({
  266. stId: iDanxuan.stId,
  267. paragraphName: paragraph.name,
  268. dlIndex: iDuanluo,
  269. dtIndex: iDanxuan.iQa,
  270. num: iDanxuan.onlyNum
  271. })
  272. }
  273. order = 0;
  274. for (const iDuoxuan of duanluo.duoxuan) {
  275. iDuoxuan.type = 'duoxuan';
  276. iDuoxuan.marked = false;
  277. iDuoxuan.onlyNum = uIndex + 1;
  278. iDuoxuan.order = order;
  279. paragraph.qas.push(iDuoxuan);
  280. iDuoxuan.reply = iDuoxuan.result;
  281. iDuoxuan.iQa = iQa;
  282. uIndex++;
  283. order++;
  284. iQa++;
  285. data.StListForSearch.push({
  286. stId: iDuoxuan.stId,
  287. paragraphName: paragraph.name,
  288. dlIndex: iDuanluo,
  289. dtIndex: iDuoxuan.iQa,
  290. num: iDuoxuan.onlyNum
  291. })
  292. }
  293. order = 0;
  294. for (const iPanduan of duanluo.panduan) {
  295. iPanduan.type = 'panduan';
  296. iPanduan.marked = false;
  297. iPanduan.onlyNum = uIndex + 1;
  298. iPanduan.order = order;
  299. paragraph.qas.push(iPanduan);
  300. iPanduan.reply = iPanduan.result;
  301. iPanduan.iQa = iQa;
  302. uIndex++;
  303. order++;
  304. iQa++;
  305. data.StListForSearch.push({
  306. stId: iPanduan.stId,
  307. paragraphName: paragraph.name,
  308. dlIndex: iDuanluo,
  309. dtIndex: iPanduan.iQa,
  310. num: iPanduan.onlyNum
  311. })
  312. }
  313. order = 0;
  314. for (const iTiankong of duanluo.tiankong) {
  315. iTiankong.type = 'tiankong';
  316. iTiankong.marked = false;
  317. iTiankong.onlyNum = uIndex + 1;
  318. iTiankong.order = order;
  319. paragraph.qas.push(iTiankong);
  320. iTiankong.reply = iTiankong.result.map(item => item[0]);
  321. iTiankong.iQa = iQa;
  322. uIndex++;
  323. order++;
  324. iQa++;
  325. data.StListForSearch.push({
  326. stId: iTiankong.stId,
  327. paragraphName: paragraph.name,
  328. dlIndex: iDuanluo,
  329. dtIndex: iTiankong.iQa,
  330. num: iTiankong.onlyNum
  331. })
  332. }
  333. iDuanluo++;
  334. questionData.value.push(paragraph)
  335. console.log(questionData.value)
  336. }
  337. }
  338. function handleBiaoji() {
  339. activeSt.value.marked = !activeSt.value.marked;
  340. }
  341. function handleCheckJiexi() {
  342. const qa = activeSt.value ;
  343. let score = qa.score;
  344. let reply = '';
  345. let result = '';
  346. let answer = qa.answer;
  347. if (qa.stTypeId == 1) {
  348. // 单选题
  349. if (qa.reply && qa.reply.trim() !== '') {
  350. reply = getLetterByIndex(qa.reply)
  351. }
  352. if (qa.result) {
  353. result = getLetterByIndex(qa.result)
  354. }
  355. }
  356. if (qa.stTypeId == 2) {
  357. // 多选题
  358. if (qa.reply && qa.reply.length) {
  359. reply = reply.map(item => {
  360. if (item.trim()) {
  361. return getLetterByIndex(item.trim())
  362. }
  363. })
  364. }
  365. if (qa.result) {
  366. result = result.map(item => {
  367. if (item.trim()) {
  368. return getLetterByIndex(item.trim())
  369. }
  370. })
  371. }
  372. }
  373. if (qa.stTypeId == 3) {
  374. // 判断题
  375. if (qa.reply == 0) {
  376. reply = '错误'
  377. }else if (qa.reply == 1) {
  378. reply = '正确'
  379. }
  380. if (qa.result == 0) {
  381. result = '错误'
  382. }else if (qa.result == 1) {
  383. result = '正确'
  384. }
  385. }
  386. if (qa.stTypeId == 4) {
  387. // 填空题
  388. }
  389. scoreAnswerRef.value.showPopup({
  390. score,reply,result,answer
  391. })
  392. }
  393. function initKaoshi() {
  394. ksApi.getKaoshiInfo({
  395. ksId: data.ksId
  396. }).then(res => {
  397. const {
  398. ksId,
  399. ksName,
  400. stTotal,
  401. stScore,
  402. biaoji,
  403. endSecond,
  404. pageSize,
  405. toggleScreenFlag,
  406. toggleScreenSecond,
  407. zhuapai,
  408. duanluoList
  409. } = res.data;
  410. data.ksId = ksId;
  411. data.ksName = ksName;
  412. data.stTotal = stTotal;
  413. data.stScore = stScore;
  414. data.biaoji = biaoji;
  415. data.endSecond = endSecond;
  416. data.pageSize = pageSize;
  417. data.toggleScreenFlag = toggleScreenFlag;
  418. data.toggleScreenSecond = toggleScreenSecond;
  419. data.zhuapai = zhuapai;
  420. data.duanluo = duanluoList;
  421. formatDuanluoList(data.duanluo);
  422. uni.setNavigationBarTitle({
  423. title: data.ksName
  424. });
  425. startCountDown.value = true;
  426. })
  427. }
  428. </script>
  429. <style lang="scss">
  430. .phone-kaoshi-page {
  431. background-color: #ccc;
  432. position: relative;
  433. .phone-navBar-box {
  434. width: 100%;
  435. height: 60px;
  436. background-color: #fff;
  437. text-align: center;
  438. position: relative;
  439. line-height: 60px;
  440. .nav-bar-icon {
  441. position: absolute;
  442. left: 0;
  443. top: 0
  444. }
  445. }
  446. .kaoshi-page-title {
  447. margin-top: 10px;
  448. background-color: #fff;
  449. height: 60px;
  450. line-height: 60px;
  451. display: flex;
  452. justify-content: space-between;
  453. padding: 0 10px;
  454. border-bottom: 1px solid #333;
  455. }
  456. .kaoshi-shiti-content {
  457. padding: 20px 20px 0 20px;
  458. height: calc(100vh - 211px);
  459. background-color: #fff;
  460. }
  461. .kaoshi-bottom-card {
  462. height: 60px;
  463. width: 100%;
  464. background-color: #ccc;
  465. display: flex;
  466. align-items: center;
  467. justify-content: flex-start;
  468. text-align: left;
  469. padding: 0 10px;
  470. box-sizing: border-box;
  471. }
  472. .ks-btn-prev {
  473. position: absolute;
  474. bottom: 150px;
  475. left: 0;
  476. }
  477. .ks-btn-next {
  478. position: absolute;
  479. bottom: 150px;
  480. right: 0;
  481. }
  482. .popup-phone-navBar-box {
  483. width: 100%;
  484. height: 60px;
  485. background-color: #fff;
  486. text-align: center;
  487. position: relative;
  488. line-height: 60px;
  489. .nav-bar-icon {
  490. position: absolute;
  491. left: 0;
  492. top: 0
  493. }
  494. }
  495. .paragraph-qa-content {
  496. display: flex;
  497. flex-wrap: wrap;
  498. .paragraph-qa {
  499. margin: 10px;
  500. width: 40px;
  501. height: 40px;
  502. text-align: center;
  503. line-height: 40px;
  504. border: 1px solid #ccc;
  505. border-radius: 50%;
  506. overflow: hidden;
  507. }
  508. // 答题卡 答完样式
  509. .paragraph-qa-block-done {
  510. background-color: skyblue;
  511. }
  512. // 答题卡 未答完样式
  513. .paragraph-qa-block-init {
  514. background-color: #ccc;
  515. }
  516. // 答题卡 标记样式
  517. .paragraph-qa-block-mark {
  518. background-color: orange;
  519. }
  520. }
  521. }
  522. </style>