unitTest.vue 4.0 KB

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