lianxi.vue 12 KB

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