ksScoreShijuan.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <template>
  2. <view class="socre-shijuan">
  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. <topCard @openCard="handleOpenCard" :name="data.ksName" :zyLevelName="data.zyLevelName" :userScore="data.userScore" :Score="data.Score" :count="activeSt && activeSt.onlyNum||0" :total="data.StListForSearch.length"></topCard>
  10. <view>
  11. <!-- 段落 -->
  12. <view class="kaoshi-shiti-content">
  13. <!-- 试题区域 -->
  14. <view v-if="activeSt">
  15. <template v-if="activeSt.stTypeId == 1">
  16. <!-- 单选 -->
  17. <danxuan :question="activeSt" :key="activeSt.stId"></danxuan>
  18. </template>
  19. <template v-if="activeSt.stTypeId == 2">
  20. <!-- 多选 -->
  21. <duoxuan :question="activeSt" :key="activeSt.stId"></duoxuan>
  22. </template>
  23. <template v-if="activeSt.stTypeId == 3">
  24. <!-- 判断 -->
  25. <panduan :question="activeSt" :key="activeSt.stId"></panduan>
  26. </template>
  27. <template v-if="activeSt.stTypeId == 4">
  28. <!-- 填空 -->
  29. <tiankong :question="activeSt" :key="activeSt.stId"></tiankong>
  30. </template>
  31. </view>
  32. </view>
  33. <!-- 解析 -->
  34. <view v-if="activeSt">
  35. <view class="phone-question-answer-box" v-if="activeSt.stTypeId != 4">
  36. <view class="phone-line-title">答案解析</view>
  37. <view class="btdf-row">本题得分:<text>{{answerRes.score}}</text>分</view>
  38. <view class="zqda-row">正确答案:<text>{{answerRes.result}}</text></view>
  39. <view class="ndda-row">您的答案:<text>{{answerRes.reply}}</text></view>
  40. <view class="dajx-row">答案解析:
  41. <rich-text :nodes="answerRes.answer"></rich-text>
  42. </view>
  43. </view>
  44. <view class="phone-question-answer-box" v-else>
  45. <view class="phone-line-title">答案解析</view>
  46. <view class="btdf-row">本题得分:<text>{{answerRes.score}}</text>分</view>
  47. <view class="zqda-row">正确答案:
  48. <view v-for="(item,index) in answerRes.result">{{`填空${index+1}`}} : {{item}}</view>
  49. </view>
  50. <view class="ndda-row">您的答案:
  51. <view v-for="(item,index) in answerRes.reply"> {{`填空${index+1}`}}: {{item}}</view>
  52. </view>
  53. <view class="dajx-row">答案解析:
  54. <rich-text :nodes="answerRes.answer"></rich-text>
  55. </view>
  56. </view>
  57. </view>
  58. <!-- 上下按钮 -->
  59. <template v-if="activeSt">
  60. <button type="default" size="mini" hover-class="none" class="phone-green-btn ks-btn-prev" @click="handlePrev" v-if="!isFistStId">上一题</button>
  61. <button type="default" size="mini" hover-class="none"class="phone-green-btn ks-btn-next" @click="handleNext" v-if="!isLastStId">下一题</button>
  62. </template>
  63. <!-- 答题卡 -->
  64. <uni-popup ref="popupRef" background-color="#fff" :is-mask-click="false" :mask-click="false">
  65. <view class="answer-card-popup">
  66. <view class="icon-title-bjcolor-navBar-box">
  67. <view @click="handlePopupBack" class="nav-bar-icon"> </view>
  68. <text class="nav-bar-title">答题卡</text>
  69. </view>
  70. <view class="answer-card-content" v-for="(paragraph,paragraphIndex) in questionData" :key="paragraphIndex">
  71. <view class="paragraph-title">
  72. {{paragraph.name}}
  73. </view>
  74. <view class="paragraph-qa" v-for="(qa,qaIndex) in paragraph.qas" :key="qaIndex"
  75. :class="getQaClass(qa)" @click="answerCardItemClick(qa)">{{qa.onlyNum}}
  76. </view>
  77. </view>
  78. </view>
  79. </uni-popup>
  80. </view>
  81. </view>
  82. </template>
  83. <script setup>
  84. import topCard from "@/components/score/topCard.vue"
  85. import danxuan from "@/components/questions/danxuan.vue";
  86. import duoxuan from "@/components/questions/duoxuan.vue";
  87. import tiankong from "@/components/questions/tiankong.vue";
  88. import panduan from "@/components/questions/panduan.vue";
  89. import {useQuestionTools} from "@/components/questions/useQuestionTools.js";
  90. import { onLoad } from "@dcloudio/uni-app";
  91. import {ref,reactive,computed} from "vue"
  92. import * as ksApi from "@/api/kaoshi.js"
  93. const {
  94. checkDanxuanReply,
  95. checkDuoxuanReply,
  96. checkPanduanReply,
  97. checkTiankongReply,
  98. getLetterByIndex
  99. } = useQuestionTools();
  100. const hisId = ref(null)
  101. const popupRef = ref(null)
  102. const data = reactive({
  103. ksId: null,
  104. ksName: '',
  105. stTotal: 0,
  106. zyLevelName: '',
  107. userScore: '',
  108. ksScore: 0,
  109. StListForSearch: [],
  110. duanluo: []
  111. })
  112. const questionData = ref([]);
  113. const progress = reactive({
  114. dlIndex: 0,
  115. dtIndex: 0
  116. })
  117. const dlName = computed(() => {
  118. if (data.StListForSearch && activeSt.value) {
  119. return data.StListForSearch[activeSt.value.onlyNum].paragraphName
  120. } else {
  121. return ''
  122. }
  123. })
  124. const activeSt = computed(() => {
  125. if (questionData.value.length) {
  126. return questionData.value.length && questionData.value[progress.dlIndex].qas[progress.dtIndex];
  127. } else {
  128. return null
  129. }
  130. })
  131. const answerRes = computed(() => {
  132. const qa = activeSt.value ;
  133. let score = qa.score;
  134. let reply = '';
  135. let result = '';
  136. let answer = qa.answer;
  137. if (qa.stTypeId == 1) {
  138. // 单选题
  139. if (qa.reply && qa.reply.trim() !== '') {
  140. reply = getLetterByIndex(qa.reply)
  141. } else {
  142. reply = '未答'
  143. }
  144. if (qa.result) {
  145. result = getLetterByIndex(qa.result)
  146. } else {
  147. result = '无答案'
  148. }
  149. }
  150. if (qa.stTypeId == 2) {
  151. // 多选题
  152. if (qa.reply && qa.reply.length) {
  153. reply = qa.reply.map(item => {
  154. if (item.trim()) {
  155. return getLetterByIndex(item.trim())
  156. }
  157. }).join(',')
  158. } else {
  159. reply = '未答'
  160. }
  161. if (qa.result) {
  162. result = qa.result.map(item => {
  163. if (item.trim()) {
  164. return getLetterByIndex(item.trim())
  165. }
  166. }).join(',')
  167. } else {
  168. result = '无答案'
  169. }
  170. }
  171. if (qa.stTypeId == 3) {
  172. // 判断题
  173. if (qa.reply == '') {
  174. reply = '未答'
  175. } else if (qa.reply == 0) {
  176. reply = '错误'
  177. }else if (qa.reply == 1) {
  178. reply = '正确'
  179. }
  180. if (qa.result == 0) {
  181. result = '错误'
  182. }else if (qa.result == 1) {
  183. result = '正确'
  184. }
  185. }
  186. if (qa.stTypeId == 4) {
  187. let reply = qa.reply || [];
  188. let result =qa.result || [];
  189. // 填空题
  190. return {score,reply,result,answer}
  191. } else {
  192. return {
  193. score,reply,result,answer
  194. }
  195. }
  196. })
  197. const isFistStId = computed(() => {
  198. if (data.StListForSearch.length) {
  199. return data.StListForSearch[0].stId == activeSt.value.stId
  200. } else {
  201. return false
  202. }
  203. });
  204. const isLastStId = computed(() => {
  205. if (data.StListForSearch.length) {
  206. return data.StListForSearch[data.StListForSearch.length - 1].stId == activeSt.value.stId
  207. } else {
  208. return false
  209. }
  210. });
  211. onLoad((options) => {
  212. hisId.value = options.hisId;
  213. initPage()
  214. })
  215. function getQaClass(qa) {
  216. if (qa.marked && qa.marked === true) {
  217. return 'paragraph-qa-block-mark';
  218. } else {
  219. if (qa.stTypeId == 1) {
  220. if (checkDanxuanReply(qa)) {
  221. return 'paragraph-qa-block-done';
  222. } else {
  223. return 'paragraph-qa-block-init';
  224. }
  225. } else if (qa.stTypeId == 2) {
  226. if (checkDuoxuanReply(qa)) {
  227. return 'paragraph-qa-block-done';
  228. } else {
  229. return 'paragraph-qa-block-init';
  230. }
  231. } else if (qa.stTypeId == 3) {
  232. if (checkPanduanReply(qa)) {
  233. return 'paragraph-qa-block-done';
  234. } else {
  235. return 'paragraph-qa-block-init';
  236. }
  237. } else if (qa.stTypeId == 4) {
  238. if (checkTiankongReply(qa)) {
  239. return 'paragraph-qa-block-done';
  240. } else {
  241. return 'paragraph-qa-block-init';
  242. }
  243. }
  244. }
  245. }
  246. function handleBack() {
  247. uni.redirectTo({
  248. url: "/pages/admin/Lianxi/list"
  249. })
  250. }
  251. function formatDuanluoList() {
  252. let uIndex = 0; // 试题num
  253. let iDuanluo = 0; // 段落num
  254. let result = [];
  255. for (const duanluo of data.duanluo) {
  256. let paragraph = {
  257. qas: [],
  258. };
  259. paragraph.name = duanluo.name;
  260. let iQa = 0; // 当前试题序号
  261. let order = 0; // 当前题型中第几题
  262. for (const iDanxuan of duanluo.danxuan) {
  263. iDanxuan.type = 'danxuan';
  264. iDanxuan.marked = false;
  265. iDanxuan.onlyNum = uIndex + 1;
  266. iDanxuan.order = order;
  267. iDanxuan.iQa = iQa;
  268. paragraph.qas.push(iDanxuan);
  269. uIndex++;
  270. order++;
  271. iQa++;
  272. data.StListForSearch.push({
  273. stId: iDanxuan.stId,
  274. paragraphName: paragraph.name,
  275. dlIndex: iDuanluo,
  276. dtIndex: iDanxuan.iQa,
  277. num: iDanxuan.onlyNum
  278. })
  279. }
  280. order = 0;
  281. for (const iDuoxuan of duanluo.duoxuan) {
  282. iDuoxuan.type = 'duoxuan';
  283. iDuoxuan.marked = false;
  284. iDuoxuan.onlyNum = uIndex + 1;
  285. iDuoxuan.order = order;
  286. paragraph.qas.push(iDuoxuan);
  287. iDuoxuan.iQa = iQa;
  288. uIndex++;
  289. order++;
  290. iQa++;
  291. data.StListForSearch.push({
  292. stId: iDuoxuan.stId,
  293. paragraphName: paragraph.name,
  294. dlIndex: iDuanluo,
  295. dtIndex: iDuoxuan.iQa,
  296. num: iDuoxuan.onlyNum
  297. })
  298. }
  299. order = 0;
  300. for (const iPanduan of duanluo.panduan) {
  301. iPanduan.type = 'panduan';
  302. iPanduan.marked = false;
  303. iPanduan.onlyNum = uIndex + 1;
  304. iPanduan.order = order;
  305. paragraph.qas.push(iPanduan);
  306. iPanduan.iQa = iQa;
  307. uIndex++;
  308. order++;
  309. iQa++;
  310. data.StListForSearch.push({
  311. stId: iPanduan.stId,
  312. paragraphName: paragraph.name,
  313. dlIndex: iDuanluo,
  314. dtIndex: iPanduan.iQa,
  315. num: iPanduan.onlyNum
  316. })
  317. }
  318. order = 0;
  319. for (const iTiankong of duanluo.tiankong) {
  320. iTiankong.type = 'tiankong';
  321. iTiankong.marked = false;
  322. iTiankong.onlyNum = uIndex + 1;
  323. iTiankong.order = order;
  324. paragraph.qas.push(iTiankong);
  325. iTiankong.iQa = iQa;
  326. uIndex++;
  327. order++;
  328. iQa++;
  329. data.StListForSearch.push({
  330. stId: iTiankong.stId,
  331. paragraphName: paragraph.name,
  332. dlIndex: iDuanluo,
  333. dtIndex: iTiankong.iQa,
  334. num: iTiankong.onlyNum
  335. })
  336. }
  337. iDuanluo++;
  338. questionData.value.push(paragraph)
  339. }
  340. }
  341. function handlePrev() {
  342. const qa = data.StListForSearch.find(item => item.stId == activeSt.value.stId);
  343. const index = qa.num - 1;
  344. if (index > 0) {
  345. const result = data.StListForSearch[index - 1];
  346. progress.dlIndex = result.dlIndex;
  347. progress.dtIndex = result.dtIndex
  348. }
  349. }
  350. function handleNext() {
  351. const qa = data.StListForSearch.find(item => item.stId == activeSt.value.stId);
  352. const index = qa.num - 1;
  353. if (index < data.StListForSearch.length) {
  354. const result = data.StListForSearch[index + 1];
  355. progress.dlIndex = result.dlIndex;
  356. progress.dtIndex = result.dtIndex
  357. }
  358. }
  359. function initPage() {
  360. ksApi.getAdminKsChengjiView({hisId: hisId.value}).then(res => {
  361. const { duanluoList,ksName, zyLevelName,userScore,ksScore } = res.data;
  362. data.ksName = ksName;
  363. data.zyLevelName = zyLevelName;
  364. data.userScore = userScore;
  365. data.ksScore = ksScore;
  366. data.duanluo = duanluoList;
  367. formatDuanluoList();
  368. })
  369. }
  370. function handlePopupBack() {
  371. popupRef.value.close()
  372. }
  373. function handleOpenCard() {
  374. popupRef.value.open('bottom')
  375. }
  376. </script>
  377. <style>
  378. </style>