lianxi.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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.lxName}}</text>
  7. </view>
  8. <!-- 第一行 -->
  9. <view class="kaoshi-page-title">
  10. <view v-if="activeSt" class="title-types">{{dlName}}</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">{{activeSt && activeSt.marked ? '取标':'标记'}}</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 lxApi from "@/api/lianxi.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 scoreAndAnswerAdminTiankong from "@/components/scoreAndAnswer/scoreAndAnswerAdminTiankong.vue";
  94. import {useQuestionTools} from "@/components/questions/useQuestionTools.js";
  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. lxId: null,
  114. lxName: '',
  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. const dlName = computed(() => {
  133. if (data.StListForSearch && activeSt.value) {
  134. return data.StListForSearch[activeSt.value.onlyNum].paragraphName
  135. } else {
  136. return ''
  137. }
  138. })
  139. watch(() => data.duanluo, (newVal) => {
  140. // 计算已答试题数量
  141. }, {
  142. deep: true
  143. })
  144. const activeSt = computed(() => {
  145. if (questionData.value.length) {
  146. return questionData.value.length && questionData.value[progress.dlIndex].qas[progress.dtIndex];
  147. } else {
  148. return null
  149. }
  150. })
  151. const isFistStId = computed(() => {
  152. if (data.StListForSearch.length) {
  153. return data.StListForSearch[0].stId == activeSt.value.stId
  154. } else {
  155. return false
  156. }
  157. });
  158. const isLastStId = computed(() => {
  159. if (data.StListForSearch.length) {
  160. return data.StListForSearch[data.StListForSearch.length - 1].stId == activeSt.value.stId
  161. } else {
  162. return false
  163. }
  164. });
  165. onLoad((option) => {
  166. data.lxId = option.lxId;
  167. initKaoshi();
  168. })
  169. function getQaClass(qa) {
  170. if (qa.marked && qa.marked === true) {
  171. return 'paragraph-qa-block-mark';
  172. } else {
  173. if (qa.stTypeId == 1) {
  174. if (checkDanxuanReply(qa)) {
  175. return 'paragraph-qa-block-done';
  176. } else {
  177. return 'paragraph-qa-block-init';
  178. }
  179. } else if (qa.stTypeId == 2) {
  180. if (checkDuoxuanReply(qa)) {
  181. return 'paragraph-qa-block-done';
  182. } else {
  183. return 'paragraph-qa-block-init';
  184. }
  185. } else if (qa.stTypeId == 3) {
  186. if (checkPanduanReply(qa)) {
  187. return 'paragraph-qa-block-done';
  188. } else {
  189. return 'paragraph-qa-block-init';
  190. }
  191. } else if (qa.stTypeId == 4) {
  192. if (checkTiankongReply(qa)) {
  193. return 'paragraph-qa-block-done';
  194. } else {
  195. return 'paragraph-qa-block-init';
  196. }
  197. }
  198. }
  199. }
  200. function skipQuestion(dlIndex, dtIndex) {
  201. progress.dlIndex = dlIndex;
  202. progress.dtIndex = dtIndex;
  203. handlePopupBack()
  204. }
  205. function answerCardItemClick(qa) {
  206. const actQa = data.StListForSearch.find(item => item.stId == qa.stId);
  207. skipQuestion(actQa.dlIndex, actQa.dtIndex)
  208. }
  209. function handleBack() {
  210. uni.redirectTo({
  211. url: "/pages/admin/Kaoshi/list"
  212. })
  213. }
  214. function onTimeUp() {
  215. console.log('end')
  216. }
  217. function showAnswerCard() {
  218. popupRef.value.open('bottom')
  219. }
  220. function handlePopupBack() {
  221. popupRef.value.close()
  222. }
  223. function handlePrev() {
  224. const qa = data.StListForSearch.find(item => item.stId == activeSt.value.stId);
  225. const index = qa.num - 1;
  226. if (index > 0) {
  227. const result = data.StListForSearch[index - 1];
  228. progress.dlIndex = result.dlIndex;
  229. progress.dtIndex = result.dtIndex
  230. }
  231. }
  232. function handleNext() {
  233. const qa = data.StListForSearch.find(item => item.stId == activeSt.value.stId);
  234. const index = qa.num - 1;
  235. if (index < data.StListForSearch.length) {
  236. const result = data.StListForSearch[index + 1];
  237. progress.dlIndex = result.dlIndex;
  238. progress.dtIndex = result.dtIndex
  239. }
  240. }
  241. function formatDuanluoList(dlData) {
  242. let uIndex = 0; // 试题num
  243. let iDuanluo = 0; // 段落num
  244. let result = [];
  245. for (const duanluo of data.duanluo) {
  246. let paragraph = {
  247. qas: [],
  248. };
  249. paragraph.name = duanluo.name;
  250. let iQa = 0; // 当前试题序号
  251. let order = 0; // 当前题型中第几题
  252. for (const iDanxuan of duanluo.danxuan) {
  253. iDanxuan.type = 'danxuan';
  254. iDanxuan.marked = false;
  255. iDanxuan.onlyNum = uIndex + 1;
  256. iDanxuan.order = order;
  257. iDanxuan.iQa = iQa;
  258. iDanxuan.reply = iDanxuan.result;
  259. paragraph.qas.push(iDanxuan);
  260. uIndex++;
  261. order++;
  262. iQa++;
  263. data.StListForSearch.push({
  264. stId: iDanxuan.stId,
  265. paragraphName: paragraph.name,
  266. dlIndex: iDuanluo,
  267. dtIndex: iDanxuan.iQa,
  268. num: iDanxuan.onlyNum
  269. })
  270. }
  271. order = 0;
  272. for (const iDuoxuan of duanluo.duoxuan) {
  273. iDuoxuan.type = 'duoxuan';
  274. iDuoxuan.marked = false;
  275. iDuoxuan.onlyNum = uIndex + 1;
  276. iDuoxuan.order = order;
  277. paragraph.qas.push(iDuoxuan);
  278. iDuoxuan.reply = iDuoxuan.result;
  279. iDuoxuan.iQa = iQa;
  280. uIndex++;
  281. order++;
  282. iQa++;
  283. data.StListForSearch.push({
  284. stId: iDuoxuan.stId,
  285. paragraphName: paragraph.name,
  286. dlIndex: iDuanluo,
  287. dtIndex: iDuoxuan.iQa,
  288. num: iDuoxuan.onlyNum
  289. })
  290. }
  291. order = 0;
  292. for (const iPanduan of duanluo.panduan) {
  293. iPanduan.type = 'panduan';
  294. iPanduan.marked = false;
  295. iPanduan.onlyNum = uIndex + 1;
  296. iPanduan.order = order;
  297. paragraph.qas.push(iPanduan);
  298. iPanduan.reply = iPanduan.result;
  299. iPanduan.iQa = iQa;
  300. uIndex++;
  301. order++;
  302. iQa++;
  303. data.StListForSearch.push({
  304. stId: iPanduan.stId,
  305. paragraphName: paragraph.name,
  306. dlIndex: iDuanluo,
  307. dtIndex: iPanduan.iQa,
  308. num: iPanduan.onlyNum
  309. })
  310. }
  311. order = 0;
  312. for (const iTiankong of duanluo.tiankong) {
  313. iTiankong.type = 'tiankong';
  314. iTiankong.marked = false;
  315. iTiankong.onlyNum = uIndex + 1;
  316. iTiankong.order = order;
  317. paragraph.qas.push(iTiankong);
  318. iTiankong.reply = iTiankong.result.map(item => item[0]);
  319. iTiankong.iQa = iQa;
  320. uIndex++;
  321. order++;
  322. iQa++;
  323. data.StListForSearch.push({
  324. stId: iTiankong.stId,
  325. paragraphName: paragraph.name,
  326. dlIndex: iDuanluo,
  327. dtIndex: iTiankong.iQa,
  328. num: iTiankong.onlyNum
  329. })
  330. }
  331. iDuanluo++;
  332. questionData.value.push(paragraph)
  333. console.log(questionData.value)
  334. }
  335. }
  336. function handleBiaoji() {
  337. activeSt.value.marked = !activeSt.value.marked;
  338. }
  339. function handleCheckJiexi() {
  340. const qa = activeSt.value ;
  341. let score = qa.score;
  342. let reply = '';
  343. let result = '';
  344. let answer = qa.answer;
  345. if (qa.stTypeId == 1) {
  346. // 单选题
  347. if (qa.reply && qa.reply.trim() !== '') {
  348. reply = getLetterByIndex(qa.reply)
  349. } else {
  350. reply = '未答'
  351. }
  352. if (qa.result) {
  353. result = getLetterByIndex(qa.result)
  354. } else {
  355. result = '无答案'
  356. }
  357. }
  358. if (qa.stTypeId == 2) {
  359. // 多选题
  360. if (qa.reply && qa.reply.length) {
  361. reply = qa.reply.map(item => {
  362. if (item.trim()) {
  363. return getLetterByIndex(item.trim())
  364. }
  365. }).join(',')
  366. } else {
  367. reply = '未答'
  368. }
  369. if (qa.result) {
  370. result = qa.result.map(item => {
  371. if (item.trim()) {
  372. return getLetterByIndex(item.trim())
  373. }
  374. }).join(',')
  375. } else {
  376. result = '无答案'
  377. }
  378. }
  379. if (qa.stTypeId == 3) {
  380. // 判断题
  381. if (qa.reply == 0) {
  382. reply = '错误'
  383. }else if (qa.reply == 1) {
  384. reply = '正确'
  385. }
  386. if (qa.result == 0) {
  387. result = '错误'
  388. }else if (qa.result == 1) {
  389. result = '正确'
  390. }
  391. }
  392. if (qa.stTypeId == 4) {
  393. let reply = qa.reply || [];
  394. let result =qa.result || [];
  395. // 填空题
  396. scoreAnswerTkRef.value.showPopup({score,reply,result,answer})
  397. } else {
  398. scoreAnswerRef.value.showPopup({
  399. score,reply,result,answer
  400. })
  401. }
  402. }
  403. function initKaoshi() {
  404. lxApi.getLianxiInfo({
  405. lxId: data.lxId
  406. }).then(res => {
  407. const {
  408. lxId,
  409. lxName,
  410. stTotal,
  411. stScore,
  412. biaoji,
  413. endSecond,
  414. pageSize,
  415. toggleScreenFlag,
  416. toggleScreenSecond,
  417. zhuapai,
  418. duanluoList
  419. } = res.data;
  420. data.lxId = lxId;
  421. data.lxName = lxName;
  422. data.stTotal = stTotal;
  423. data.stScore = stScore;
  424. data.biaoji = biaoji;
  425. data.endSecond = endSecond;
  426. data.pageSize = pageSize;
  427. data.toggleScreenFlag = toggleScreenFlag;
  428. data.toggleScreenSecond = toggleScreenSecond;
  429. data.zhuapai = zhuapai;
  430. data.duanluo = duanluoList;
  431. formatDuanluoList(data.duanluo);
  432. uni.setNavigationBarTitle({
  433. title: data.lxName
  434. });
  435. startCountDown.value = true;
  436. })
  437. }
  438. </script>