exam.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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.ksName}}</text>
  7. </view>
  8. <!-- 第一行 -->
  9. <view class="kaoshi-page-title">
  10. <view v-if="activeSt" class="title-types">{{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-box">
  36. <button class="phone-green-btn bj-btn" hover-class="none" type="default" size="mini" @click="handleBiaoji">标记</button>
  37. <view @click="showAnswerCard" class="shiti-num-box">
  38. <icon class="shiti-num-icon"></icon>
  39. <text class="active-num">{{activeSt ? activeSt.onlyNum: 0}}</text>/<text>{{data.StListForSearch.length}}</text>
  40. </view>
  41. <button class="phone-white-btn jx-btn" hover-class="none" type="default" size="mini" @click="handleCheckJiexi">解析</button>
  42. </view>
  43. <template v-if="activeSt">
  44. <button type="default" size="mini" hover-class="none" class="phone-green-btn ks-btn-prev" @click="handlePrev" v-if="!isFistStId">上一题</button>
  45. <button type="default" size="mini" hover-class="none"class="phone-green-btn ks-btn-next" @click="handleNext" v-if="!isLastStId">下一题</button>
  46. </template>
  47. <!-- 答题卡 -->
  48. <uni-popup ref="popupRef" background-color="#fff" :is-mask-click="false" :mask-click="false">
  49. <view class="answer-card-popup">
  50. <view class="icon-title-bjcolor-navBar-box">
  51. <view @click="handlePopupBack" class="nav-bar-icon"> </view>
  52. <text class="nav-bar-title">答题卡</text>
  53. </view>
  54. <view class="answer-card-content" v-for="(paragraph,paragraphIndex) in questionData" :key="paragraphIndex">
  55. <view class="paragraph-title">
  56. {{paragraph.name}}
  57. </view>
  58. <view class="paragraph-qa" v-for="(qa,qaIndex) in paragraph.qas" :key="qaIndex"
  59. :class="getQaClass(qa)" @click="answerCardItemClick(qa)">{{qa.onlyNum}}
  60. </view>
  61. </view>
  62. </view>
  63. </uni-popup>
  64. <!--
  65. // 倒计时
  66. <view v-if="!!data.endSecond">
  67. <text>考试倒计时:</text>
  68. <uni-countdown :show-day="false" :second="1000" @timeup="onTimeUp" :start="startCountDown"></uni-countdown>
  69. </view>
  70. -->
  71. <!-- 答案解析 -->
  72. <scoreAndAnswerVue ref="scoreAnswerRef"></scoreAndAnswerVue>
  73. </view>
  74. </template>
  75. <script setup>
  76. import {
  77. ref,
  78. reactive,
  79. computed,
  80. watch
  81. } from "vue";
  82. import {
  83. onLoad
  84. } from "@dcloudio/uni-app";
  85. import * as ksApi from "@/api/kaoshi.js"
  86. import danxuan from "@/components/questions/danxuan.vue";
  87. import duoxuan from "@/components/questions/duoxuan.vue";
  88. import tiankong from "@/components/questions/tiankong.vue";
  89. import panduan from "@/components/questions/panduan.vue";
  90. import scoreAndAnswerVue from "@/components/scoreAndAnswer/scoreAndAnswerAdmin.vue";
  91. import {useQuestionTools} from "@/components/questions/useQuestionTools.js";
  92. const {
  93. checkDanxuanReply,
  94. checkDuoxuanReply,
  95. checkPanduanReply,
  96. checkTiankongReply,
  97. getLetterByIndex
  98. } = useQuestionTools();
  99. const stTypes = {
  100. 1: '单选题',
  101. 2: '多选题',
  102. 3: '判断题',
  103. 4: '填空题',
  104. }
  105. const popupRef = ref(null)
  106. const scoreAnswerRef = ref(null)
  107. const startCountDown = ref(false);
  108. const data = reactive({
  109. ksId: null,
  110. ksName: '',
  111. stTotal: 0,
  112. stScore: 0,
  113. biaoji: null,
  114. endSecond: 0,
  115. pageSize: 0,
  116. toggleScreenFlag: 0,
  117. toggleScreenSecond: 0,
  118. zhuapai: 0,
  119. duanluo: [],
  120. markDB: [],
  121. StListForSearch: [],
  122. })
  123. const questionData = ref([]);
  124. const progress = reactive({
  125. dlIndex: 0,
  126. dtIndex: 0
  127. })
  128. watch(() => data.duanluo, (newVal) => {
  129. // 计算已答试题数量
  130. }, {
  131. deep: true
  132. })
  133. const activeSt = computed(() => {
  134. if (questionData.value.length) {
  135. return questionData.value.length && questionData.value[progress.dlIndex].qas[progress.dtIndex];
  136. } else {
  137. return null
  138. }
  139. })
  140. const isFistStId = computed(() => {
  141. if (data.StListForSearch.length) {
  142. return data.StListForSearch[0].stId == activeSt.value.stId
  143. } else {
  144. return false
  145. }
  146. });
  147. const isLastStId = computed(() => {
  148. if (data.StListForSearch.length) {
  149. return data.StListForSearch[data.StListForSearch.length - 1].stId == activeSt.value.stId
  150. } else {
  151. return false
  152. }
  153. });
  154. onLoad((option) => {
  155. data.ksId = option.ksId;
  156. initKaoshi();
  157. })
  158. function getQaClass(qa) {
  159. if (qa.marked && qa.marked === true) {
  160. return 'paragraph-qa-block-mark';
  161. } else {
  162. if (qa.stTypeId == 1) {
  163. if (checkDanxuanReply(qa)) {
  164. return 'paragraph-qa-block-done';
  165. } else {
  166. return 'paragraph-qa-block-init';
  167. }
  168. } else if (qa.stTypeId == 2) {
  169. if (checkDuoxuanReply(qa)) {
  170. return 'paragraph-qa-block-done';
  171. } else {
  172. return 'paragraph-qa-block-init';
  173. }
  174. } else if (qa.stTypeId == 3) {
  175. if (checkPanduanReply(qa)) {
  176. return 'paragraph-qa-block-done';
  177. } else {
  178. return 'paragraph-qa-block-init';
  179. }
  180. } else if (qa.stTypeId == 4) {
  181. if (checkTiankongReply(qa)) {
  182. return 'paragraph-qa-block-done';
  183. } else {
  184. return 'paragraph-qa-block-init';
  185. }
  186. }
  187. }
  188. }
  189. function skipQuestion(dlIndex, dtIndex) {
  190. progress.dlIndex = dlIndex;
  191. progress.dtIndex = dtIndex;
  192. handlePopupBack()
  193. }
  194. function answerCardItemClick(qa) {
  195. const actQa = data.StListForSearch.find(item => item.stId == qa.stId);
  196. skipQuestion(actQa.dlIndex, actQa.dtIndex)
  197. }
  198. function handleBack() {
  199. uni.redirectTo({
  200. url: "/pages/admin/Kaoshi/list"
  201. })
  202. }
  203. function onTimeUp() {
  204. console.log('end')
  205. }
  206. function showAnswerCard() {
  207. popupRef.value.open('bottom')
  208. }
  209. function handlePopupBack() {
  210. popupRef.value.close()
  211. }
  212. function handlePrev() {
  213. const qa = data.StListForSearch.find(item => item.stId == activeSt.value.stId);
  214. const index = qa.num - 1;
  215. if (index > 0) {
  216. const result = data.StListForSearch[index - 1];
  217. progress.dlIndex = result.dlIndex;
  218. progress.dtIndex = result.dtIndex
  219. }
  220. }
  221. function handleNext() {
  222. const qa = data.StListForSearch.find(item => item.stId == activeSt.value.stId);
  223. const index = qa.num - 1;
  224. if (index < data.StListForSearch.length) {
  225. const result = data.StListForSearch[index + 1];
  226. progress.dlIndex = result.dlIndex;
  227. progress.dtIndex = result.dtIndex
  228. }
  229. }
  230. function formatDuanluoList(dlData) {
  231. let uIndex = 0; // 试题num
  232. let iDuanluo = 0; // 段落num
  233. let result = [];
  234. for (const duanluo of data.duanluo) {
  235. let paragraph = {
  236. qas: [],
  237. };
  238. paragraph.name = duanluo.name;
  239. let iQa = 0; // 当前试题序号
  240. let order = 0; // 当前题型中第几题
  241. for (const iDanxuan of duanluo.danxuan) {
  242. iDanxuan.type = 'danxuan';
  243. iDanxuan.marked = false;
  244. iDanxuan.onlyNum = uIndex + 1;
  245. iDanxuan.order = order;
  246. iDanxuan.iQa = iQa;
  247. iDanxuan.reply = iDanxuan.result;
  248. paragraph.qas.push(iDanxuan);
  249. uIndex++;
  250. order++;
  251. iQa++;
  252. data.StListForSearch.push({
  253. stId: iDanxuan.stId,
  254. paragraphName: paragraph.name,
  255. dlIndex: iDuanluo,
  256. dtIndex: iDanxuan.iQa,
  257. num: iDanxuan.onlyNum
  258. })
  259. }
  260. order = 0;
  261. for (const iDuoxuan of duanluo.duoxuan) {
  262. iDuoxuan.type = 'duoxuan';
  263. iDuoxuan.marked = false;
  264. iDuoxuan.onlyNum = uIndex + 1;
  265. iDuoxuan.order = order;
  266. paragraph.qas.push(iDuoxuan);
  267. iDuoxuan.reply = iDuoxuan.result;
  268. iDuoxuan.iQa = iQa;
  269. uIndex++;
  270. order++;
  271. iQa++;
  272. data.StListForSearch.push({
  273. stId: iDuoxuan.stId,
  274. paragraphName: paragraph.name,
  275. dlIndex: iDuanluo,
  276. dtIndex: iDuoxuan.iQa,
  277. num: iDuoxuan.onlyNum
  278. })
  279. }
  280. order = 0;
  281. for (const iPanduan of duanluo.panduan) {
  282. iPanduan.type = 'panduan';
  283. iPanduan.marked = false;
  284. iPanduan.onlyNum = uIndex + 1;
  285. iPanduan.order = order;
  286. paragraph.qas.push(iPanduan);
  287. iPanduan.reply = iPanduan.result;
  288. iPanduan.iQa = iQa;
  289. uIndex++;
  290. order++;
  291. iQa++;
  292. data.StListForSearch.push({
  293. stId: iPanduan.stId,
  294. paragraphName: paragraph.name,
  295. dlIndex: iDuanluo,
  296. dtIndex: iPanduan.iQa,
  297. num: iPanduan.onlyNum
  298. })
  299. }
  300. order = 0;
  301. for (const iTiankong of duanluo.tiankong) {
  302. iTiankong.type = 'tiankong';
  303. iTiankong.marked = false;
  304. iTiankong.onlyNum = uIndex + 1;
  305. iTiankong.order = order;
  306. paragraph.qas.push(iTiankong);
  307. iTiankong.reply = iTiankong.result.map(item => item[0]);
  308. iTiankong.iQa = iQa;
  309. uIndex++;
  310. order++;
  311. iQa++;
  312. data.StListForSearch.push({
  313. stId: iTiankong.stId,
  314. paragraphName: paragraph.name,
  315. dlIndex: iDuanluo,
  316. dtIndex: iTiankong.iQa,
  317. num: iTiankong.onlyNum
  318. })
  319. }
  320. iDuanluo++;
  321. questionData.value.push(paragraph)
  322. console.log(questionData.value)
  323. }
  324. }
  325. function handleBiaoji() {
  326. activeSt.value.marked = !activeSt.value.marked;
  327. }
  328. function handleCheckJiexi() {
  329. const qa = activeSt.value ;
  330. let score = qa.score;
  331. let reply = '';
  332. let result = '';
  333. let answer = qa.answer;
  334. if (qa.stTypeId == 1) {
  335. // 单选题
  336. if (qa.reply && qa.reply.trim() !== '') {
  337. reply = getLetterByIndex(qa.reply)
  338. }
  339. if (qa.result) {
  340. result = getLetterByIndex(qa.result)
  341. }
  342. }
  343. if (qa.stTypeId == 2) {
  344. // 多选题
  345. if (qa.reply && qa.reply.length) {
  346. reply = reply.map(item => {
  347. if (item.trim()) {
  348. return getLetterByIndex(item.trim())
  349. }
  350. })
  351. }
  352. if (qa.result) {
  353. result = result.map(item => {
  354. if (item.trim()) {
  355. return getLetterByIndex(item.trim())
  356. }
  357. })
  358. }
  359. }
  360. if (qa.stTypeId == 3) {
  361. // 判断题
  362. if (qa.reply == 0) {
  363. reply = '错误'
  364. }else if (qa.reply == 1) {
  365. reply = '正确'
  366. }
  367. if (qa.result == 0) {
  368. result = '错误'
  369. }else if (qa.result == 1) {
  370. result = '正确'
  371. }
  372. }
  373. if (qa.stTypeId == 4) {
  374. // 填空题
  375. }
  376. scoreAnswerRef.value.showPopup({
  377. score,reply,result,answer
  378. })
  379. }
  380. function initKaoshi() {
  381. ksApi.getKaoshiInfo({
  382. ksId: data.ksId
  383. }).then(res => {
  384. const {
  385. ksId,
  386. ksName,
  387. stTotal,
  388. stScore,
  389. biaoji,
  390. endSecond,
  391. pageSize,
  392. toggleScreenFlag,
  393. toggleScreenSecond,
  394. zhuapai,
  395. duanluoList
  396. } = res.data;
  397. data.ksId = ksId;
  398. data.ksName = ksName;
  399. data.stTotal = stTotal;
  400. data.stScore = stScore;
  401. data.biaoji = biaoji;
  402. data.endSecond = endSecond;
  403. data.pageSize = pageSize;
  404. data.toggleScreenFlag = toggleScreenFlag;
  405. data.toggleScreenSecond = toggleScreenSecond;
  406. data.zhuapai = zhuapai;
  407. data.duanluo = duanluoList;
  408. formatDuanluoList(data.duanluo);
  409. uni.setNavigationBarTitle({
  410. title: data.ksName
  411. });
  412. startCountDown.value = true;
  413. })
  414. }
  415. </script>