index.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. export default {
  2. data() {
  3. return {
  4. }
  5. },
  6. methods: {
  7. calculateScore(data) {
  8. let score = 0; //计算总分
  9. let totalScore = 0; //总分
  10. let doWrongQuestionIds = []; //做错题id(案例题简答不算在内)
  11. let doQuestionIds = []; //做过的题目id
  12. let lessQuestionNum = 0; //多选题少选
  13. let rightQuestionIds = []; //做对的题目id
  14. let totalQuestionNum = 0; //排除主观题的总条数(简单题)
  15. data.forEach((item) => {
  16. console.log("答案--", item.ans, "选择--", item.ques);
  17. totalScore += item.score * (item.type == 4 ? item.jsonStr.length : 1);
  18. if (
  19. item.type < 4 ||
  20. (item.type == 4 && !item.jsonStr.some((e) => e.type == 5))
  21. ) {
  22. totalQuestionNum++;
  23. }
  24. if (item.type == 1 || item.type == 3) {
  25. //正确
  26. if (item.ques == item.ans) {
  27. item.scoreResult = item.score;
  28. score += item.score;
  29. rightQuestionIds.push(item.questionId);
  30. } else {
  31. //错误
  32. item.scoreResult = 0;
  33. if (item.ques) {
  34. doWrongQuestionIds.push(item.questionId);
  35. }
  36. }
  37. if (item.ques) {
  38. doQuestionIds.push(item.questionId);
  39. }
  40. } else if (item.type == 2) {
  41. let isRight =
  42. item.ans &&
  43. item.ans.every((quesItem, quesIndex) => {
  44. if (item.ques) {
  45. return item.ques[quesIndex] == item.ans[quesIndex];
  46. } else {
  47. return false;
  48. }
  49. });
  50. if (isRight) {
  51. score += item.score;
  52. item.scoreResult = item.score;
  53. rightQuestionIds.push(item.questionId);
  54. } else {
  55. let hasPart = false;
  56. let checkboxScore = 1; //获取单题总分数
  57. item.ques &&
  58. item.ques.forEach((ques, quesIndex) => {
  59. //选错一个全扣
  60. if (item.ques) {
  61. if (item.ans.indexOf(item.ques[quesIndex]) == -1) {
  62. checkboxScore = 0;
  63. }
  64. } else {
  65. checkboxScore = 0;
  66. }
  67. });
  68. //没选错
  69. if (checkboxScore) {
  70. checkboxScore = 0;
  71. item.ans.forEach((ans, quesIndex) => {
  72. //漏选扣一部分,对n题给n X partScore 分
  73. if (item.ques) {
  74. if (item.ques.indexOf(item.ans[quesIndex]) != -1) {
  75. checkboxScore += item.partScore;
  76. hasPart = true;
  77. }
  78. } else {
  79. checkboxScore = 0;
  80. }
  81. });
  82. }
  83. if (!hasPart) {
  84. //0分
  85. item.scoreResult = 0;
  86. if (item.ques) {
  87. doWrongQuestionIds.push(item.questionId);
  88. }
  89. } else {
  90. //部分分
  91. lessQuestionNum++;
  92. item.scoreResult = checkboxScore;
  93. score += checkboxScore;
  94. }
  95. }
  96. if (item.ques && item.ques.length) {
  97. doQuestionIds.push(item.questionId);
  98. }
  99. } else if (item.type == 4) {
  100. let len = item.ans.length;
  101. let questionScore = 0;
  102. if (item.ques && item.ques.length) {
  103. item.ques.forEach((ele, idx) => {
  104. if (
  105. ele == item.ans[idx] ||
  106. (item.jsonStr[idx].type == 2 &&
  107. ele.toString() == item.ans[idx].toString())
  108. ) {
  109. len--;
  110. questionScore += item.score;
  111. }
  112. });
  113. score += questionScore;
  114. item.scoreResult = questionScore;
  115. len == 0 && rightQuestionIds.push(item.questionId);
  116. doQuestionIds.push(item.questionId);
  117. }
  118. } else if (item.type == 5) {
  119. if (item.ques && (item.ques.imageList.length || item.ques.text)) {
  120. doQuestionIds.push(item.questionId);
  121. }
  122. }
  123. });
  124. return {
  125. reportStatus: score >= (data[0].passScore || totalScore * 0.6) ? 1 : 0,
  126. lessQuestionNum,
  127. performance: score,
  128. totalScore,
  129. doQuestionNum: doQuestionIds.length,
  130. doQuestionIds: doQuestionIds.join(","),
  131. rightQuestionIds: rightQuestionIds.join(","),
  132. rightQuestionNum: rightQuestionIds.length,
  133. rightRate:(rightQuestionIds.length / totalQuestionNum).toFixed(2),
  134. historyExamJson: JSON.stringify(data),
  135. questionIds: doWrongQuestionIds,
  136. totalQuestionNum,
  137. };
  138. },
  139. go(path) {
  140. this.$router.push({
  141. path,
  142. });
  143. },
  144. },
  145. beforeDestroy() {
  146. try {
  147. this.$msgbox.close();
  148. } catch (err) { }
  149. },
  150. }