exam.vue 12 KB

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