paper-exam.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <mx-paper :readonly="!!prevData.readonly" :continue-name="prevData.continueName"/>
  3. </template>
  4. <script setup>
  5. import {onMounted, ref} from 'vue'
  6. import {useTransfer} from "@/hooks/useTransfer";
  7. import {getExamRecordsDetail} from "@/api/webApi/paper";
  8. import {openExamineePaper} from "@/api/webApi/studentEvaluating";
  9. import {useProvidePaperService} from "@/components/mx-paper/usePaperInjection";
  10. import {useProvideQuestionService} from "@/components/mx-question/useQuestionInjection";
  11. import {alertAsync} from "@/utils/uni-helper";
  12. import {useProvidePaperNavigationService} from "@/components/mx-paper/usePaperNavigationServiceInjection";
  13. const {prevData, callbackEventData} = useTransfer()
  14. const paper = ref({})
  15. // paper service, question service解耦了视图与数据的关系,使两方都可以独立重写
  16. const paperService = useProvidePaperService(paper)
  17. const questionService = useProvideQuestionService(paperService)
  18. useProvidePaperNavigationService(paperService, questionService)
  19. onMounted(() => loadPaper())
  20. paperService.onAnswerComplete(async () => {
  21. const msg = paperService.answerCompletedTips.value
  22. await alertAsync(msg)
  23. questionService.cleanUserData()
  24. paperService.reset()
  25. await loadPaper()
  26. })
  27. paperService.onScoreComplete(async () => {
  28. // 因为这里并没有合适的API同步试卷的属性,
  29. // 暂时手改allowScore为false,可以呈现做题统计和继续练习按钮
  30. paper.value.allowScore = false
  31. paperService.index.value = 0
  32. callbackEventData.value = true // 只需要标记有变更即可
  33. })
  34. paperService.onContinueNext(async () => {
  35. questionService.cleanUserData()
  36. paperService.reset()
  37. await loadPaper()
  38. })
  39. const loadPaper = async () => {
  40. uni.showLoading()
  41. try {
  42. const loadFun = prevData.value.readonly ? getExamRecordsDetail : openExamineePaper
  43. const res = await loadFun(prevData.value)
  44. paper.value = res.data
  45. } finally {
  46. uni.hideLoading()
  47. }
  48. }
  49. </script>
  50. <style lang="scss">
  51. </style>