exam.vue 12 KB

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