unitTest.vue 4.0 KB

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