unitTest.vue 4.2 KB

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