猫妈狗爸伴宠师小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.0 KiB

  1. import dayjs from "dayjs";
  2. // 判断选项是否被选中
  3. export function isOptionSelected(question, optionId) {
  4. if (!question.userAnswerBaseList || !question.userAnswerBaseList.length) return false;
  5. return question.userAnswerBaseList.some(answer => answer.answerId === optionId);
  6. }
  7. // 判断答案是否正确
  8. export function isAnswerCorrect(question) {
  9. if (!question.userAnswerBaseList || !question.userAnswerBaseList.length) return false;
  10. // 获取所有正确答案的ID
  11. const correctOptionIds = question.answerList
  12. .filter(option => option.isTrue)
  13. .map(option => option.id);
  14. // 获取用户选择的答案ID
  15. const userAnswerIds = [...new Set(question.userAnswerBaseList.map(answer => answer.answerId))];
  16. // 判断用户选择的答案数量是否与正确答案数量相同
  17. if (userAnswerIds.length !== correctOptionIds.length) {
  18. return false;
  19. }
  20. // 判断用户选择的答案是否都是正确的
  21. return userAnswerIds.every(answerId => correctOptionIds.includes(answerId));
  22. }
  23. export function isQuestionAnswered(question) {
  24. if (question.type == '培训') {
  25. // 填空题:检查是否有答案且答案不为空
  26. return question.userAppletAnswerTrain &&
  27. question.userAppletAnswerTrain.answer &&
  28. question.userAppletAnswerTrain.answer.trim() !== '';
  29. } else {
  30. // 选择题:检查是否有选择的答案
  31. return question.userAnswerBaseList && question.userAnswerBaseList.length > 0;
  32. }
  33. }
  34. // 判断全部题目答案是否达到指定的准确率
  35. export function isSuccessPrecision(list, number = 100){
  36. let errNumber = 0
  37. for (var index = 0; index < list.length; index++) {
  38. var question = list[index];
  39. if (question.type == '基本' && !isAnswerCorrect(question)) {
  40. errNumber++
  41. }
  42. }
  43. console.log(errNumber, (list.length - errNumber) / list.length * 100);
  44. if(((list.length - errNumber) / list.length * 100) < number){
  45. return false
  46. }
  47. return true
  48. }
  49. export default {
  50. isOptionSelected,
  51. isAnswerCorrect,
  52. isQuestionAnswered,
  53. isSuccessPrecision,
  54. }