exam.vue 12 KB

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