unitTest.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <view class="ezy-exam-page">
  3. <view class="icon-title-navBar-box">
  4. <view @click="handleBack" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">单元测试</text>
  6. </view>
  7. <view>
  8. <view>
  9. <view>当前学习进度</view>
  10. <view>{{data.current+1}}/{{data.total}}</view>
  11. </view>
  12. <progress :percent="data.current/data.total * 100" :border-radius="30" stroke-width="10" />
  13. </view>
  14. <view class="shiti-frame-box">
  15. <w-swiper :list="data.list" :current="data.current" class="ezy-exam-swiper" @change="onSwiperChange">
  16. <template v-slot:default="{item}">
  17. <view class="body" v-if="item.mta_show">
  18. <danxuan :question="item" v-if="item.type == '1'"></danxuan>
  19. <panduan :question="item" v-if="item.type == '2'"></panduan>
  20. <tiankong :question="item" v-if="item.type == '3'" :placeholders="item.placeholders"></tiankong>
  21. <button type="primary" v-if="item.stId == data.list[data.total-1].stId"
  22. @click="handleSubmit">交卷</button>
  23. </view>
  24. </template>
  25. </w-swiper>
  26. </view>
  27. <!-- 左右滑动提示 -->
  28. <view>
  29. <view>
  30. < <text>左右滑动查看更多题目</text>>
  31. </view>
  32. </view>
  33. <!-- 填空 -->
  34. <FillItem :value="result" ref="popupRef" @blur="onBlur"></FillItem>
  35. <unitResultVue ref="uniResRef" @check-answer="onCheckAnswer" @do-replay="onDoReplay"></unitResultVue>
  36. <unitAnswerVue :list="data.list" ref="uniAnsRef" @back="handleBack"></unitAnswerVue>
  37. </view>
  38. </template>
  39. <script setup>
  40. import mtaRadio from '@/components/question/yingyu/mtaRadio.vue'
  41. import FillItem from "@/components/question/FillItem.vue";
  42. import wSwiper from '@/components/wSwiper/wSwiper.vue';
  43. import danxuan from "@/components/question/danxuan.vue";
  44. import panduan from "@/components/question/panduan.vue";
  45. import tiankong from "@/components/question/tiankong.vue";
  46. import unitResultVue from './components/unitResult.vue';
  47. import unitAnswerVue from "./components/unitAnswer.vue";
  48. import * as httpApi from "@/api/chanpinShuxue.js"
  49. import {
  50. reactive,
  51. ref
  52. } from "vue"
  53. import {
  54. onLoad
  55. } from "@dcloudio/uni-app"
  56. import {
  57. useShuxueTest
  58. } from "./components/useShuxueUnitTest.js"
  59. const {
  60. data,
  61. handleSubmit,
  62. updateRightWrong,
  63. resetStart
  64. } = useShuxueTest(handleSeeResult, handleSeeResultClose)
  65. const curTiankong = ref(null);
  66. const result = ref('');
  67. const popupRef = ref(null);
  68. const uniResRef = ref(null);
  69. const uniAnsRef = ref(null);
  70. function handleSeeResultClose() {
  71. uniResRef.value.closePopup()
  72. }
  73. function handleSeeResult() {
  74. uniResRef.value.showPopup({
  75. right: data.rightAnswer,
  76. wrong: data.wrongAnswer
  77. })
  78. }
  79. function handleCheckAnswer() {
  80. uniResRef.value.showPopup({
  81. jieId: data.jieId
  82. })
  83. }
  84. function onDoReplay() {
  85. resetStart()
  86. }
  87. function onCheckAnswer() {
  88. uniAnsRef.value.showPopup();
  89. }
  90. onLoad(() => {
  91. uni.$on('tiankong-fillItem', (val) => {
  92. const {
  93. index,
  94. question
  95. } = val;
  96. curTiankong.value = val;
  97. result.value = question.reply[index];
  98. const dom = getPopupRef();
  99. dom && dom.showPopup();
  100. })
  101. uni.$on('unitShuxueTest-submit',val => {
  102. updateRightWrong(val)
  103. })
  104. })
  105. function getPopupRef() {
  106. return popupRef.value;
  107. }
  108. function onBlur({
  109. result
  110. }) {
  111. if (curTiankong.value) {
  112. uni.$emit('tiankong-setResult', {
  113. index: curTiankong.value.index,
  114. stId: curTiankong.value.question.stId,
  115. result
  116. });
  117. }
  118. const dom = getPopupRef();
  119. dom && dom.handleClear();
  120. }
  121. function handleBack() {
  122. uni.navigateBack()
  123. }
  124. function onSwiperChange(index) {
  125. data.current = index;
  126. uni.$emit('swiper-change', index)
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .swiper-box {
  131. height: 200px;
  132. }
  133. .swiper-item {
  134. display: flex;
  135. flex-direction: column;
  136. justify-content: center;
  137. align-items: center;
  138. height: 200px;
  139. }
  140. </style>